Skip to content

Commit 54366d7

Browse files
committed
feat: sign transactions with cip 1854 derivation path
1 parent 5680a89 commit 54366d7

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/e2e/test/long-running/multisig-wallet/MultiSigWallet.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AddressType,
55
GroupedAddress,
66
InMemoryKeyAgent,
7+
KeyPurpose,
78
KeyRole
89
} from '@cardano-sdk/key-management';
910
import {
@@ -33,6 +34,7 @@ const DUMMY_HEX_BYTES =
3334

3435
const DERIVATION_PATH: AccountKeyDerivationPath = {
3536
index: 0,
37+
purpose: KeyPurpose.MULTI_SIG,
3638
role: KeyRole.External
3739
};
3840

packages/key-management/src/InMemoryKeyAgent.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,15 @@ export class InMemoryKeyAgent extends KeyAgentBase implements KeyAgent {
5757
this.#getPassphrase = getPassphrase;
5858
}
5959

60-
async signBlob({ index, role: type }: AccountKeyDerivationPath, blob: HexBlob): Promise<SignBlobResult> {
60+
async signBlob(
61+
{ index, role: type, purpose = KeyPurpose.STANDARD }: AccountKeyDerivationPath,
62+
blob: HexBlob
63+
): Promise<SignBlobResult> {
6164
const rootPrivateKey = await this.#decryptRootPrivateKey();
6265
const accountKey = await deriveAccountPrivateKey({
6366
accountIndex: this.accountIndex,
6467
bip32Ed25519: this.bip32Ed25519,
68+
purpose,
6569
rootPrivateKey
6670
});
6771

@@ -135,15 +139,18 @@ export class InMemoryKeyAgent extends KeyAgentBase implements KeyAgent {
135139
await Crypto.Ed25519PublicKey.fromHex(await this.derivePublicKey(DREP_KEY_DERIVATION_PATH)).hash()
136140
).hex();
137141
const derivationPaths = ownSignatureKeyPaths(body, knownAddresses, txInKeyPathMap, dRepKeyHash);
138-
const keyPaths = uniqBy([...derivationPaths, ...additionalKeyPaths], ({ role, index }) => `${role}.${index}`);
142+
const keyPaths = uniqBy(
143+
[...derivationPaths, ...additionalKeyPaths],
144+
({ role, index, purpose }) => `${purpose}.${role}.${index}`
145+
);
139146
// TODO:
140147
// if (keyPaths.length === 0) {
141148
// throw new ProofGenerationError();
142149
// }
143150
return new Map<Crypto.Ed25519PublicKeyHex, Crypto.Ed25519SignatureHex>(
144151
await Promise.all(
145-
keyPaths.map(async ({ role, index }) => {
146-
const { publicKey, signature } = await this.signBlob({ index, role }, blob);
152+
keyPaths.map(async ({ role, index, purpose }) => {
153+
const { publicKey, signature } = await this.signBlob({ index, purpose, role }, blob);
147154
return [publicKey, signature] as const;
148155
})
149156
)

0 commit comments

Comments
 (0)