@mysten/sui 2.37.0 → 2.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cryptography/mnemonics.d.mts +4 -1
  3. package/dist/cryptography/mnemonics.d.mts.map +1 -1
  4. package/dist/cryptography/mnemonics.mjs +5 -2
  5. package/dist/cryptography/mnemonics.mjs.map +1 -1
  6. package/dist/cryptography/signature.d.mts +6 -6
  7. package/dist/cryptography/slip10.d.mts +5 -0
  8. package/dist/cryptography/slip10.d.mts.map +1 -0
  9. package/dist/cryptography/slip10.mjs +55 -0
  10. package/dist/cryptography/slip10.mjs.map +1 -0
  11. package/dist/grpc/proto/sui/forking/v1alpha/forking_service.client.d.mts +4 -4
  12. package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
  13. package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
  14. package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
  15. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
  16. package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
  17. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
  18. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.mts +4 -4
  19. package/dist/keypairs/ed25519/keypair.d.mts.map +1 -1
  20. package/dist/keypairs/ed25519/keypair.mjs +6 -9
  21. package/dist/keypairs/ed25519/keypair.mjs.map +1 -1
  22. package/dist/keypairs/mldsa65/index.d.mts +3 -2
  23. package/dist/keypairs/mldsa65/index.mjs +3 -2
  24. package/dist/keypairs/mldsa65/keypair.d.mts +19 -1
  25. package/dist/keypairs/mldsa65/keypair.d.mts.map +1 -1
  26. package/dist/keypairs/mldsa65/keypair.mjs +33 -1
  27. package/dist/keypairs/mldsa65/keypair.mjs.map +1 -1
  28. package/dist/transactions/Transaction.d.mts +6 -6
  29. package/dist/transactions/data/internal.d.mts +133 -133
  30. package/dist/transactions/data/internal.d.mts.map +1 -1
  31. package/dist/transactions/data/v1.d.mts +239 -239
  32. package/dist/transactions/data/v1.d.mts.map +1 -1
  33. package/dist/transactions/data/v2.d.mts +16 -16
  34. package/dist/transactions/data/v2.d.mts.map +1 -1
  35. package/dist/version.mjs +1 -1
  36. package/dist/version.mjs.map +1 -1
  37. package/dist/zklogin/bcs.d.mts +14 -14
  38. package/docs/cryptography/keypairs.md +4 -2
  39. package/package.json +5 -5
  40. package/src/cryptography/mnemonics.ts +5 -2
  41. package/src/cryptography/slip10.ts +84 -0
  42. package/src/keypairs/ed25519/keypair.ts +11 -14
  43. package/src/keypairs/mldsa65/index.ts +6 -1
  44. package/src/keypairs/mldsa65/keypair.ts +46 -0
  45. package/src/version.ts +1 -1
  46. package/dist/keypairs/ed25519/ed25519-hd-key.mjs +0 -45
  47. package/dist/keypairs/ed25519/ed25519-hd-key.mjs.map +0 -1
  48. package/src/keypairs/ed25519/ed25519-hd-key.ts +0 -83
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @mysten/sui.js
2
2
 
3
+ ## 2.38.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7b88b72: Add mnemonic derivation for ML-DSA-65: `MLDSA65Keypair.deriveKeypair` and
8
+ `deriveKeypairFromSeed` derive keys at `m/94'/784'/0'/0'/0'` with SLIP-0010 (hardened only,
9
+ `ML-DSA-65 seed` master key), matching `sui keytool`.
10
+
11
+ Ed25519 and ML-DSA-65 share one SLIP-0010 implementation. Derivation paths for both now reject
12
+ indices of 2^31 and above and non-canonical index spellings, which would otherwise wrap onto
13
+ another account, and seeds outside the SLIP-0010 range of 16 to 64 bytes.
14
+
3
15
  ## 2.37.0
4
16
 
5
17
  ### Minor Changes
@@ -2,9 +2,12 @@
2
2
  /**
3
3
  * Parse and validate a path that is compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'.
4
4
  *
5
+ * The purpose node distinguishes signature schemes: 44 for Ed25519 (the default) and 94 for ML-DSA-65.
6
+ *
5
7
  * @param path path string (e.g. `m/44'/784'/0'/0'/0'`).
8
+ * @param purpose purpose node of the scheme, defaults to 44.
6
9
  */
7
- declare function isValidHardenedPath(path: string): boolean;
10
+ declare function isValidHardenedPath(path: string, purpose?: number): boolean;
8
11
  /**
9
12
  * Parse and validate a path that is compliant to BIP-32 in form m/54'/784'/{account_index}'/{change_index}/{address_index}
10
13
  * for Secp256k1 and m/74'/784'/{account_index}'/{change_index}/{address_index} for Secp256r1.
@@ -1 +1 @@
1
- {"version":3,"file":"mnemonics.d.mts","names":[],"sources":["../../src/cryptography/mnemonics.ts"],"mappings":";;AAUA;;;;iBAAgB,mBAAA,CAAoB,IAAA;AAepC;;;;;AAYA;;;AAZA,iBAAgB,gBAAA,CAAiB,IAAA;;AAqBjC;;;;iBATgB,cAAA,CAAe,SAAA,WAAoB,UAAA;;;;;;iBASnC,iBAAA,CAAkB,SAAA"}
1
+ {"version":3,"file":"mnemonics.d.mts","names":[],"sources":["../../src/cryptography/mnemonics.ts"],"mappings":";;AAaA;;;;;AAeA;;iBAfgB,mBAAA,CAAoB,IAAA,UAAc,OAAA;;;AA2BlD;;;;;AASA;iBArBgB,gBAAA,CAAiB,IAAA;;;;;;iBAYjB,cAAA,CAAe,SAAA,WAAoB,UAAA;;;;;;iBASnC,iBAAA,CAAkB,SAAA"}
@@ -5,10 +5,13 @@ import { mnemonicToSeedSync } from "@scure/bip39";
5
5
  /**
6
6
  * Parse and validate a path that is compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'.
7
7
  *
8
+ * The purpose node distinguishes signature schemes: 44 for Ed25519 (the default) and 94 for ML-DSA-65.
9
+ *
8
10
  * @param path path string (e.g. `m/44'/784'/0'/0'/0'`).
11
+ * @param purpose purpose node of the scheme, defaults to 44.
9
12
  */
