Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"dependencies": {
"@interledger/open-payments": "^7.1.3",
"@noble/ed25519": "^2.3.0",
"@noble/ed25519": "^3.0.0",
"@noble/hashes": "^2.0.1",
"@radix-ui/react-tabs": "^1.1.13",
"awilix": "^12.0.5",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions src/background/services/openPayments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
createAuthenticatedClient,
OpenPaymentsClientError,
} from '@interledger/open-payments/dist/client';
import * as ed from '@noble/ed25519';
import { signAsync } from '@noble/ed25519';
import { hexToBytes } from '@noble/hashes/utils.js';
import type { Request } from 'http-message-signatures';
import { signMessage } from 'http-message-signatures/lib/httpbis';
import { createContentDigestHeader } from 'httpbis-digest-headers';
Expand Down Expand Up @@ -98,7 +99,7 @@ export class OpenPaymentsService {
id: keyId,
alg: 'ed25519',
async sign(data: Uint8Array) {
return Buffer.from(await ed.signAsync(data, key.slice(16)));
return Buffer.from(await signAsync(data, key));
},
};
}
Expand Down Expand Up @@ -162,7 +163,12 @@ export class OpenPaymentsService {

async initClient(walletAddressUrl: string) {
const { privateKey, keyId } = await this.getPrivateKeyInformation();

let privateKeyBytes = hexToBytes(privateKey);
if (privateKeyBytes.length === 48) {
// For keys generated before https://github.com/interledger/web-monetization-extension/pull/1192
// biome-ignore format: inline array looks cleaner
privateKeyBytes = privateKeyBytes.slice(16)
}
this.client = await createAuthenticatedClient({
validateResponses: false,
requestTimeoutMs: 10_000,
Expand All @@ -185,7 +191,7 @@ export class OpenPaymentsService {
? JSON.stringify(await request.json())
: undefined,
},
privateKey: ed.etc.hexToBytes(privateKey),
privateKey: privateKeyBytes,
keyId,
});

Expand Down
16 changes: 3 additions & 13 deletions src/shared/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import * as ed from '@noble/ed25519';
import { keygenAsync } from '@noble/ed25519';

export async function generateEd25519KeyPair() {
const rawPrivateKey = ed.utils.randomPrivateKey();
// PKCS#8 format (version + algorithm)
// Adding these values upfront solves the future import of the key using
// `crypto.subtle.importKey` once the WebCrypto API supports the Ed25519 algorithm.
// biome-ignore format: inline array looks cleaner
const privateKey = new Uint8Array([
48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32,
...rawPrivateKey,
])
const publicKey = await ed.getPublicKeyAsync(rawPrivateKey);

return { privateKey, publicKey };
const keyPair = await keygenAsync();
return { privateKey: keyPair.secretKey, publicKey: keyPair.publicKey };
}

export function exportJWK(key: Uint8Array, kid: string) {
Expand Down