@aptos-labs/ts-sdk 0.0.3 → 0.0.4

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 (56) hide show
  1. package/README.md +1 -0
  2. package/dist/browser/index.global.js +26 -25
  3. package/dist/browser/index.global.js.map +1 -1
  4. package/dist/cjs/index.d.ts +413 -227
  5. package/dist/cjs/index.js +451 -181
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/esm/index.d.ts +413 -227
  8. package/dist/esm/index.mjs +440 -178
  9. package/dist/esm/index.mjs.map +1 -1
  10. package/dist/types/index.d.ts +11 -17
  11. package/dist/types/index.js.map +1 -1
  12. package/package.json +3 -2
  13. package/src/api/account.ts +17 -18
  14. package/src/api/ans.ts +58 -0
  15. package/src/api/aptos.ts +7 -1
  16. package/src/api/coin.ts +3 -3
  17. package/src/api/digitalAsset.ts +9 -8
  18. package/src/api/event.ts +4 -3
  19. package/src/api/faucet.ts +3 -2
  20. package/src/api/general.ts +2 -2
  21. package/src/api/staking.ts +5 -4
  22. package/src/api/transactionSubmission.ts +27 -18
  23. package/src/bcs/deserializer.ts +4 -4
  24. package/src/bcs/serializable/moveStructs.ts +5 -9
  25. package/src/bcs/serializer.ts +4 -4
  26. package/src/client/core.ts +14 -6
  27. package/src/core/account.ts +83 -29
  28. package/src/core/accountAddress.ts +34 -30
  29. package/src/core/authenticationKey.ts +11 -9
  30. package/src/core/crypto/ed25519.ts +48 -1
  31. package/src/core/crypto/hdKey.ts +105 -0
  32. package/src/core/crypto/index.ts +1 -0
  33. package/src/core/crypto/secp256k1.ts +36 -0
  34. package/src/index.ts +0 -1
  35. package/src/internal/account.ts +80 -58
  36. package/src/internal/ans.ts +177 -0
  37. package/src/internal/coin.ts +5 -5
  38. package/src/internal/digitalAsset.ts +16 -17
  39. package/src/internal/event.ts +7 -7
  40. package/src/internal/faucet.ts +4 -4
  41. package/src/internal/general.ts +3 -3
  42. package/src/internal/staking.ts +8 -8
  43. package/src/internal/transactionSubmission.ts +71 -18
  44. package/src/transactions/instances/index.ts +1 -0
  45. package/src/transactions/instances/moduleId.ts +1 -1
  46. package/src/transactions/instances/rotationProofChallenge.ts +58 -0
  47. package/src/transactions/transactionBuilder/helpers.ts +5 -1
  48. package/src/transactions/transactionBuilder/remoteAbi.ts +3 -3
  49. package/src/transactions/transactionBuilder/transactionBuilder.ts +31 -45
  50. package/src/transactions/typeTag/index.ts +10 -10
  51. package/src/transactions/typeTag/parser.ts +1 -1
  52. package/src/transactions/types.ts +28 -17
  53. package/src/types/index.ts +11 -16
  54. package/src/utils/apiEndpoints.ts +8 -0
  55. package/src/version.ts +1 -1
  56. package/src/utils/hdKey.ts +0 -113
@@ -1,113 +0,0 @@
1
- // Copyright © Aptos Foundation
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { hmac } from "@noble/hashes/hmac";
5
- import { sha512 } from "@noble/hashes/sha512";
6
- import * as bip39 from "@scure/bip39";
7
-
8
- export type DerivedKeys = {
9
- key: Uint8Array;
10
- chainCode: Uint8Array;
11
- };
12
-
13
- /**
14
- * Aptos derive path is 637
15
- *
16
- * See https://github.com/satoshilabs/slips/blob/master/slip-0044.md
17
- */
18
- export const APTOS_PATH_REGEX = /^m\/44'\/637'\/[0-9]+'\/[0-9]+'\/[0-9]+'?$/;
19
-
20
- /**
21
- * A list of supported key types and associated seeds
22
- */
23
- export enum KeyType {
24
- ED25519 = "ed25519 seed",
25
- }
26
-
27
- const HARDENED_OFFSET = 0x80000000;
28
-
29
- const deriveKey = (hashSeed: Uint8Array | string, data: Uint8Array | string): DerivedKeys => {
30
- const digest = hmac.create(sha512, hashSeed).update(data).digest();
31
- return {
32
- key: digest.slice(0, 32),
33
- chainCode: digest.slice(32),
34
- };
35
- };
36
-
37
- /**
38
- * Derive a child key from the private key
39
- * @param key
40
- * @param chainCode
41
- * @param index
42
- * @constructor
43
- */
44
- const CKDPriv = ({ key, chainCode }: DerivedKeys, index: number): DerivedKeys => {
45
- const buffer = new ArrayBuffer(4);
46
- new DataView(buffer).setUint32(0, index);
47
- const indexBytes = new Uint8Array(buffer);
48
- const zero = new Uint8Array([0]);
49
- const data = new Uint8Array([...zero, ...key, ...indexBytes]);
50
-
51
- return deriveKey(chainCode, data);
52
- };
53
-
54
- const removeApostrophes = (val: string): string => val.replace("'", "");
55
-
56
- /**
57
- * Splits derive path into segments
58
- * @param path
59
- */
60
- const splitPath = (path: string): Array<string> => path.split("/").slice(1).map(removeApostrophes);
61
-
62
- /**
63
- * Checks if the BIP44 path is valid for Aptos
64
- * @param path the BIP44 path
65
- *
66
- * @returns true if the path is a valid Aptos path
67
- */
68
- export const isValidPath = (path: string): boolean => {
69
- if (!APTOS_PATH_REGEX.test(path)) {
70
- return false;
71
- }
72
- return !splitPath(path).some(Number.isNaN as any);
73
- };
74
-
75
- /**
76
- * Normalizes the mnemonic by removing extra whitespace and making it lowercase
77
- * @param mnemonic the mnemonic seed phrase
78
- */
79
- const mnemonicToSeed = (mnemonic: string): Uint8Array => {
80
- const normalizedMnemonic = mnemonic
81
- .trim()
82
- .split(/\s+/)
83
- .map((part) => part.toLowerCase())
84
- .join(" ");
85
- return bip39.mnemonicToSeedSync(normalizedMnemonic);
86
- };
87
-
88
- /**
89
- * Derives a private key from a mnemonic seed phrase.
90
- *
91
- * To derive multiple keys from the same phrase, change the path
92
- * @param keyType the key type seed used to derive keys
93
- * @param path the BIP44 path
94
- * @param seedPhrase the mnemonic seed phrase
95
- * @param offset the offset used for key derivation, defaults to [HARDENED_OFFSET]
96
- */
97
- export const derivePrivateKeyFromMnemonic = (
98
- keyType: KeyType,
99
- path: string,
100
- seedPhrase: string,
101
- offset = HARDENED_OFFSET,
102
- ): DerivedKeys => {
103
- if (!isValidPath(path)) {
104
- throw new Error("Invalid derivation path");
105
- }
106
-
107
- // Derive the master key from the mnemonic
108
- const { key, chainCode } = deriveKey(keyType, mnemonicToSeed(seedPhrase));
109
- const segments = splitPath(path).map((el) => parseInt(el, 10));
110
-
111
- // Derive the child key based on the path
112
- return segments.reduce((parentKeys, segment) => CKDPriv(parentKeys, segment + offset), { key, chainCode });
113
- };