10
- function isValidHardenedPath(path) {
11
- if (!(/* @__PURE__ */ new RegExp("^m\\/44'\\/784'\\/[0-9]+'\\/[0-9]+'\\/[0-9]+'+$")).test(path)) return false;
13
+ function isValidHardenedPath(path, purpose = 44) {
14
+ if (!(/* @__PURE__ */ new RegExp(`^m\\/${purpose}'\\/784'\\/[0-9]+'\\/[0-9]+'\\/[0-9]+'+$`)).test(path)) return false;
12
15
  return true;
13
16
  }
14
17
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"mnemonics.mjs","names":["bip39MnemonicToSeedSync"],"sources":["../../src/cryptography/mnemonics.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { toHex } from '@mysten/bcs';\nimport { mnemonicToSeedSync as bip39MnemonicToSeedSync } from '@scure/bip39';\n\n/**\n * Parse and validate a path that is compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'.\n *\n * @param path path string (e.g. `m/44'/784'/0'/0'/0'`).\n */\nexport function isValidHardenedPath(path: string): boolean {\n\tif (!new RegExp(\"^m\\\\/44'\\\\/784'\\\\/[0-9]+'\\\\/[0-9]+'\\\\/[0-9]+'+$\").test(path)) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n/**\n * Parse and validate a path that is compliant to BIP-32 in form m/54'/784'/{account_index}'/{change_index}/{address_index}\n * for Secp256k1 and m/74'/784'/{account_index}'/{change_index}/{address_index} for Secp256r1.\n *\n * Note that the purpose for Secp256k1 is registered as 54, to differentiate from Ed25519 with purpose 44.\n *\n * @param path path string (e.g. `m/54'/784'/0'/0/0`).\n */\nexport function isValidBIP32Path(path: string): boolean {\n\tif (!new RegExp(\"^m\\\\/(54|74)'\\\\/784'\\\\/[0-9]+'\\\\/[0-9]+\\\\/[0-9]+$\").test(path)) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n/**\n * Uses KDF to derive 64 bytes of key data from mnemonic with empty password.\n *\n * @param mnemonics 12 words string split by spaces.\n */\nexport function mnemonicToSeed(mnemonics: string): Uint8Array {\n\treturn bip39MnemonicToSeedSync(mnemonics, '');\n}\n\n/**\n * Derive the seed in hex format from a 12-word mnemonic string.\n *\n * @param mnemonics 12 words string split by spaces.\n */\nexport function mnemonicToSeedHex(mnemonics: string): string {\n\treturn toHex(mnemonicToSeed(mnemonics));\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,oBAAoB,MAAuB;AAC1D,KAAI,kBAAC,IAAI,OAAO,kDAAkD,EAAC,KAAK,KAAK,CAC5E,QAAO;AAER,QAAO;;;;;;;;;;AAWR,SAAgB,iBAAiB,MAAuB;AACvD,KAAI,kBAAC,IAAI,OAAO,oDAAoD,EAAC,KAAK,KAAK,CAC9E,QAAO;AAER,QAAO;;;;;;;AAQR,SAAgB,eAAe,WAA+B;AAC7D,QAAOA,mBAAwB,WAAW,GAAG;;;;;;;AAQ9C,SAAgB,kBAAkB,WAA2B;AAC5D,QAAO,MAAM,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"mnemonics.mjs","names":["bip39MnemonicToSeedSync"],"sources":["../../src/cryptography/mnemonics.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { toHex } from '@mysten/bcs';\nimport { mnemonicToSeedSync as bip39MnemonicToSeedSync } from '@scure/bip39';\n\n/**\n * Parse and validate a path that is compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'.\n *\n * The purpose node distinguishes signature schemes: 44 for Ed25519 (the default) and 94 for ML-DSA-65.\n *\n * @param path path string (e.g. `m/44'/784'/0'/0'/0'`).\n * @param purpose purpose node of the scheme, defaults to 44.\n */\nexport function isValidHardenedPath(path: string, purpose = 44): boolean {\n\tif (!new RegExp(`^m\\\\/${purpose}'\\\\/784'\\\\/[0-9]+'\\\\/[0-9]+'\\\\/[0-9]+'+$`).test(path)) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n/**\n * Parse and validate a path that is compliant to BIP-32 in form m/54'/784'/{account_index}'/{change_index}/{address_index}\n * for Secp256k1 and m/74'/784'/{account_index}'/{change_index}/{address_index} for Secp256r1.\n *\n * Note that the purpose for Secp256k1 is registered as 54, to differentiate from Ed25519 with purpose 44.\n *\n * @param path path string (e.g. `m/54'/784'/0'/0/0`).\n */\nexport function isValidBIP32Path(path: string): boolean {\n\tif (!new RegExp(\"^m\\\\/(54|74)'\\\\/784'\\\\/[0-9]+'\\\\/[0-9]+\\\\/[0-9]+$\").test(path)) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n/**\n * Uses KDF to derive 64 bytes of key data from mnemonic with empty password.\n *\n * @param mnemonics 12 words string split by spaces.\n */\nexport function mnemonicToSeed(mnemonics: string): Uint8Array {\n\treturn bip39MnemonicToSeedSync(mnemonics, '');\n}\n\n/**\n * Derive the seed in hex format from a 12-word mnemonic string.\n *\n * @param mnemonics 12 words string split by spaces.\n */\nexport function mnemonicToSeedHex(mnemonics: string): string {\n\treturn toHex(mnemonicToSeed(mnemonics));\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,oBAAoB,MAAc,UAAU,IAAa;AACxE,KAAI,kBAAC,IAAI,OAAO,QAAQ,QAAQ,0CAA0C,EAAC,KAAK,KAAK,CACpF,QAAO;AAER,QAAO;;;;;;;;;;AAWR,SAAgB,iBAAiB,MAAuB;AACvD,KAAI,kBAAC,IAAI,OAAO,oDAAoD,EAAC,KAAK,KAAK,CAC9E,QAAO;AAER,QAAO;;;;;;;AAQR,SAAgB,eAAe,WAA+B;AAC7D,QAAOA,mBAAwB,WAAW,GAAG;;;;;;;AAQ9C,SAAgB,kBAAkB,WAA2B;AAC5D,QAAO,MAAM,eAAe,UAAU,CAAC"}
@@ -23,6 +23,12 @@ declare function toSerializedSignature({
23
23
  * Decodes a serialized signature into its constituent components: the signature scheme, the actual signature, and the public key
24
24
  */
25
25
  declare function parseSerializedSignature(serializedSignature: string): {
26
+ serializedSignature: string;
27
+ signatureScheme: "ED25519" | "Secp256k1" | "Secp256r1" | "MLDSA65";
28
+ signature: Uint8Array<ArrayBuffer>;
29
+ publicKey: Uint8Array<ArrayBuffer>;
30
+ bytes: Uint8Array<ArrayBuffer>;
31
+ } | {
26
32
  signatureScheme: "Passkey";
27
33
  serializedSignature: string;
28
34
  signature: Uint8Array<ArrayBufferLike>;
@@ -30,12 +36,6 @@ declare function parseSerializedSignature(serializedSignature: string): {
30
36
  clientDataJson: string;
31
37
  userSignature: Uint8Array<ArrayBuffer>;
32
38
  publicKey: Uint8Array<ArrayBuffer>;
33
- } | {
34
- serializedSignature: string;
35
- signatureScheme: "ED25519" | "Secp256k1" | "Secp256r1" | "MLDSA65";
36
- signature: Uint8Array<ArrayBuffer>;
37
- publicKey: Uint8Array<ArrayBuffer>;
38
- bytes: Uint8Array<ArrayBuffer>;
39
39
  } | {
40
40
  serializedSignature: string;
41
41
  signatureScheme: "ZkLogin";
@@ -0,0 +1,5 @@
1
+ //#region src/cryptography/slip10.d.ts
2
+ declare const MLDSA65_SLIP10_MASTER_KEY = "ML-DSA-65 seed";
3
+ //#endregion
4
+ export { MLDSA65_SLIP10_MASTER_KEY };
5
+ //# sourceMappingURL=slip10.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slip10.d.mts","names":[],"sources":["../../src/cryptography/slip10.ts"],"mappings":";cAgBa,yBAAA"}
@@ -0,0 +1,55 @@
1
+ import { sha512 } from "@noble/hashes/sha2.js";
2
+ import { hmac } from "@noble/hashes/hmac.js";
3
+
4
+ //#region src/cryptography/slip10.ts
5
+ const ED25519_SLIP10_MASTER_KEY = "ed25519 seed";
6
+ const MLDSA65_SLIP10_MASTER_KEY = "ML-DSA-65 seed";
7
+ const HARDENED_OFFSET = 2147483648;
8
+ const MIN_SEED_LENGTH = 16;
9
+ const MAX_SEED_LENGTH = 64;
10
+ const pathRegex = /^m(\/(0|[1-9][0-9]*)')+$/;
11
+ const getMasterKeyFromSeed = (masterKey, seed) => {
12
+ return split(hmac(sha512, new TextEncoder().encode(masterKey), seed));
13
+ };
14
+ const CKDPriv = ({ key, chainCode }, index) => {
15
+ const data = new Uint8Array(1 + key.length + 4);
16
+ data.set(key, 1);
17
+ new DataView(data.buffer).setUint32(1 + key.length, index);
18
+ const I = hmac(sha512, chainCode, data);
19
+ data.fill(0);
20
+ return split(I);
21
+ };
22
+ const split = (I) => {
23
+ const node = {
24
+ key: I.slice(0, 32),
25
+ chainCode: I.slice(32)
26
+ };
27
+ I.fill(0);
28
+ return node;
29
+ };
30
+ const wipe = ({ key, chainCode }) => {
31
+ key.fill(0);
32
+ chainCode.fill(0);
33
+ };
34
+ /**
35
+ * Derive the SLIP-0010 node at `path` from `seed` under `masterKey`. Every level must be
36
+ * hardened; neither scheme has public derivation. The node secret at the end of the path
37
+ * is the Ed25519 private key or the FIPS 204 keygen seed.
38
+ */
39
+ const derivePath = (masterKey, path, seed) => {
40
+ if (!pathRegex.test(path)) throw new Error("Invalid derivation path");
41
+ if (seed.length < MIN_SEED_LENGTH || seed.length > MAX_SEED_LENGTH) throw new Error(`Invalid seed length: expected ${MIN_SEED_LENGTH} to ${MAX_SEED_LENGTH} bytes`);
42
+ const segments = path.split("/").slice(1).map((el) => parseInt(el.slice(0, -1), 10));
43
+ if (segments.some((segment) => segment >= HARDENED_OFFSET)) throw new Error("Invalid derivation path");
44
+ let node = getMasterKeyFromSeed(masterKey, seed);
45
+ for (const segment of segments) {
46
+ const child = CKDPriv(node, (segment | HARDENED_OFFSET) >>> 0);
47
+ wipe(node);
48
+ node = child;
49
+ }
50
+ return node;
51
+ };
52
+
53
+ //#endregion
54
+ export { ED25519_SLIP10_MASTER_KEY, MLDSA65_SLIP10_MASTER_KEY, derivePath };
55
+ //# sourceMappingURL=slip10.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slip10.mjs","names":[],"sources":["../../src/cryptography/slip10.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// SLIP-0010 hardened derivation for Ed25519 and ML-DSA-65. The master key string picks\n// the tree; the HMAC-SHA512 walk below it is the same. Mirrors `fastcrypto::slip10`.\n\nimport { hmac } from '@noble/hashes/hmac.js';\nimport { sha512 } from '@noble/hashes/sha2.js';\n\nexport type Slip10Node = {\n\tkey: Uint8Array;\n\tchainCode: Uint8Array;\n};\n\nexport const ED25519_SLIP10_MASTER_KEY = 'ed25519 seed';\n// Proposed in https://github.com/satoshilabs/slips/pull/1968.\nexport const MLDSA65_SLIP10_MASTER_KEY = 'ML-DSA-65 seed';\n\nconst HARDENED_OFFSET = 0x80000000;\n\n// SLIP-0010 seeds are 128 to 512 bits.\nconst MIN_SEED_LENGTH = 16;\nconst MAX_SEED_LENGTH = 64;\n\n// Canonical decimal indices only; the range is checked in `derivePath`.\nconst pathRegex = /^m(\\/(0|[1-9][0-9]*)')+$/;\n\nconst getMasterKeyFromSeed = (masterKey: string, seed: Uint8Array): Slip10Node => {\n\tconst I = hmac(sha512, new TextEncoder().encode(masterKey), seed);\n\treturn split(I);\n};\n\nconst CKDPriv = ({ key, chainCode }: Slip10Node, index: number): Slip10Node => {\n\tconst data = new Uint8Array(1 + key.length + 4);\n\tdata.set(key, 1);\n\tnew DataView(data.buffer).setUint32(1 + key.length, index);\n\n\tconst I = hmac(sha512, chainCode, data);\n\tdata.fill(0);\n\treturn split(I);\n};\n\n// Copies the halves out and wipes the HMAC output, so no node secret outlives its use.\nconst split = (I: Uint8Array): Slip10Node => {\n\tconst node = { key: I.slice(0, 32), chainCode: I.slice(32) };\n\tI.fill(0);\n\treturn node;\n};\n\nconst wipe = ({ key, chainCode }: Slip10Node) => {\n\tkey.fill(0);\n\tchainCode.fill(0);\n};\n\n/**\n * Derive the SLIP-0010 node at `path` from `seed` under `masterKey`. Every level must be\n * hardened; neither scheme has public derivation. The node secret at the end of the path\n * is the Ed25519 private key or the FIPS 204 keygen seed.\n */\nexport const derivePath = (masterKey: string, path: string, seed: Uint8Array): Slip10Node => {\n\tif (!pathRegex.test(path)) {\n\t\tthrow new Error('Invalid derivation path');\n\t}\n\tif (seed.length < MIN_SEED_LENGTH || seed.length > MAX_SEED_LENGTH) {\n\t\tthrow new Error(`Invalid seed length: expected ${MIN_SEED_LENGTH} to ${MAX_SEED_LENGTH} bytes`);\n\t}\n\n\tconst segments = path\n\t\t.split('/')\n\t\t.slice(1)\n\t\t.map((el) => parseInt(el.slice(0, -1), 10));\n\t// An index of 2^31 or more would collide with a hardened index after the OR below.\n\tif (segments.some((segment) => segment >= HARDENED_OFFSET)) {\n\t\tthrow new Error('Invalid derivation path');\n\t}\n\n\tlet node = getMasterKeyFromSeed(masterKey, seed);\n\tfor (const segment of segments) {\n\t\tconst child = CKDPriv(node, (segment | HARDENED_OFFSET) >>> 0);\n\t\twipe(node);\n\t\tnode = child;\n\t}\n\treturn node;\n};\n"],"mappings":";;;;AAcA,MAAa,4BAA4B;AAEzC,MAAa,4BAA4B;AAEzC,MAAM,kBAAkB;AAGxB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AAGxB,MAAM,YAAY;AAElB,MAAM,wBAAwB,WAAmB,SAAiC;AAEjF,QAAO,MADG,KAAK,QAAQ,IAAI,aAAa,CAAC,OAAO,UAAU,EAAE,KAAK,CAClD;;AAGhB,MAAM,WAAW,EAAE,KAAK,aAAyB,UAA8B;CAC9E,MAAM,OAAO,IAAI,WAAW,IAAI,IAAI,SAAS,EAAE;AAC/C,MAAK,IAAI,KAAK,EAAE;AAChB,KAAI,SAAS,KAAK,OAAO,CAAC,UAAU,IAAI,IAAI,QAAQ,MAAM;CAE1D,MAAM,IAAI,KAAK,QAAQ,WAAW,KAAK;AACvC,MAAK,KAAK,EAAE;AACZ,QAAO,MAAM,EAAE;;AAIhB,MAAM,SAAS,MAA8B;CAC5C,MAAM,OAAO;EAAE,KAAK,EAAE,MAAM,GAAG,GAAG;EAAE,WAAW,EAAE,MAAM,GAAG;EAAE;AAC5D,GAAE,KAAK,EAAE;AACT,QAAO;;AAGR,MAAM,QAAQ,EAAE,KAAK,gBAA4B;AAChD,KAAI,KAAK,EAAE;AACX,WAAU,KAAK,EAAE;;;;;;;AAQlB,MAAa,cAAc,WAAmB,MAAc,SAAiC;AAC5F,KAAI,CAAC,UAAU,KAAK,KAAK,CACxB,OAAM,IAAI,MAAM,0BAA0B;AAE3C,KAAI,KAAK,SAAS,mBAAmB,KAAK,SAAS,gBAClD,OAAM,IAAI,MAAM,iCAAiC,gBAAgB,MAAM,gBAAgB,QAAQ;CAGhG,MAAM,WAAW,KACf,MAAM,IAAI,CACV,MAAM,EAAE,CACR,KAAK,OAAO,SAAS,GAAG,MAAM,GAAG,GAAG,EAAE,GAAG,CAAC;AAE5C,KAAI,SAAS,MAAM,YAAY,WAAW,gBAAgB,CACzD,OAAM,IAAI,MAAM,0BAA0B;CAG3C,IAAI,OAAO,qBAAqB,WAAW,KAAK;AAChD,MAAK,MAAM,WAAW,UAAU;EAC/B,MAAM,QAAQ,QAAQ,OAAO,UAAU,qBAAqB,EAAE;AAC9D,OAAK,KAAK;AACV,SAAO;;AAER,QAAO"}
@@ -1,6 +1,6 @@
1
1
  import { AdvanceCheckpointRequest, AdvanceCheckpointResponse, AdvanceClockRequest, AdvanceClockResponse, GetStatusRequest, GetStatusResponse } from "./forking_service.mjs";
2
- import * as _protobuf_ts_runtime0 from "@protobuf-ts/runtime";
3
- import * as _protobuf_ts_runtime_rpc0 from "@protobuf-ts/runtime-rpc";
2
+ import * as _protobuf_ts_runtime6 from "@protobuf-ts/runtime";
3
+ import * as _protobuf_ts_runtime_rpc6 from "@protobuf-ts/runtime-rpc";
4
4
  import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
5
5
 
6
6
  //#region src/grpc/proto/sui/forking/v1alpha/forking_service.client.d.ts
@@ -37,9 +37,9 @@ interface IForkingServiceClient {
37
37
  declare class ForkingServiceClient implements IForkingServiceClient, ServiceInfo {
38
38
  private readonly _transport;
39
39
  typeName: string;
40
- methods: _protobuf_ts_runtime_rpc0.MethodInfo<any, any>[];
40
+ methods: _protobuf_ts_runtime_rpc6.MethodInfo<any, any>[];
41
41
  options: {
42
- [extensionName: string]: _protobuf_ts_runtime0.JsonValue;
42
+ [extensionName: string]: _protobuf_ts_runtime6.JsonValue;
43
43
  };
44
44
  constructor(_transport: RpcTransport);
45
45
  /**
@@ -1,6 +1,6 @@
1
1
  import { BatchGetObjectsRequest, BatchGetObjectsResponse, BatchGetTransactionsRequest, BatchGetTransactionsResponse, GetCheckpointRequest, GetCheckpointResponse, GetEpochRequest, GetEpochResponse, GetObjectRequest, GetObjectResponse, GetServiceInfoRequest, GetServiceInfoResponse, GetTransactionRequest, GetTransactionResponse, ListCheckpointsRequest, ListCheckpointsResponse, ListEventsRequest, ListEventsResponse, ListTransactionsRequest, ListTransactionsResponse } from "./ledger_service.mjs";
2
- import * as _protobuf_ts_runtime1 from "@protobuf-ts/runtime";
3
- import * as _protobuf_ts_runtime_rpc1 from "@protobuf-ts/runtime-rpc";
2
+ import * as _protobuf_ts_runtime2 from "@protobuf-ts/runtime";
3
+ import * as _protobuf_ts_runtime_rpc2 from "@protobuf-ts/runtime-rpc";
4
4
  import { RpcOptions, RpcTransport, ServerStreamingCall, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
5
5
 
6
6
  //#region src/grpc/proto/sui/rpc/v2/ledger_service.client.d.ts
@@ -73,9 +73,9 @@ interface ILedgerServiceClient {
73
73
  declare class LedgerServiceClient implements ILedgerServiceClient, ServiceInfo {
74
74
  private readonly _transport;
75
75
  typeName: string;
76
- methods: _protobuf_ts_runtime_rpc1.MethodInfo<any, any>[];
76
+ methods: _protobuf_ts_runtime_rpc2.MethodInfo<any, any>[];
77
77
  options: {
78
- [extensionName: string]: _protobuf_ts_runtime1.JsonValue;
78
+ [extensionName: string]: _protobuf_ts_runtime2.JsonValue;
79
79
  };
80
80
  constructor(_transport: RpcTransport);
81
81
  /**
@@ -1,6 +1,6 @@
1
1
  import { GetDatatypeRequest, GetDatatypeResponse, GetFunctionRequest, GetFunctionResponse, GetPackageRequest, GetPackageResponse, ListPackageVersionsRequest, ListPackageVersionsResponse } from "./move_package_service.mjs";
2
- import * as _protobuf_ts_runtime2 from "@protobuf-ts/runtime";
3
- import * as _protobuf_ts_runtime_rpc2 from "@protobuf-ts/runtime-rpc";
2
+ import * as _protobuf_ts_runtime0 from "@protobuf-ts/runtime";
3
+ import * as _protobuf_ts_runtime_rpc0 from "@protobuf-ts/runtime-rpc";
4
4
  import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
5
5
 
6
6
  //#region src/grpc/proto/sui/rpc/v2/move_package_service.client.d.ts
@@ -31,9 +31,9 @@ interface IMovePackageServiceClient {
31
31
  declare class MovePackageServiceClient implements IMovePackageServiceClient, ServiceInfo {
32
32
  private readonly _transport;
33
33
  typeName: string;
34
- methods: _protobuf_ts_runtime_rpc2.MethodInfo<any, any>[];
34
+ methods: _protobuf_ts_runtime_rpc0.MethodInfo<any, any>[];
35
35
  options: {
36
- [extensionName: string]: _protobuf_ts_runtime2.JsonValue;
36
+ [extensionName: string]: _protobuf_ts_runtime0.JsonValue;
37
37
  };
38
38
  constructor(_transport: RpcTransport);
39
39
  /**
@@ -1,6 +1,6 @@
1
1
  import { LookupNameRequest, LookupNameResponse, ReverseLookupNameRequest, ReverseLookupNameResponse } from "./name_service.mjs";
2
- import * as _protobuf_ts_runtime6 from "@protobuf-ts/runtime";
3
- import * as _protobuf_ts_runtime_rpc6 from "@protobuf-ts/runtime-rpc";
2
+ import * as _protobuf_ts_runtime5 from "@protobuf-ts/runtime";
3
+ import * as _protobuf_ts_runtime_rpc5 from "@protobuf-ts/runtime-rpc";
4
4
  import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
5
5
 
6
6
  //#region src/grpc/proto/sui/rpc/v2/name_service.client.d.ts
@@ -23,9 +23,9 @@ interface INameServiceClient {
23
23
  declare class NameServiceClient implements INameServiceClient, ServiceInfo {
24
24
  private readonly _transport;
25
25
  typeName: string;
26
- methods: _protobuf_ts_runtime_rpc6.MethodInfo<any, any>[];
26
+ methods: _protobuf_ts_runtime_rpc5.MethodInfo<any, any>[];
27
27
  options: {
28
- [extensionName: string]: _protobuf_ts_runtime6.JsonValue;
28
+ [extensionName: string]: _protobuf_ts_runtime5.JsonValue;
29
29
  };
30
30
  constructor(_transport: RpcTransport);
31
31
  /**
@@ -1,6 +1,6 @@
1
1
  import { VerifySignatureRequest, VerifySignatureResponse } from "./signature_verification_service.mjs";
2
- import * as _protobuf_ts_runtime3 from "@protobuf-ts/runtime";
3
- import * as _protobuf_ts_runtime_rpc3 from "@protobuf-ts/runtime-rpc";
2
+ import * as _protobuf_ts_runtime0 from "@protobuf-ts/runtime";
3
+ import * as _protobuf_ts_runtime_rpc0 from "@protobuf-ts/runtime-rpc";
4
4
  import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
5
5
 
6
6
  //#region src/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.ts
@@ -21,9 +21,9 @@ interface ISignatureVerificationServiceClient {
21
21
  declare class SignatureVerificationServiceClient implements ISignatureVerificationServiceClient, ServiceInfo {
22
22
  private readonly _transport;
23
23
  typeName: string;
24
- methods: _protobuf_ts_runtime_rpc3.MethodInfo<any, any>[];
24
+ methods: _protobuf_ts_runtime_rpc0.MethodInfo<any, any>[];
25
25
  options: {
26
- [extensionName: string]: _protobuf_ts_runtime3.JsonValue;
26
+ [extensionName: string]: _protobuf_ts_runtime0.JsonValue;
27
27
  };
28
28
  constructor(_transport: RpcTransport);
29
29
  /**
@@ -1,6 +1,6 @@
1
1
  import { GetBalanceRequest, GetBalanceResponse, GetCoinInfoRequest, GetCoinInfoResponse, ListBalancesRequest, ListBalancesResponse, ListDynamicFieldsRequest, ListDynamicFieldsResponse, ListOwnedObjectsRequest, ListOwnedObjectsResponse } from "./state_service.mjs";
2
- import * as _protobuf_ts_runtime4 from "@protobuf-ts/runtime";
3
- import * as _protobuf_ts_runtime_rpc4 from "@protobuf-ts/runtime-rpc";
2
+ import * as _protobuf_ts_runtime3 from "@protobuf-ts/runtime";
3
+ import * as _protobuf_ts_runtime_rpc3 from "@protobuf-ts/runtime-rpc";
4
4
  import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
5
5
 
6
6
  //#region src/grpc/proto/sui/rpc/v2/state_service.client.d.ts
@@ -35,9 +35,9 @@ interface IStateServiceClient {
35
35
  declare class StateServiceClient implements IStateServiceClient, ServiceInfo {
36
36
  private readonly _transport;
37
37
  typeName: string;
38
- methods: _protobuf_ts_runtime_rpc4.MethodInfo<any, any>[];
38
+ methods: _protobuf_ts_runtime_rpc3.MethodInfo<any, any>[];
39
39
  options: {
40
- [extensionName: string]: _protobuf_ts_runtime4.JsonValue;
40
+ [extensionName: string]: _protobuf_ts_runtime3.JsonValue;
41
41
  };
42
42
  constructor(_transport: RpcTransport);
43
43
  /**
@@ -1,6 +1,6 @@
1
1
  import { SubscribeCheckpointsRequest, SubscribeCheckpointsResponse, SubscribeEventsRequest, SubscribeEventsResponse, SubscribeTransactionsRequest, SubscribeTransactionsResponse } from "./subscription_service.mjs";
2
- import * as _protobuf_ts_runtime5 from "@protobuf-ts/runtime";
3
- import * as _protobuf_ts_runtime_rpc5 from "@protobuf-ts/runtime-rpc";
2
+ import * as _protobuf_ts_runtime1 from "@protobuf-ts/runtime";
3
+ import * as _protobuf_ts_runtime_rpc1 from "@protobuf-ts/runtime-rpc";
4
4
  import { RpcOptions, RpcTransport, ServerStreamingCall, ServiceInfo } from "@protobuf-ts/runtime-rpc";
5
5
 
6
6
  //#region src/grpc/proto/sui/rpc/v2/subscription_service.client.d.ts
@@ -100,9 +100,9 @@ interface ISubscriptionServiceClient {
100
100
  declare class SubscriptionServiceClient implements ISubscriptionServiceClient, ServiceInfo {
101
101
  private readonly _transport;
102
102
  typeName: string;
103
- methods: _protobuf_ts_runtime_rpc5.MethodInfo<any, any>[];
103
+ methods: _protobuf_ts_runtime_rpc1.MethodInfo<any, any>[];
104
104
  options: {
105
- [extensionName: string]: _protobuf_ts_runtime5.JsonValue;
105
+ [extensionName: string]: _protobuf_ts_runtime1.JsonValue;
106
106
  };
107
107
  constructor(_transport: RpcTransport);
108
108
  /**
@@ -1,6 +1,6 @@
1
1
  import { ExecuteTransactionRequest, ExecuteTransactionResponse, SimulateTransactionRequest, SimulateTransactionResponse } from "./transaction_execution_service.mjs";
2
- import * as _protobuf_ts_runtime0 from "@protobuf-ts/runtime";
3
- import * as _protobuf_ts_runtime_rpc0 from "@protobuf-ts/runtime-rpc";
2
+ import * as _protobuf_ts_runtime4 from "@protobuf-ts/runtime";
3
+ import * as _protobuf_ts_runtime_rpc4 from "@protobuf-ts/runtime-rpc";
4
4
  import { RpcOptions, RpcTransport, ServiceInfo, UnaryCall } from "@protobuf-ts/runtime-rpc";
5
5
 
6
6
  //#region src/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.ts
@@ -23,9 +23,9 @@ interface ITransactionExecutionServiceClient {
23
23
  declare class TransactionExecutionServiceClient implements ITransactionExecutionServiceClient, ServiceInfo {
24
24
  private readonly _transport;
25
25
  typeName: string;
26
- methods: _protobuf_ts_runtime_rpc0.MethodInfo<any, any>[];
26
+ methods: _protobuf_ts_runtime_rpc4.MethodInfo<any, any>[];
27
27
  options: {
28
- [extensionName: string]: _protobuf_ts_runtime0.JsonValue;
28
+ [extensionName: string]: _protobuf_ts_runtime4.JsonValue;
29
29
  };
30
30
  constructor(_transport: RpcTransport);
31
31
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"keypair.d.mts","names":[],"sources":["../../../src/keypairs/ed25519/keypair.ts"],"mappings":";;;;;cAiBa,+BAAA;;AAAb;;;;UAOiB,kBAAA;EAChB,SAAA,EAAW,UAAA;EACX,SAAA,EAAW,UAAA;AAAA;;;;cAMC,cAAA,SAAuB,OAAA;EAAA,QAC3B,OAAA;EAPa;;AAMtB;;;;cASa,OAAA,GAAU,kBAAA;EA0BH;;;EAPnB,YAAA,CAAA,GAAgB,eAAA;EAiFC;;;EAAA,OA1EV,QAAA,CAAA,GAAY,cAAA;EAqFqC;;;;;;;;;;EAAA,OAnEjD,aAAA,CACN,SAAA,EAAW,UAAA,WACX,OAAA;IAAY,cAAA;EAAA,IACV,cAAA;EArBI;;;EAyDP,YAAA,CAAA,GAAgB,gBAAA;EAtCf;;;EA6CD,YAAA,CAAA;EAPA;;;EAiBM,IAAA,CAAK,IAAA,EAAM,UAAA,GAAU,OAAA,CAAA,UAAA,CAAA,WAAA;EAAV;;;;;;;EAAA,OAWV,aAAA,CAAc,SAAA,UAAmB,IAAA,YAAgB,cAAA;EAAA;;;;;;;;EAAA,OAoBjD,qBAAA,CAAsB,IAAA,WAAe,UAAA,EAAY,IAAA,YAAgB,cAAA;AAAA"}
1
+ {"version":3,"file":"keypair.d.mts","names":[],"sources":["../../../src/keypairs/ed25519/keypair.ts"],"mappings":";;;;;cAiBa,+BAAA;;AAAb;;;;UAOiB,kBAAA;EAChB,SAAA,EAAW,UAAA;EACX,SAAA,EAAW,UAAA;AAAA;;;;cAMC,cAAA,SAAuB,OAAA;EAAA,QAC3B,OAAA;EAPa;;AAMtB;;;;cASa,OAAA,GAAU,kBAAA;EA0BH;;;EAPnB,YAAA,CAAA,GAAgB,eAAA;EAiFC;;;EAAA,OA1EV,QAAA,CAAA,GAAY,cAAA;EAqFqC;;;;;;;;;;EAAA,OAnEjD,aAAA,CACN,SAAA,EAAW,UAAA,WACX,OAAA;IAAY,cAAA;EAAA,IACV,cAAA;EArBI;;;EAyDP,YAAA,CAAA,GAAgB,gBAAA;EAtCf;;;EA6CD,YAAA,CAAA;EAPA;;;EAiBM,IAAA,CAAK,IAAA,EAAM,UAAA,GAAU,OAAA,CAAA,UAAA,CAAA,WAAA;EAAV;;;;;;;EAAA,OAWV,aAAA,CAAc,SAAA,UAAmB,IAAA,YAAgB,cAAA;EAAA;;;;;;;;EAAA,OAYjD,qBAAA,CAAsB,IAAA,WAAe,UAAA,EAAY,IAAA,YAAgB,cAAA;AAAA"}
@@ -1,8 +1,8 @@
1
- import { isValidHardenedPath, mnemonicToSeedHex } from "../../cryptography/mnemonics.mjs";
1
+ import { isValidHardenedPath, mnemonicToSeed } from "../../cryptography/mnemonics.mjs";
2
2
  import { Keypair, PRIVATE_KEY_SIZE, decodeSuiPrivateKey, encodeSuiPrivateKey } from "../../cryptography/keypair.mjs";
3
- import { derivePath } from "./ed25519-hd-key.mjs";
3
+ import { ED25519_SLIP10_MASTER_KEY, derivePath } from "../../cryptography/slip10.mjs";
4
4
  import { Ed25519PublicKey } from "./publickey.mjs";
5
- import { toHex } from "@mysten/bcs";
5
+ import { fromHex } from "@mysten/bcs";
6
6
  import { ed25519 } from "@noble/curves/ed25519.js";
7
7
 
8
8
  //#region src/keypairs/ed25519/keypair.ts
@@ -102,10 +102,7 @@ var Ed25519Keypair = class Ed25519Keypair extends Keypair {
102
102
  * be compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'.
103
103
  */
104
104
  static deriveKeypair(mnemonics, path) {
105
- if (path == null) path = DEFAULT_ED25519_DERIVATION_PATH;
106
- if (!isValidHardenedPath(path)) throw new Error("Invalid derivation path");
107
- const { key } = derivePath(path, mnemonicToSeedHex(mnemonics));
108
- return Ed25519Keypair.fromSecretKey(key);
105
+ return Ed25519Keypair.deriveKeypairFromSeed(mnemonicToSeed(mnemonics), path);
109
106
  }
110
107
  /**
111
108
  * Derive Ed25519 keypair from mnemonicSeed and path.
@@ -118,8 +115,8 @@ var Ed25519Keypair = class Ed25519Keypair extends Keypair {
118
115
  static deriveKeypairFromSeed(seed, path) {
119
116
  if (path == null) path = DEFAULT_ED25519_DERIVATION_PATH;
120
117
  if (!isValidHardenedPath(path)) throw new Error("Invalid derivation path");
121
- const seedHex = typeof seed === "string" ? seed : toHex(seed);
122
- const { key } = derivePath(path, seedHex);
118
+ const { key, chainCode } = derivePath(ED25519_SLIP10_MASTER_KEY, path, typeof seed === "string" ? fromHex(seed) : seed);
119
+ chainCode.fill(0);
123
120
  return Ed25519Keypair.fromSecretKey(key);
124
121
  }
125
122
  };
@@ -1 +1 @@
1
- {"version":3,"file":"keypair.mjs","names":[],"sources":["../../../src/keypairs/ed25519/keypair.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toHex } from '@mysten/bcs';\nimport { ed25519 } from '@noble/curves/ed25519.js';\n\nimport {\n\tdecodeSuiPrivateKey,\n\tencodeSuiPrivateKey,\n\tKeypair,\n\tPRIVATE_KEY_SIZE,\n} from '../../cryptography/keypair.js';\nimport { isValidHardenedPath, mnemonicToSeedHex } from '../../cryptography/mnemonics.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { derivePath } from './ed25519-hd-key.js';\nimport { Ed25519PublicKey } from './publickey.js';\n\nexport const DEFAULT_ED25519_DERIVATION_PATH = \"m/44'/784'/0'/0'/0'\";\n\n/**\n * Ed25519 Keypair data. The publickey is the 32-byte public key and\n * the secretkey is 64-byte, where the first 32 bytes is the secret\n * key and the last 32 bytes is the public key.\n */\nexport interface Ed25519KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Ed25519 Keypair used for signing transactions.\n */\nexport class Ed25519Keypair extends Keypair {\n\tprivate keypair: Ed25519KeypairData;\n\n\t/**\n\t * Create a new Ed25519 keypair instance.\n\t * Generate random keypair if no {@link Ed25519Keypair} is provided.\n\t *\n\t * @param keypair Ed25519 keypair\n\t */\n\tconstructor(keypair?: Ed25519KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = {\n\t\t\t\tpublicKey: keypair.publicKey,\n\t\t\t\tsecretKey: keypair.secretKey.slice(0, 32),\n\t\t\t};\n\t\t} else {\n\t\t\tconst privateKey = ed25519.utils.randomSecretKey();\n\t\t\tthis.keypair = {\n\t\t\t\tpublicKey: ed25519.getPublicKey(privateKey),\n\t\t\t\tsecretKey: privateKey,\n\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair ED25519\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'ED25519';\n\t}\n\n\t/**\n\t * Generate a new random Ed25519 keypair\n\t */\n\tstatic generate(): Ed25519Keypair {\n\t\tconst secretKey = ed25519.utils.randomSecretKey();\n\t\treturn new Ed25519Keypair({\n\t\t\tpublicKey: ed25519.getPublicKey(secretKey),\n\t\t\tsecretKey,\n\t\t});\n\t}\n\n\t/**\n\t * Create a Ed25519 keypair from a raw secret key byte array, also known as seed.\n\t * This is NOT the private scalar which is result of hashing and bit clamping of\n\t * the raw secret key.\n\t *\n\t * @throws error if the provided secret key is invalid and validation is not skipped.\n\t *\n\t * @param secretKey secret key as a byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Ed25519Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.scheme !== 'ED25519') {\n\t\t\t\tthrow new Error(`Expected a ED25519 keypair, got ${decoded.scheme}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey, options);\n\t\t}\n\n\t\tconst secretKeyLength = secretKey.length;\n\t\tif (secretKeyLength !== PRIVATE_KEY_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`Wrong secretKey size. Expected ${PRIVATE_KEY_SIZE} bytes, got ${secretKeyLength}.`,\n\t\t\t);\n\t\t}\n\t\tconst keypair = {\n\t\t\tpublicKey: ed25519.getPublicKey(secretKey),\n\t\t\tsecretKey,\n\t\t};\n\n\t\tif (!options || !options.skipValidation) {\n\t\t\tconst encoder = new TextEncoder();\n\t\t\tconst signData = encoder.encode('sui validation');\n\t\t\tconst signature = ed25519.sign(signData, secretKey);\n\t\t\tif (!ed25519.verify(signature, signData, keypair.publicKey)) {\n\t\t\t\tthrow new Error('provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Ed25519Keypair(keypair);\n\t}\n\n\t/**\n\t * The public key for this Ed25519 keypair\n\t */\n\tgetPublicKey(): Ed25519PublicKey {\n\t\treturn new Ed25519PublicKey(this.keypair.publicKey);\n\t}\n\n\t/**\n\t * The Bech32 secret key string for this Ed25519 keypair\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeSuiPrivateKey(\n\t\t\tthis.keypair.secretKey.slice(0, PRIVATE_KEY_SIZE),\n\t\t\tthis.getKeyScheme(),\n\t\t);\n\t}\n\n\t/**\n\t * Return the signature for the provided data using Ed25519.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\treturn ed25519.sign(data, this.keypair.secretKey) as Uint8Array<ArrayBuffer>;\n\t}\n\n\t/**\n\t * Derive Ed25519 keypair from mnemonics and path. The mnemonics must be normalized\n\t * and validated against the english wordlist.\n\t *\n\t * If path is none, it will default to m/44'/784'/0'/0'/0', otherwise the path must\n\t * be compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'.\n\t */\n\tstatic deriveKeypair(mnemonics: string, path?: string): Ed25519Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_ED25519_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidHardenedPath(path)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\tconst { key } = derivePath(path, mnemonicToSeedHex(mnemonics));\n\n\t\treturn Ed25519Keypair.fromSecretKey(key);\n\t}\n\n\t/**\n\t * Derive Ed25519 keypair from mnemonicSeed and path.\n\t *\n\t * If path is none, it will default to m/44'/784'/0'/0'/0', otherwise the path must\n\t * be compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'.\n\t *\n\t * @param seed - The seed as a hex string or Uint8Array.\n\t */\n\tstatic deriveKeypairFromSeed(seed: string | Uint8Array, path?: string): Ed25519Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_ED25519_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidHardenedPath(path)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\tconst seedHex = typeof seed === 'string' ? seed : toHex(seed);\n\t\tconst { key } = derivePath(path, seedHex);\n\n\t\treturn Ed25519Keypair.fromSecretKey(key);\n\t}\n}\n"],"mappings":";;;;;;;;AAiBA,MAAa,kCAAkC;;;;AAe/C,IAAa,iBAAb,MAAa,uBAAuB,QAAQ;;;;;;;CAS3C,YAAY,SAA8B;AACzC,SAAO;AACP,MAAI,QACH,MAAK,UAAU;GACd,WAAW,QAAQ;GACnB,WAAW,QAAQ,UAAU,MAAM,GAAG,GAAG;GACzC;OACK;GACN,MAAM,aAAa,QAAQ,MAAM,iBAAiB;AAClD,QAAK,UAAU;IACd,WAAW,QAAQ,aAAa,WAAW;IAC3C,WAAW;IACX;;;;;;CAOH,eAAgC;AAC/B,SAAO;;;;;CAMR,OAAO,WAA2B;EACjC,MAAM,YAAY,QAAQ,MAAM,iBAAiB;AACjD,SAAO,IAAI,eAAe;GACzB,WAAW,QAAQ,aAAa,UAAU;GAC1C;GACA,CAAC;;;;;;;;;;;;CAaH,OAAO,cACN,WACA,SACiB;AACjB,MAAI,OAAO,cAAc,UAAU;GAClC,MAAM,UAAU,oBAAoB,UAAU;AAE9C,OAAI,QAAQ,WAAW,UACtB,OAAM,IAAI,MAAM,mCAAmC,QAAQ,SAAS;AAGrE,UAAO,KAAK,cAAc,QAAQ,WAAW,QAAQ;;EAGtD,MAAM,kBAAkB,UAAU;AAClC,MAAI,oBAAoB,iBACvB,OAAM,IAAI,MACT,kCAAkC,iBAAiB,cAAc,gBAAgB,GACjF;EAEF,MAAM,UAAU;GACf,WAAW,QAAQ,aAAa,UAAU;GAC1C;GACA;AAED,MAAI,CAAC,WAAW,CAAC,QAAQ,gBAAgB;GAExC,MAAM,WADU,IAAI,aAAa,CACR,OAAO,iBAAiB;GACjD,MAAM,YAAY,QAAQ,KAAK,UAAU,UAAU;AACnD,OAAI,CAAC,QAAQ,OAAO,WAAW,UAAU,QAAQ,UAAU,CAC1D,OAAM,IAAI,MAAM,gCAAgC;;AAGlD,SAAO,IAAI,eAAe,QAAQ;;;;;CAMnC,eAAiC;AAChC,SAAO,IAAI,iBAAiB,KAAK,QAAQ,UAAU;;;;;CAMpD,eAAuB;AACtB,SAAO,oBACN,KAAK,QAAQ,UAAU,MAAM,GAAG,iBAAiB,EACjD,KAAK,cAAc,CACnB;;;;;CAMF,MAAM,KAAK,MAAkB;AAC5B,SAAO,QAAQ,KAAK,MAAM,KAAK,QAAQ,UAAU;;;;;;;;;CAUlD,OAAO,cAAc,WAAmB,MAA+B;AACtE,MAAI,QAAQ,KACX,QAAO;AAER,MAAI,CAAC,oBAAoB,KAAK,CAC7B,OAAM,IAAI,MAAM,0BAA0B;EAE3C,MAAM,EAAE,QAAQ,WAAW,MAAM,kBAAkB,UAAU,CAAC;AAE9D,SAAO,eAAe,cAAc,IAAI;;;;;;;;;;CAWzC,OAAO,sBAAsB,MAA2B,MAA+B;AACtF,MAAI,QAAQ,KACX,QAAO;AAER,MAAI,CAAC,oBAAoB,KAAK,CAC7B,OAAM,IAAI,MAAM,0BAA0B;EAE3C,MAAM,UAAU,OAAO,SAAS,WAAW,OAAO,MAAM,KAAK;EAC7D,MAAM,EAAE,QAAQ,WAAW,MAAM,QAAQ;AAEzC,SAAO,eAAe,cAAc,IAAI"}
1
+ {"version":3,"file":"keypair.mjs","names":[],"sources":["../../../src/keypairs/ed25519/keypair.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex } from '@mysten/bcs';\nimport { ed25519 } from '@noble/curves/ed25519.js';\n\nimport {\n\tdecodeSuiPrivateKey,\n\tencodeSuiPrivateKey,\n\tKeypair,\n\tPRIVATE_KEY_SIZE,\n} from '../../cryptography/keypair.js';\nimport { isValidHardenedPath, mnemonicToSeed } from '../../cryptography/mnemonics.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { derivePath, ED25519_SLIP10_MASTER_KEY } from '../../cryptography/slip10.js';\nimport { Ed25519PublicKey } from './publickey.js';\n\nexport const DEFAULT_ED25519_DERIVATION_PATH = \"m/44'/784'/0'/0'/0'\";\n\n/**\n * Ed25519 Keypair data. The publickey is the 32-byte public key and\n * the secretkey is 64-byte, where the first 32 bytes is the secret\n * key and the last 32 bytes is the public key.\n */\nexport interface Ed25519KeypairData {\n\tpublicKey: Uint8Array;\n\tsecretKey: Uint8Array;\n}\n\n/**\n * An Ed25519 Keypair used for signing transactions.\n */\nexport class Ed25519Keypair extends Keypair {\n\tprivate keypair: Ed25519KeypairData;\n\n\t/**\n\t * Create a new Ed25519 keypair instance.\n\t * Generate random keypair if no {@link Ed25519Keypair} is provided.\n\t *\n\t * @param keypair Ed25519 keypair\n\t */\n\tconstructor(keypair?: Ed25519KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = {\n\t\t\t\tpublicKey: keypair.publicKey,\n\t\t\t\tsecretKey: keypair.secretKey.slice(0, 32),\n\t\t\t};\n\t\t} else {\n\t\t\tconst privateKey = ed25519.utils.randomSecretKey();\n\t\t\tthis.keypair = {\n\t\t\t\tpublicKey: ed25519.getPublicKey(privateKey),\n\t\t\t\tsecretKey: privateKey,\n\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair ED25519\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'ED25519';\n\t}\n\n\t/**\n\t * Generate a new random Ed25519 keypair\n\t */\n\tstatic generate(): Ed25519Keypair {\n\t\tconst secretKey = ed25519.utils.randomSecretKey();\n\t\treturn new Ed25519Keypair({\n\t\t\tpublicKey: ed25519.getPublicKey(secretKey),\n\t\t\tsecretKey,\n\t\t});\n\t}\n\n\t/**\n\t * Create a Ed25519 keypair from a raw secret key byte array, also known as seed.\n\t * This is NOT the private scalar which is result of hashing and bit clamping of\n\t * the raw secret key.\n\t *\n\t * @throws error if the provided secret key is invalid and validation is not skipped.\n\t *\n\t * @param secretKey secret key as a byte array or Bech32 secret key string\n\t * @param options: skip secret key validation\n\t */\n\tstatic fromSecretKey(\n\t\tsecretKey: Uint8Array | string,\n\t\toptions?: { skipValidation?: boolean },\n\t): Ed25519Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.scheme !== 'ED25519') {\n\t\t\t\tthrow new Error(`Expected a ED25519 keypair, got ${decoded.scheme}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey, options);\n\t\t}\n\n\t\tconst secretKeyLength = secretKey.length;\n\t\tif (secretKeyLength !== PRIVATE_KEY_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`Wrong secretKey size. Expected ${PRIVATE_KEY_SIZE} bytes, got ${secretKeyLength}.`,\n\t\t\t);\n\t\t}\n\t\tconst keypair = {\n\t\t\tpublicKey: ed25519.getPublicKey(secretKey),\n\t\t\tsecretKey,\n\t\t};\n\n\t\tif (!options || !options.skipValidation) {\n\t\t\tconst encoder = new TextEncoder();\n\t\t\tconst signData = encoder.encode('sui validation');\n\t\t\tconst signature = ed25519.sign(signData, secretKey);\n\t\t\tif (!ed25519.verify(signature, signData, keypair.publicKey)) {\n\t\t\t\tthrow new Error('provided secretKey is invalid');\n\t\t\t}\n\t\t}\n\t\treturn new Ed25519Keypair(keypair);\n\t}\n\n\t/**\n\t * The public key for this Ed25519 keypair\n\t */\n\tgetPublicKey(): Ed25519PublicKey {\n\t\treturn new Ed25519PublicKey(this.keypair.publicKey);\n\t}\n\n\t/**\n\t * The Bech32 secret key string for this Ed25519 keypair\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeSuiPrivateKey(\n\t\t\tthis.keypair.secretKey.slice(0, PRIVATE_KEY_SIZE),\n\t\t\tthis.getKeyScheme(),\n\t\t);\n\t}\n\n\t/**\n\t * Return the signature for the provided data using Ed25519.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\treturn ed25519.sign(data, this.keypair.secretKey) as Uint8Array<ArrayBuffer>;\n\t}\n\n\t/**\n\t * Derive Ed25519 keypair from mnemonics and path. The mnemonics must be normalized\n\t * and validated against the english wordlist.\n\t *\n\t * If path is none, it will default to m/44'/784'/0'/0'/0', otherwise the path must\n\t * be compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'.\n\t */\n\tstatic deriveKeypair(mnemonics: string, path?: string): Ed25519Keypair {\n\t\treturn Ed25519Keypair.deriveKeypairFromSeed(mnemonicToSeed(mnemonics), path);\n\t}\n\n\t/**\n\t * Derive Ed25519 keypair from mnemonicSeed and path.\n\t *\n\t * If path is none, it will default to m/44'/784'/0'/0'/0', otherwise the path must\n\t * be compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'.\n\t *\n\t * @param seed - The seed as a hex string or Uint8Array.\n\t */\n\tstatic deriveKeypairFromSeed(seed: string | Uint8Array, path?: string): Ed25519Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_ED25519_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidHardenedPath(path)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\tconst { key, chainCode } = derivePath(\n\t\t\tED25519_SLIP10_MASTER_KEY,\n\t\t\tpath,\n\t\t\ttypeof seed === 'string' ? fromHex(seed) : seed,\n\t\t);\n\n\t\t// The keypair keeps `key` as its secret; only the chain code is surplus.\n\t\tchainCode.fill(0);\n\t\treturn Ed25519Keypair.fromSecretKey(key);\n\t}\n}\n"],"mappings":";;;;;;;;AAiBA,MAAa,kCAAkC;;;;AAe/C,IAAa,iBAAb,MAAa,uBAAuB,QAAQ;;;;;;;CAS3C,YAAY,SAA8B;AACzC,SAAO;AACP,MAAI,QACH,MAAK,UAAU;GACd,WAAW,QAAQ;GACnB,WAAW,QAAQ,UAAU,MAAM,GAAG,GAAG;GACzC;OACK;GACN,MAAM,aAAa,QAAQ,MAAM,iBAAiB;AAClD,QAAK,UAAU;IACd,WAAW,QAAQ,aAAa,WAAW;IAC3C,WAAW;IACX;;;;;;CAOH,eAAgC;AAC/B,SAAO;;;;;CAMR,OAAO,WAA2B;EACjC,MAAM,YAAY,QAAQ,MAAM,iBAAiB;AACjD,SAAO,IAAI,eAAe;GACzB,WAAW,QAAQ,aAAa,UAAU;GAC1C;GACA,CAAC;;;;;;;;;;;;CAaH,OAAO,cACN,WACA,SACiB;AACjB,MAAI,OAAO,cAAc,UAAU;GAClC,MAAM,UAAU,oBAAoB,UAAU;AAE9C,OAAI,QAAQ,WAAW,UACtB,OAAM,IAAI,MAAM,mCAAmC,QAAQ,SAAS;AAGrE,UAAO,KAAK,cAAc,QAAQ,WAAW,QAAQ;;EAGtD,MAAM,kBAAkB,UAAU;AAClC,MAAI,oBAAoB,iBACvB,OAAM,IAAI,MACT,kCAAkC,iBAAiB,cAAc,gBAAgB,GACjF;EAEF,MAAM,UAAU;GACf,WAAW,QAAQ,aAAa,UAAU;GAC1C;GACA;AAED,MAAI,CAAC,WAAW,CAAC,QAAQ,gBAAgB;GAExC,MAAM,WADU,IAAI,aAAa,CACR,OAAO,iBAAiB;GACjD,MAAM,YAAY,QAAQ,KAAK,UAAU,UAAU;AACnD,OAAI,CAAC,QAAQ,OAAO,WAAW,UAAU,QAAQ,UAAU,CAC1D,OAAM,IAAI,MAAM,gCAAgC;;AAGlD,SAAO,IAAI,eAAe,QAAQ;;;;;CAMnC,eAAiC;AAChC,SAAO,IAAI,iBAAiB,KAAK,QAAQ,UAAU;;;;;CAMpD,eAAuB;AACtB,SAAO,oBACN,KAAK,QAAQ,UAAU,MAAM,GAAG,iBAAiB,EACjD,KAAK,cAAc,CACnB;;;;;CAMF,MAAM,KAAK,MAAkB;AAC5B,SAAO,QAAQ,KAAK,MAAM,KAAK,QAAQ,UAAU;;;;;;;;;CAUlD,OAAO,cAAc,WAAmB,MAA+B;AACtE,SAAO,eAAe,sBAAsB,eAAe,UAAU,EAAE,KAAK;;;;;;;;;;CAW7E,OAAO,sBAAsB,MAA2B,MAA+B;AACtF,MAAI,QAAQ,KACX,QAAO;AAER,MAAI,CAAC,oBAAoB,KAAK,CAC7B,OAAM,IAAI,MAAM,0BAA0B;EAE3C,MAAM,EAAE,KAAK,cAAc,WAC1B,2BACA,MACA,OAAO,SAAS,WAAW,QAAQ,KAAK,GAAG,KAC3C;AAGD,YAAU,KAAK,EAAE;AACjB,SAAO,eAAe,cAAc,IAAI"}
@@ -1,3 +1,4 @@
1
1
  import { MLDSA65PublicKey, MLDSA65_PUBLIC_KEY_SIZE, MLDSA65_SIGNATURE_SIZE } from "./publickey.mjs";
2
- import { MLDSA65Keypair, MLDSA65KeypairData } from "./keypair.mjs";
3
- export { MLDSA65Keypair, type MLDSA65KeypairData, MLDSA65PublicKey, MLDSA65_PUBLIC_KEY_SIZE, MLDSA65_SIGNATURE_SIZE };
2
+ import { DEFAULT_MLDSA65_DERIVATION_PATH, MLDSA65Keypair, MLDSA65KeypairData } from "./keypair.mjs";
3
+ import { MLDSA65_SLIP10_MASTER_KEY } from "../../cryptography/slip10.mjs";
4
+ export { DEFAULT_MLDSA65_DERIVATION_PATH, MLDSA65Keypair, type MLDSA65KeypairData, MLDSA65PublicKey, MLDSA65_PUBLIC_KEY_SIZE, MLDSA65_SIGNATURE_SIZE, MLDSA65_SLIP10_MASTER_KEY };
@@ -1,4 +1,5 @@
1
+ import { MLDSA65_SLIP10_MASTER_KEY } from "../../cryptography/slip10.mjs";
1
2
  import { MLDSA65PublicKey, MLDSA65_PUBLIC_KEY_SIZE, MLDSA65_SIGNATURE_SIZE } from "./publickey.mjs";
2
- import { MLDSA65Keypair } from "./keypair.mjs";
3
+ import { DEFAULT_MLDSA65_DERIVATION_PATH, MLDSA65Keypair } from "./keypair.mjs";
3
4
 
4
- export { MLDSA65Keypair, MLDSA65PublicKey, MLDSA65_PUBLIC_KEY_SIZE, MLDSA65_SIGNATURE_SIZE };
5
+ export { DEFAULT_MLDSA65_DERIVATION_PATH, MLDSA65Keypair, MLDSA65PublicKey, MLDSA65_PUBLIC_KEY_SIZE, MLDSA65_SIGNATURE_SIZE, MLDSA65_SLIP10_MASTER_KEY };
@@ -3,6 +3,7 @@ import { Keypair } from "../../cryptography/keypair.mjs";
3
3
  import { MLDSA65PublicKey } from "./publickey.mjs";
4
4
 
5
5
  //#region src/keypairs/mldsa65/keypair.d.ts
6
+ declare const DEFAULT_MLDSA65_DERIVATION_PATH = "m/94'/784'/0'/0'/0'";
6
7
  /**
7
8
  * ML-DSA-65 Keypair data. `seed` is the 32-byte FIPS 204 seed, the only form
8
9
  * that is ever exported or stored (`suiprivkey`, keystore). `secretKey` is the
@@ -61,7 +62,24 @@ declare class MLDSA65Keypair extends Keypair {
61
62
  * same data twice gives two different valid signatures.
62
63
  */
63
64
  sign(data: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
65
+ /**
66
+ * Derive ML-DSA-65 keypair from mnemonics and path. The mnemonics must be normalized
67
+ * and validated against the english wordlist.
68
+ *
69
+ * If path is none, it will default to m/94'/784'/0'/0'/0', otherwise the path must
70
+ * be compliant to SLIP-0010 in form m/94'/784'/{account_index}'/{change_index}'/{address_index}'.
71
+ */
72
+ static deriveKeypair(mnemonics: string, path?: string): MLDSA65Keypair;
73
+ /**
74
+ * Derive ML-DSA-65 keypair from mnemonicSeed and path.
75
+ *
76
+ * If path is none, it will default to m/94'/784'/0'/0'/0', otherwise the path must
77
+ * be compliant to SLIP-0010 in form m/94'/784'/{account_index}'/{change_index}'/{address_index}'.
78
+ *
79
+ * @param seed - The seed as a hex string or Uint8Array.
80
+ */
81
+ static deriveKeypairFromSeed(seed: string | Uint8Array, path?: string): MLDSA65Keypair;
64
82
  }
65
83
  //#endregion
66
- export { MLDSA65Keypair, MLDSA65KeypairData };
84
+ export { DEFAULT_MLDSA65_DERIVATION_PATH, MLDSA65Keypair, MLDSA65KeypairData };
67
85
  //# sourceMappingURL=keypair.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"keypair.d.mts","names":[],"sources":["../../../src/keypairs/mldsa65/keypair.ts"],"mappings":";;;;;;;AAoBA;;;UAAiB,kBAAA;EAChB,IAAA,EAAM,UAAA;EACN,SAAA,EAAW,UAAA;EACX,SAAA,EAAW,UAAA;AAAA;;;;cAMC,cAAA,SAAuB,OAAA;EAAA,QAC3B,OAAA;EAPG;;;AAMZ;;;cASa,OAAA,GAAU,kBAAA;EAYN;;;EAAhB,YAAA,CAAA,GAAgB,eAAA;EA0CM;;;EAAA,OAnCf,QAAA,CAAA,GAAY,cAAA;EA2DQ;;;;;EAAA,OAlDpB,aAAA,CAAc,SAAA,EAAW,UAAA,YAAsB,cAAA;EArCnB;;;;;;EAAA,OA+D5B,QAAA,CAAS,IAAA,EAAM,UAAA,GAAa,cAAA;EAnC5B;;;EA0CP,YAAA,CAAA,GAAgB,gBAAA;EAjCK;;;EAwCrB,YAAA,CAAA;EAdgB;;;;;;EAwBV,IAAA,CAAK,IAAA,EAAM,UAAA,GAAU,OAAA,CAAA,UAAA,CAAA,WAAA;AAAA"}
1
+ {"version":3,"file":"keypair.d.mts","names":[],"sources":["../../../src/keypairs/mldsa65/keypair.ts"],"mappings":";;;;;cAkBa,+BAAA;;AAAb;;;;UASiB,kBAAA;EAChB,IAAA,EAAM,UAAA;EACN,SAAA,EAAW,UAAA;EACX,SAAA,EAAW,UAAA;AAAA;;;;cAMC,cAAA,SAAuB,OAAA;EAAA,QAC3B,OAAA;EATF;;;;;;cAiBM,OAAA,GAAU,kBAAA;EATV;;;EAqBZ,YAAA,CAAA,GAAgB,eAAA;EAAA;;;EAAA,OAOT,QAAA,CAAA,GAAY,cAAA;EAmCG;;;;;EAAA,OA1Bf,aAAA,CAAc,SAAA,EAAW,UAAA,YAAsB,cAAA;EAkD3B;;;;;;EAAA,OAxBpB,QAAA,CAAS,IAAA,EAAM,UAAA,GAAa,cAAA;EA/DA;;;EAsEnC,YAAA,CAAA,GAAgB,gBAAA;EA7DJ;;;EAoEZ,YAAA,CAAA;EAjDmB;;;;;;EA2Db,IAAA,CAAK,IAAA,EAAM,UAAA,GAAU,OAAA,CAAA,UAAA,CAAA,WAAA;EAxBX;;;;;;;EAAA,OAmCT,aAAA,CAAc,SAAA,UAAmB,IAAA,YAAgB,cAAA;EAX7B;;;;;;;;EAAA,OAuBpB,qBAAA,CAAsB,IAAA,WAAe,UAAA,EAAY,IAAA,YAAgB,cAAA;AAAA"}
@@ -1,9 +1,14 @@
1
+ import { isValidHardenedPath, mnemonicToSeed } from "../../cryptography/mnemonics.mjs";
1
2
  import { Keypair, PRIVATE_KEY_SIZE, decodeSuiPrivateKey, encodeSuiPrivateKey } from "../../cryptography/keypair.mjs";
3
+ import { MLDSA65_SLIP10_MASTER_KEY, derivePath } from "../../cryptography/slip10.mjs";
2
4
  import { MLDSA65PublicKey } from "./publickey.mjs";
5
+ import { fromHex } from "@mysten/bcs";
3
6
  import { randomBytes } from "@noble/hashes/utils.js";
4
7
  import { ml_dsa65 } from "@noble/post-quantum/ml-dsa.js";
5
8
 
6
9
  //#region src/keypairs/mldsa65/keypair.ts
10
+ const DEFAULT_MLDSA65_DERIVATION_PATH = "m/94'/784'/0'/0'/0'";
11
+ const MLDSA65_DERIVATION_PURPOSE = 94;
7
12
  /**
8
13
  * An ML-DSA-65 (FIPS 204) Keypair used for signing transactions.
9
14
  */
@@ -75,6 +80,33 @@ var MLDSA65Keypair = class MLDSA65Keypair extends Keypair {
75
80
  async sign(data) {
76
81
  return ml_dsa65.sign(data, this.keypair.secretKey);
77
82
  }
83
+ /**
84
+ * Derive ML-DSA-65 keypair from mnemonics and path. The mnemonics must be normalized
85
+ * and validated against the english wordlist.
86
+ *
87
+ * If path is none, it will default to m/94'/784'/0'/0'/0', otherwise the path must
88
+ * be compliant to SLIP-0010 in form m/94'/784'/{account_index}'/{change_index}'/{address_index}'.
89
+ */
90
+ static deriveKeypair(mnemonics, path) {
91
+ return MLDSA65Keypair.deriveKeypairFromSeed(mnemonicToSeed(mnemonics), path);
92
+ }
93
+ /**
94
+ * Derive ML-DSA-65 keypair from mnemonicSeed and path.
95
+ *
96
+ * If path is none, it will default to m/94'/784'/0'/0'/0', otherwise the path must
97
+ * be compliant to SLIP-0010 in form m/94'/784'/{account_index}'/{change_index}'/{address_index}'.
98
+ *
99
+ * @param seed - The seed as a hex string or Uint8Array.
100
+ */
101
+ static deriveKeypairFromSeed(seed, path) {
102
+ if (path == null) path = DEFAULT_MLDSA65_DERIVATION_PATH;
103
+ if (!isValidHardenedPath(path, MLDSA65_DERIVATION_PURPOSE)) throw new Error("Invalid derivation path");
104
+ const { key, chainCode } = derivePath(MLDSA65_SLIP10_MASTER_KEY, path, typeof seed === "string" ? fromHex(seed) : seed);
105
+ const keypair = MLDSA65Keypair.fromSecretKey(key);
106
+ key.fill(0);
107
+ chainCode.fill(0);
108
+ return keypair;
109
+ }
78
110
  };
79
111
  function expand(input) {
80
112
  const seed = Uint8Array.from(input);
@@ -87,5 +119,5 @@ function expand(input) {
87
119
  }
88
120
 
89
121
  //#endregion
90
- export { MLDSA65Keypair };
122
+ export { DEFAULT_MLDSA65_DERIVATION_PATH, MLDSA65Keypair };
91
123
  //# sourceMappingURL=keypair.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"keypair.mjs","names":[],"sources":["../../../src/keypairs/mldsa65/keypair.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { randomBytes } from '@noble/hashes/utils.js';\nimport { ml_dsa65 } from '@noble/post-quantum/ml-dsa.js';\n\nimport {\n\tdecodeSuiPrivateKey,\n\tencodeSuiPrivateKey,\n\tKeypair,\n\tPRIVATE_KEY_SIZE,\n} from '../../cryptography/keypair.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { MLDSA65PublicKey } from './publickey.js';\n\n/**\n * ML-DSA-65 Keypair data. `seed` is the 32-byte FIPS 204 seed, the only form\n * that is ever exported or stored (`suiprivkey`, keystore). `secretKey` is the\n * 4032-byte signing key expanded from it, kept so signing does not re-expand.\n */\nexport interface MLDSA65KeypairData {\n\tseed: Uint8Array;\n\tsecretKey: Uint8Array;\n\tpublicKey: Uint8Array;\n}\n\n/**\n * An ML-DSA-65 (FIPS 204) Keypair used for signing transactions.\n */\nexport class MLDSA65Keypair extends Keypair {\n\tprivate keypair: MLDSA65KeypairData;\n\n\t/**\n\t * Create a new ML-DSA-65 keypair instance.\n\t * Generate random keypair if no {@link MLDSA65Keypair} is provided.\n\t *\n\t * @param keypair ML-DSA-65 keypair\n\t */\n\tconstructor(keypair?: MLDSA65KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tthis.keypair = expand(randomBytes(PRIVATE_KEY_SIZE));\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair MLDSA65\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'MLDSA65';\n\t}\n\n\t/**\n\t * Generate a new random ML-DSA-65 keypair\n\t */\n\tstatic generate(): MLDSA65Keypair {\n\t\treturn new MLDSA65Keypair();\n\t}\n\n\t/**\n\t * Create an ML-DSA-65 keypair from its 32-byte seed.\n\t *\n\t * @param secretKey the 32-byte seed as a byte array or Bech32 secret key string\n\t */\n\tstatic fromSecretKey(secretKey: Uint8Array | string): MLDSA65Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.scheme !== 'MLDSA65') {\n\t\t\t\tthrow new Error(`Expected a MLDSA65 keypair, got ${decoded.scheme}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey);\n\t\t}\n\n\t\tif (secretKey.length !== PRIVATE_KEY_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`Wrong secretKey size. Expected ${PRIVATE_KEY_SIZE} bytes, got ${secretKey.length}.`,\n\t\t\t);\n\t\t}\n\n\t\treturn new MLDSA65Keypair(expand(secretKey));\n\t}\n\n\t/**\n\t * Generate a keypair from a 32 byte seed. Same as {@link fromSecretKey}:\n\t * for ML-DSA-65 the seed is the secret key.\n\t *\n\t * @param seed seed byte array\n\t */\n\tstatic fromSeed(seed: Uint8Array): MLDSA65Keypair {\n\t\treturn MLDSA65Keypair.fromSecretKey(seed);\n\t}\n\n\t/**\n\t * The public key for this ML-DSA-65 keypair\n\t */\n\tgetPublicKey(): MLDSA65PublicKey {\n\t\treturn new MLDSA65PublicKey(this.keypair.publicKey);\n\t}\n\n\t/**\n\t * The Bech32 secret key string for this ML-DSA-65 keypair, encoding the 32-byte seed.\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeSuiPrivateKey(this.keypair.seed, this.getKeyScheme());\n\t}\n\n\t/**\n\t * Return the signature for the provided data using ML-DSA-65.\n\t *\n\t * Hedged signing: 32 fresh random bytes go into every signature, so signing the\n\t * same data twice gives two different valid signatures.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\treturn ml_dsa65.sign(data, this.keypair.secretKey) as Uint8Array<ArrayBuffer>;\n\t}\n}\n\nfunction expand(input: Uint8Array): MLDSA65KeypairData {\n\t// Own the seed: the caller may wipe or reuse its buffer, and the exported\n\t// secret key must keep matching the signing key.\n\tconst seed = Uint8Array.from(input);\n\tconst { publicKey, secretKey } = ml_dsa65.keygen(seed);\n\treturn { seed, secretKey, publicKey };\n}\n"],"mappings":";;;;;;;;;AA6BA,IAAa,iBAAb,MAAa,uBAAuB,QAAQ;;;;;;;CAS3C,YAAY,SAA8B;AACzC,SAAO;AACP,MAAI,QACH,MAAK,UAAU;MAEf,MAAK,UAAU,OAAO,YAAY,iBAAiB,CAAC;;;;;CAOtD,eAAgC;AAC/B,SAAO;;;;;CAMR,OAAO,WAA2B;AACjC,SAAO,IAAI,gBAAgB;;;;;;;CAQ5B,OAAO,cAAc,WAAgD;AACpE,MAAI,OAAO,cAAc,UAAU;GAClC,MAAM,UAAU,oBAAoB,UAAU;AAE9C,OAAI,QAAQ,WAAW,UACtB,OAAM,IAAI,MAAM,mCAAmC,QAAQ,SAAS;AAGrE,UAAO,KAAK,cAAc,QAAQ,UAAU;;AAG7C,MAAI,UAAU,WAAW,iBACxB,OAAM,IAAI,MACT,kCAAkC,iBAAiB,cAAc,UAAU,OAAO,GAClF;AAGF,SAAO,IAAI,eAAe,OAAO,UAAU,CAAC;;;;;;;;CAS7C,OAAO,SAAS,MAAkC;AACjD,SAAO,eAAe,cAAc,KAAK;;;;;CAM1C,eAAiC;AAChC,SAAO,IAAI,iBAAiB,KAAK,QAAQ,UAAU;;;;;CAMpD,eAAuB;AACtB,SAAO,oBAAoB,KAAK,QAAQ,MAAM,KAAK,cAAc,CAAC;;;;;;;;CASnE,MAAM,KAAK,MAAkB;AAC5B,SAAO,SAAS,KAAK,MAAM,KAAK,QAAQ,UAAU;;;AAIpD,SAAS,OAAO,OAAuC;CAGtD,MAAM,OAAO,WAAW,KAAK,MAAM;CACnC,MAAM,EAAE,WAAW,cAAc,SAAS,OAAO,KAAK;AACtD,QAAO;EAAE;EAAM;EAAW;EAAW"}
1
+ {"version":3,"file":"keypair.mjs","names":[],"sources":["../../../src/keypairs/mldsa65/keypair.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex } from '@mysten/bcs';\nimport { randomBytes } from '@noble/hashes/utils.js';\nimport { ml_dsa65 } from '@noble/post-quantum/ml-dsa.js';\n\nimport {\n\tdecodeSuiPrivateKey,\n\tencodeSuiPrivateKey,\n\tKeypair,\n\tPRIVATE_KEY_SIZE,\n} from '../../cryptography/keypair.js';\nimport { isValidHardenedPath, mnemonicToSeed } from '../../cryptography/mnemonics.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport { derivePath, MLDSA65_SLIP10_MASTER_KEY } from '../../cryptography/slip10.js';\nimport { MLDSA65PublicKey } from './publickey.js';\n\nexport const DEFAULT_MLDSA65_DERIVATION_PATH = \"m/94'/784'/0'/0'/0'\";\n\nconst MLDSA65_DERIVATION_PURPOSE = 94;\n\n/**\n * ML-DSA-65 Keypair data. `seed` is the 32-byte FIPS 204 seed, the only form\n * that is ever exported or stored (`suiprivkey`, keystore). `secretKey` is the\n * 4032-byte signing key expanded from it, kept so signing does not re-expand.\n */\nexport interface MLDSA65KeypairData {\n\tseed: Uint8Array;\n\tsecretKey: Uint8Array;\n\tpublicKey: Uint8Array;\n}\n\n/**\n * An ML-DSA-65 (FIPS 204) Keypair used for signing transactions.\n */\nexport class MLDSA65Keypair extends Keypair {\n\tprivate keypair: MLDSA65KeypairData;\n\n\t/**\n\t * Create a new ML-DSA-65 keypair instance.\n\t * Generate random keypair if no {@link MLDSA65Keypair} is provided.\n\t *\n\t * @param keypair ML-DSA-65 keypair\n\t */\n\tconstructor(keypair?: MLDSA65KeypairData) {\n\t\tsuper();\n\t\tif (keypair) {\n\t\t\tthis.keypair = keypair;\n\t\t} else {\n\t\t\tthis.keypair = expand(randomBytes(PRIVATE_KEY_SIZE));\n\t\t}\n\t}\n\n\t/**\n\t * Get the key scheme of the keypair MLDSA65\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'MLDSA65';\n\t}\n\n\t/**\n\t * Generate a new random ML-DSA-65 keypair\n\t */\n\tstatic generate(): MLDSA65Keypair {\n\t\treturn new MLDSA65Keypair();\n\t}\n\n\t/**\n\t * Create an ML-DSA-65 keypair from its 32-byte seed.\n\t *\n\t * @param secretKey the 32-byte seed as a byte array or Bech32 secret key string\n\t */\n\tstatic fromSecretKey(secretKey: Uint8Array | string): MLDSA65Keypair {\n\t\tif (typeof secretKey === 'string') {\n\t\t\tconst decoded = decodeSuiPrivateKey(secretKey);\n\n\t\t\tif (decoded.scheme !== 'MLDSA65') {\n\t\t\t\tthrow new Error(`Expected a MLDSA65 keypair, got ${decoded.scheme}`);\n\t\t\t}\n\n\t\t\treturn this.fromSecretKey(decoded.secretKey);\n\t\t}\n\n\t\tif (secretKey.length !== PRIVATE_KEY_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`Wrong secretKey size. Expected ${PRIVATE_KEY_SIZE} bytes, got ${secretKey.length}.`,\n\t\t\t);\n\t\t}\n\n\t\treturn new MLDSA65Keypair(expand(secretKey));\n\t}\n\n\t/**\n\t * Generate a keypair from a 32 byte seed. Same as {@link fromSecretKey}:\n\t * for ML-DSA-65 the seed is the secret key.\n\t *\n\t * @param seed seed byte array\n\t */\n\tstatic fromSeed(seed: Uint8Array): MLDSA65Keypair {\n\t\treturn MLDSA65Keypair.fromSecretKey(seed);\n\t}\n\n\t/**\n\t * The public key for this ML-DSA-65 keypair\n\t */\n\tgetPublicKey(): MLDSA65PublicKey {\n\t\treturn new MLDSA65PublicKey(this.keypair.publicKey);\n\t}\n\n\t/**\n\t * The Bech32 secret key string for this ML-DSA-65 keypair, encoding the 32-byte seed.\n\t */\n\tgetSecretKey(): string {\n\t\treturn encodeSuiPrivateKey(this.keypair.seed, this.getKeyScheme());\n\t}\n\n\t/**\n\t * Return the signature for the provided data using ML-DSA-65.\n\t *\n\t * Hedged signing: 32 fresh random bytes go into every signature, so signing the\n\t * same data twice gives two different valid signatures.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\treturn ml_dsa65.sign(data, this.keypair.secretKey) as Uint8Array<ArrayBuffer>;\n\t}\n\n\t/**\n\t * Derive ML-DSA-65 keypair from mnemonics and path. The mnemonics must be normalized\n\t * and validated against the english wordlist.\n\t *\n\t * If path is none, it will default to m/94'/784'/0'/0'/0', otherwise the path must\n\t * be compliant to SLIP-0010 in form m/94'/784'/{account_index}'/{change_index}'/{address_index}'.\n\t */\n\tstatic deriveKeypair(mnemonics: string, path?: string): MLDSA65Keypair {\n\t\treturn MLDSA65Keypair.deriveKeypairFromSeed(mnemonicToSeed(mnemonics), path);\n\t}\n\n\t/**\n\t * Derive ML-DSA-65 keypair from mnemonicSeed and path.\n\t *\n\t * If path is none, it will default to m/94'/784'/0'/0'/0', otherwise the path must\n\t * be compliant to SLIP-0010 in form m/94'/784'/{account_index}'/{change_index}'/{address_index}'.\n\t *\n\t * @param seed - The seed as a hex string or Uint8Array.\n\t */\n\tstatic deriveKeypairFromSeed(seed: string | Uint8Array, path?: string): MLDSA65Keypair {\n\t\tif (path == null) {\n\t\t\tpath = DEFAULT_MLDSA65_DERIVATION_PATH;\n\t\t}\n\t\tif (!isValidHardenedPath(path, MLDSA65_DERIVATION_PURPOSE)) {\n\t\t\tthrow new Error('Invalid derivation path');\n\t\t}\n\t\tconst { key, chainCode } = derivePath(\n\t\t\tMLDSA65_SLIP10_MASTER_KEY,\n\t\t\tpath,\n\t\t\ttypeof seed === 'string' ? fromHex(seed) : seed,\n\t\t);\n\n\t\t// `fromSecretKey` copies the seed, so the node can be wiped here.\n\t\tconst keypair = MLDSA65Keypair.fromSecretKey(key);\n\t\tkey.fill(0);\n\t\tchainCode.fill(0);\n\t\treturn keypair;\n\t}\n}\n\nfunction expand(input: Uint8Array): MLDSA65KeypairData {\n\t// Own the seed: the caller may wipe or reuse its buffer, and the exported\n\t// secret key must keep matching the signing key.\n\tconst seed = Uint8Array.from(input);\n\tconst { publicKey, secretKey } = ml_dsa65.keygen(seed);\n\treturn { seed, secretKey, publicKey };\n}\n"],"mappings":";;;;;;;;;AAkBA,MAAa,kCAAkC;AAE/C,MAAM,6BAA6B;;;;AAgBnC,IAAa,iBAAb,MAAa,uBAAuB,QAAQ;;;;;;;CAS3C,YAAY,SAA8B;AACzC,SAAO;AACP,MAAI,QACH,MAAK,UAAU;MAEf,MAAK,UAAU,OAAO,YAAY,iBAAiB,CAAC;;;;;CAOtD,eAAgC;AAC/B,SAAO;;;;;CAMR,OAAO,WAA2B;AACjC,SAAO,IAAI,gBAAgB;;;;;;;CAQ5B,OAAO,cAAc,WAAgD;AACpE,MAAI,OAAO,cAAc,UAAU;GAClC,MAAM,UAAU,oBAAoB,UAAU;AAE9C,OAAI,QAAQ,WAAW,UACtB,OAAM,IAAI,MAAM,mCAAmC,QAAQ,SAAS;AAGrE,UAAO,KAAK,cAAc,QAAQ,UAAU;;AAG7C,MAAI,UAAU,WAAW,iBACxB,OAAM,IAAI,MACT,kCAAkC,iBAAiB,cAAc,UAAU,OAAO,GAClF;AAGF,SAAO,IAAI,eAAe,OAAO,UAAU,CAAC;;;;;;;;CAS7C,OAAO,SAAS,MAAkC;AACjD,SAAO,eAAe,cAAc,KAAK;;;;;CAM1C,eAAiC;AAChC,SAAO,IAAI,iBAAiB,KAAK,QAAQ,UAAU;;;;;CAMpD,eAAuB;AACtB,SAAO,oBAAoB,KAAK,QAAQ,MAAM,KAAK,cAAc,CAAC;;;;;;;;CASnE,MAAM,KAAK,MAAkB;AAC5B,SAAO,SAAS,KAAK,MAAM,KAAK,QAAQ,UAAU;;;;;;;;;CAUnD,OAAO,cAAc,WAAmB,MAA+B;AACtE,SAAO,eAAe,sBAAsB,eAAe,UAAU,EAAE,KAAK;;;;;;;;;;CAW7E,OAAO,sBAAsB,MAA2B,MAA+B;AACtF,MAAI,QAAQ,KACX,QAAO;AAER,MAAI,CAAC,oBAAoB,MAAM,2BAA2B,CACzD,OAAM,IAAI,MAAM,0BAA0B;EAE3C,MAAM,EAAE,KAAK,cAAc,WAC1B,2BACA,MACA,OAAO,SAAS,WAAW,QAAQ,KAAK,GAAG,KAC3C;EAGD,MAAM,UAAU,eAAe,cAAc,IAAI;AACjD,MAAI,KAAK,EAAE;AACX,YAAU,KAAK,EAAE;AACjB,SAAO;;;AAIT,SAAS,OAAO,OAAuC;CAGtD,MAAM,OAAO,WAAW,KAAK,MAAM;CACnC,MAAM,EAAE,WAAW,cAAc,SAAS,OAAO,KAAK;AACtD,QAAO;EAAE;EAAM;EAAW;EAAW"}