Skip to content

Commit 82449e7

Browse files
committed
feat!: enforce passing purpose when deriving path
1 parent 54366d7 commit 82449e7

File tree

57 files changed

+317
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+317
-145
lines changed

packages/e2e/src/factories.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
CommunicationType,
3232
InMemoryKeyAgent,
3333
KeyAgentDependencies,
34+
KeyPurpose,
3435
Witnesser,
3536
util
3637
} from '@cardano-sdk/key-management';
@@ -204,7 +205,8 @@ keyManagementFactory.register('inMemory', async (params: any): Promise<CreateKey
204205
accountIndex: params.accountIndex,
205206
chainId: params.chainId,
206207
getPassphrase: async () => Buffer.from(params.passphrase),
207-
mnemonicWords
208+
mnemonicWords,
209+
purpose: params.purpose
208210
},
209211
dependencies
210212
)
@@ -220,7 +222,8 @@ keyManagementFactory.register('ledger', async (params: any): Promise<CreateKeyAg
220222
accountIndex: params.accountIndex,
221223
chainId: params.chainId,
222224
communicationType: CommunicationType.Node,
223-
deviceConnection
225+
deviceConnection,
226+
purpose: params.purpose
224227
},
225228
dependencies
226229
);
@@ -238,6 +241,7 @@ keyManagementFactory.register(
238241
{
239242
accountIndex: params.accountIndex,
240243
chainId: params.chainId,
244+
purpose: params.purpose,
241245
trezorConfig: {
242246
communicationType: CommunicationType.Node,
243247
manifest: {
@@ -277,6 +281,7 @@ export type GetWalletProps = {
277281
env: any;
278282
idx?: number;
279283
logger: Logger;
284+
purpose: KeyPurpose;
280285
name: string;
281286
polling?: PollingConfig;
282287
handlePolicyIds?: Cardano.PolicyId[];
@@ -290,6 +295,7 @@ export type GetSharedWalletProps = {
290295
env: any;
291296
logger: Logger;
292297
name: string;
298+
purpose: KeyPurpose;
293299
polling?: PollingConfig;
294300
handlePolicyIds?: Cardano.PolicyId[];
295301
stores?: storage.WalletStores;
@@ -321,7 +327,7 @@ const patchInitializeTxToRespectEpochBoundary = <T extends ObservableWallet>(
321327
* @returns an object containing the wallet and providers passed to it
322328
*/
323329
export const getWallet = async (props: GetWalletProps) => {
324-
const { env, idx, logger, name, stores, customKeyParams, keyAgent, witnesser } = props;
330+
const { env, idx, logger, name, stores, customKeyParams, keyAgent, witnesser, purpose } = props;
325331
let polling = props.polling;
326332
const providers = {
327333
addressDiscovery: await addressDiscoveryFactory.create(
@@ -378,7 +384,7 @@ export const getWallet = async (props: GetWalletProps) => {
378384
}
379385

380386
const wallet = createPersonalWallet(
381-
{ name, polling },
387+
{ name, polling, purpose },
382388
{
383389
...providers,
384390
bip32Account,
@@ -405,7 +411,7 @@ export const getWallet = async (props: GetWalletProps) => {
405411
* @returns an object containing the wallet and providers passed to it
406412
*/
407413
export const getSharedWallet = async (props: GetSharedWalletProps) => {
408-
const { env, logger, name, polling, stores, paymentScript, stakingScript, witnesser } = props;
414+
const { env, logger, name, polling, stores, paymentScript, stakingScript, witnesser, purpose } = props;
409415
const providers = {
410416
assetProvider: await assetProviderFactory.create(env.ASSET_PROVIDER, env.ASSET_PROVIDER_PARAMS, logger),
411417
chainHistoryProvider: await chainHistoryProviderFactory.create(
@@ -433,7 +439,7 @@ export const getSharedWallet = async (props: GetSharedWalletProps) => {
433439
utxoProvider: await utxoProviderFactory.create(env.UTXO_PROVIDER, env.UTXO_PROVIDER_PARAMS, logger)
434440
};
435441
const wallet = createSharedWallet(
436-
{ name, polling },
442+
{ name, polling, purpose },
437443
{
438444
...providers,
439445
logger,

packages/e2e/src/scripts/mnemonic.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-console */
22
/* eslint-disable @typescript-eslint/no-floating-promises */
33
import * as Crypto from '@cardano-sdk/crypto';
4-
import { AddressType, InMemoryKeyAgent, util } from '@cardano-sdk/key-management';
4+
import { AddressType, InMemoryKeyAgent, KeyPurpose, util } from '@cardano-sdk/key-management';
55
import { localNetworkChainId } from '../util';
66

77
/** Generates a new set of Mnemonic words and prints them to the console. */
@@ -14,7 +14,8 @@ import { localNetworkChainId } from '../util';
1414
{
1515
chainId: localNetworkChainId,
1616
getPassphrase: async () => Buffer.from(''),
17-
mnemonicWords: mnemonicArray
17+
mnemonicWords: mnemonicArray,
18+
purpose: KeyPurpose.STANDARD
1819
},
1920
{
2021
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),

packages/e2e/src/tools/multi-delegation-data-gen/utils/utils.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* eslint-disable no-console, max-statements, max-params, @typescript-eslint/no-floating-promises */
2-
import { ValueTransferConfig, configLoader } from './config';
2+
import { Cardano } from '@cardano-sdk/core';
3+
import { KeyPurpose, util } from '@cardano-sdk/key-management';
4+
import { logger } from '@cardano-sdk/util-dev';
35

46
import { BaseWallet } from '@cardano-sdk/wallet';
5-
import { Cardano } from '@cardano-sdk/core';
67
import { Files, Paths } from './files';
78
import {
89
KeyAgentFactoryProps,
@@ -16,8 +17,7 @@ import {
1617
} from '../../../';
1718
import { Observable, filter, firstValueFrom, map } from 'rxjs';
1819
import { TaskResult, TerminalProgressMonitor } from './terminal-progress-monitor';
19-
import { logger } from '@cardano-sdk/util-dev';
20-
import { util } from '@cardano-sdk/key-management';
20+
import { ValueTransferConfig, configLoader } from './config';
2121
import chalk from 'chalk';
2222

2323
/**
@@ -96,8 +96,16 @@ export const loadConfiguration = async (monitor: TerminalProgressMonitor) => {
9696
export const waitForFundingWallet = async (monitor: TerminalProgressMonitor): Promise<BaseWallet> => {
9797
monitor.startTask('Waiting for funding wallet to be ready.');
9898

99-
const fundingWallet = (await getWallet({ env, idx: 0, logger, name: 'Funding wallet', polling: { interval: 500 } }))
100-
.wallet;
99+
const fundingWallet = (
100+
await getWallet({
101+
env,
102+
idx: 0,
103+
logger,
104+
name: 'Funding wallet',
105+
polling: { interval: 500 },
106+
purpose: KeyPurpose.STANDARD
107+
})
108+
).wallet;
101109

102110
await walletReady(fundingWallet);
103111

@@ -132,7 +140,8 @@ export const createDelegationWallet = async (monitor: TerminalProgressMonitor) =
132140
idx: 0,
133141
logger,
134142
name: 'Delegation Wallet',
135-
polling: { interval: 500 }
143+
polling: { interval: 500 },
144+
purpose: KeyPurpose.STANDARD
136145
})
137146
).wallet;
138147
};

packages/e2e/src/util/createMockKeyAgent.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Bip32PublicKeyHex, SodiumBip32Ed25519 } from '@cardano-sdk/crypto';
22
import { Cardano } from '@cardano-sdk/core';
3-
import { GroupedAddress, KeyAgent, KeyAgentType } from '@cardano-sdk/key-management';
3+
import { GroupedAddress, KeyAgent, KeyAgentType, KeyPurpose } from '@cardano-sdk/key-management';
44

55
const accountIndex = 0;
66
const chainId = Cardano.ChainIds.Preview;
@@ -23,7 +23,8 @@ export const createMockKeyAgent = (deriveAddressesReturn: GroupedAddress[] = [])
2323
accountIndex,
2424
chainId,
2525
encryptedRootPrivateKeyBytes: [],
26-
extendedAccountPublicKey
26+
extendedAccountPublicKey,
27+
purpose: KeyPurpose.STANDARD
2728
},
2829
signBlob: jest.fn(),
2930
signTransaction: jest.fn()

packages/e2e/src/util/handle-util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Asset, Cardano, Handle, Serialization, metadatum, nativeScriptPolicyId,
22
import { FinalizeTxProps, ObservableWallet } from '@cardano-sdk/wallet';
33
import { HexBlob } from '@cardano-sdk/util';
44
import { InitializeTxProps } from '@cardano-sdk/tx-construction';
5-
import { KeyAgent, KeyRole, util as keyManagementUtil } from '@cardano-sdk/key-management';
5+
import { KeyAgent, KeyPurpose, KeyRole, util as keyManagementUtil } from '@cardano-sdk/key-management';
66
import { firstValueFrom } from 'rxjs';
77
import { readFile } from 'fs/promises';
88
import { submitAndConfirm } from './util';
@@ -79,6 +79,7 @@ export const createHandleMetadata = (handlePolicyId: string, handleNames: string
7979
export const createHandlePolicy = async (keyAgent: KeyAgent) => {
8080
const derivationPath = {
8181
index: 0,
82+
purpose: KeyPurpose.STANDARD,
8283
role: KeyRole.External
8384
};
8485
const pubKey = await keyAgent.derivePublicKey(derivationPath);

packages/e2e/src/util/util.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
timeout
1919
} from 'rxjs';
2020
import { FAST_OPERATION_TIMEOUT_DEFAULT, SYNC_TIMEOUT_DEFAULT } from '../defaults';
21-
import { InMemoryKeyAgent, TransactionSigner } from '@cardano-sdk/key-management';
21+
import { InMemoryKeyAgent, KeyPurpose, TransactionSigner } from '@cardano-sdk/key-management';
2222
import { InitializeTxProps } from '@cardano-sdk/tx-construction';
2323
import { TestWallet, networkInfoProviderFactory } from '../factories';
2424
import { getEnv, walletVariables } from '../environment';
@@ -228,17 +228,20 @@ export const submitCertificate = async (certificate: Cardano.Certificate, wallet
228228
* @param mnemonics The random set of mnemonics.
229229
* @param genesis Network genesis parameters
230230
* @param bip32Ed25519 The Ed25519 cryptography implementation.
231+
* @param purpose they key derivation purpose of either 1852 or 1854
231232
*/
232233
export const createStandaloneKeyAgent = async (
233234
mnemonics: string[],
234235
genesis: Cardano.CompactGenesis,
235-
bip32Ed25519: Crypto.Bip32Ed25519
236+
bip32Ed25519: Crypto.Bip32Ed25519,
237+
purpose: KeyPurpose
236238
) =>
237239
await InMemoryKeyAgent.fromBip39MnemonicWords(
238240
{
239241
chainId: genesis,
240242
getPassphrase: async () => Buffer.from(''),
241-
mnemonicWords: mnemonics
243+
mnemonicWords: mnemonics,
244+
purpose
242245
},
243246
{ bip32Ed25519, logger }
244247
);

packages/e2e/test/artillery/wallet-restoration/WalletRestoration.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AddressType, GroupedAddress, util } from '@cardano-sdk/key-management';
1+
import { AddressType, GroupedAddress, KeyPurpose, util } from '@cardano-sdk/key-management';
22
import { AddressesModel, WalletVars } from './types';
33
import { Cardano } from '@cardano-sdk/core';
44
import { FunctionHook } from '../artillery';
@@ -12,6 +12,7 @@ export const mapToGroupedAddress = (addrModel: AddressesModel): GroupedAddress =
1212
address: Cardano.PaymentAddress(addrModel.address),
1313
index: 0,
1414
networkId: addrModel.address.startsWith('addr_test') ? Cardano.NetworkId.Testnet : Cardano.NetworkId.Mainnet,
15+
purpose: KeyPurpose.STANDARD,
1516
rewardAccount: Cardano.RewardAccount(addrModel.stake_address),
1617
type: AddressType.External
1718
});
@@ -99,7 +100,8 @@ export const walletRestoration: FunctionHook<WalletVars> = async ({ vars, _uid }
99100
keyAgent,
100101
logger,
101102
name: `Test Wallet of VU with id: ${_uid}`,
102-
polling: { interval: 50 }
103+
polling: { interval: 50 },
104+
purpose: KeyPurpose.STANDARD
103105
});
104106

105107
vars.currentWallet = wallet;

packages/e2e/test/load-test-custom/wallet-restoration/wallet-restoration.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import path from 'path';
55
dotenv.config({ path: path.join(__dirname, '../../../.env') });
66
import { BaseWallet } from '@cardano-sdk/wallet';
77
import { Cardano } from '@cardano-sdk/core';
8-
import { GroupedAddress, util } from '@cardano-sdk/key-management';
8+
import { GroupedAddress, KeyPurpose, util } from '@cardano-sdk/key-management';
99
import { Logger } from 'ts-log';
1010
import { MINUTE, createMockKeyAgent, getEnv, getWallet, waitForWalletStateSettle, walletVariables } from '../../../src';
1111
import { logger } from '@cardano-sdk/util-dev';
@@ -48,7 +48,8 @@ const initWallets = async (walletsNum: number, addresses: GroupedAddress[]): Pro
4848
keyAgent,
4949
logger,
5050
name: 'Test Wallet',
51-
polling: { interval: 50 }
51+
polling: { interval: 50 },
52+
purpose: KeyPurpose.STANDARD
5253
});
5354
wallets.push(wallet);
5455
}

packages/e2e/test/local-network/register-pool.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import {
1212
walletReady,
1313
walletVariables
1414
} from '../../src';
15+
import { firstValueFrom } from 'rxjs';
1516
import { logger } from '@cardano-sdk/util-dev';
1617

1718
import * as Crypto from '@cardano-sdk/crypto';
18-
import { AddressType, KeyRole } from '@cardano-sdk/key-management';
19-
import { firstValueFrom } from 'rxjs';
19+
import { AddressType, KeyPurpose, KeyRole } from '@cardano-sdk/key-management';
2020

2121
const env = getEnv(walletVariables);
2222

@@ -54,15 +54,17 @@ describe('local-network/register-pool', () => {
5454
idx: 0,
5555
logger,
5656
name: 'Pool Wallet 1',
57-
polling: { interval: 500 }
57+
polling: { interval: 500 },
58+
purpose: KeyPurpose.STANDARD
5859
});
5960
wallet2 = await getWallet({
6061
customKeyParams: wallet2Params,
6162
env,
6263
idx: 0,
6364
logger,
6465
name: 'Pool Wallet 2',
65-
polling: { interval: 500 }
66+
polling: { interval: 500 },
67+
purpose: KeyPurpose.STANDARD
6668
});
6769

6870
await waitForWalletStateSettle(wallet1.wallet);

packages/e2e/test/long-running/multisig-wallet/multisig-delegation-rewards.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Crypto from '@cardano-sdk/crypto';
22
import { BaseWallet } from '@cardano-sdk/wallet';
33
import { Cardano, EraSummary, StakePoolProvider, createSlotEpochCalc } from '@cardano-sdk/core';
4-
import { InMemoryKeyAgent, KeyRole } from '@cardano-sdk/key-management';
4+
import { InMemoryKeyAgent, KeyPurpose, KeyRole } from '@cardano-sdk/key-management';
55
import { MultiSigTx } from './MultiSigTx';
66
import { MultiSigWallet } from './MultiSigWallet';
77
import { Observable, filter, firstValueFrom, map, take } from 'rxjs';
@@ -34,6 +34,7 @@ const charlotteMnemonics =
3434

3535
const DERIVATION_PATH = {
3636
index: 0,
37+
purpose: KeyPurpose.MULTI_SIG,
3738
role: KeyRole.External
3839
};
3940

@@ -63,7 +64,7 @@ const fundMultiSigWallet = async (sendingWallet: BaseWallet, address: Cardano.Pa
6364
const getKeyAgent = async (mnemonics: string, faucetWallet: BaseWallet, bip32Ed25519: Crypto.Bip32Ed25519) => {
6465
const genesis = await firstValueFrom(faucetWallet.genesisParameters$);
6566

66-
const keyAgent = await createStandaloneKeyAgent(mnemonics.split(' '), genesis, bip32Ed25519);
67+
const keyAgent = await createStandaloneKeyAgent(mnemonics.split(' '), genesis, bip32Ed25519, KeyPurpose.STANDARD);
6768

6869
const pubKey = await keyAgent.derivePublicKey(DERIVATION_PATH);
6970

@@ -135,7 +136,8 @@ describe('multi signature wallet', () => {
135136
env,
136137
logger,
137138
name: 'Faucet Wallet',
138-
polling: { interval: 50 }
139+
polling: { interval: 50 },
140+
purpose: KeyPurpose.MULTI_SIG
139141
}));
140142

141143
await walletReady(faucetWallet);

0 commit comments

Comments
 (0)