Skip to content

Commit

Permalink
support path derivation in secretbox
Browse files Browse the repository at this point in the history
  • Loading branch information
upalinski committed Jan 8, 2025
1 parent 1f25b5c commit 51f5a76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/embed-wallet/src/EmbedWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ export class EmbedWallet {
* console.log(secretBox);
* ```
*/
async naclSecretbox(message: string): Promise<String> {
return this.provider.request({ method: 'ed25519_nacl_secretbox', params: [message] });
async naclSecretbox(message: string, path?: string): Promise<String> {
return this.provider.request({ method: 'ed25519_nacl_secretbox', params: [message, path] });
}

/**
Expand All @@ -411,8 +411,8 @@ export class EmbedWallet {
* console.log(message);
* ```
*/
async naclSecretboxOpen(message: string): Promise<String> {
return this.provider.request({ method: 'ed25519_nacl_secretbox_open', params: [message] });
async naclSecretboxOpen(message: string, path?: string): Promise<String> {
return this.provider.request({ method: 'ed25519_nacl_secretbox_open', params: [message, path] });
}

/**
Expand Down
10 changes: 8 additions & 2 deletions packages/wallet-engine/src/engine/polkadot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ export const createPolkadotEngine = ({ getPrivateKey, polkadotRpc }: PolkadotEng
ed25519_nacl_secretbox: createAsyncMiddleware(async (req, res) => {
const [message, path] = req.params as string[];

const secretKey = getSecretKey();
let secretKey = getSecretKey();
if (path) {
secretKey = Buffer.concat([secretKey, Buffer.from(`/${path}`)]);
}
const dek = blake2AsU8a(secretKey);

res.result = u8aToHex(nacl.secretbox(new TextEncoder().encode(message), new Uint8Array(24), dek));
Expand All @@ -134,7 +137,10 @@ export const createPolkadotEngine = ({ getPrivateKey, polkadotRpc }: PolkadotEng
ed25519_nacl_secretbox_open: createAsyncMiddleware(async (req, res) => {
const [secretBox, path] = req.params as string[];

const secretKey = getSecretKey();
let secretKey = getSecretKey();
if (path) {
secretKey = Buffer.concat([secretKey, Buffer.from(`/${path}`)]);
}
const dek = blake2AsU8a(secretKey);

const message = nacl.secretbox.open(hexToU8a(secretBox), new Uint8Array(24), dek);
Expand Down

0 comments on commit 51f5a76

Please sign in to comment.