@talismn/crypto 0.3.0 → 0.3.1

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 (43) hide show
  1. package/dist/index.d.mts +124 -0
  2. package/dist/index.d.ts +124 -0
  3. package/dist/index.js +811 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +729 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +23 -25
  8. package/dist/declarations/src/address/addressFromPublicKey.d.ts +0 -5
  9. package/dist/declarations/src/address/encodeAnyAddress.d.ts +0 -5
  10. package/dist/declarations/src/address/encoding/addressEncodingFromCurve.d.ts +0 -3
  11. package/dist/declarations/src/address/encoding/bitcoin.d.ts +0 -37
  12. package/dist/declarations/src/address/encoding/detectAddressEncoding.d.ts +0 -2
  13. package/dist/declarations/src/address/encoding/ethereum.d.ts +0 -6
  14. package/dist/declarations/src/address/encoding/index.d.ts +0 -6
  15. package/dist/declarations/src/address/encoding/solana.d.ts +0 -2
  16. package/dist/declarations/src/address/encoding/ss58.d.ts +0 -3
  17. package/dist/declarations/src/address/index.d.ts +0 -6
  18. package/dist/declarations/src/address/isAddressEqual.d.ts +0 -1
  19. package/dist/declarations/src/address/isAddressValid.d.ts +0 -1
  20. package/dist/declarations/src/address/normalizeAddress.d.ts +0 -1
  21. package/dist/declarations/src/derivation/common.d.ts +0 -5
  22. package/dist/declarations/src/derivation/deriveEcdsa.d.ts +0 -3
  23. package/dist/declarations/src/derivation/deriveEd25519.d.ts +0 -3
  24. package/dist/declarations/src/derivation/deriveEthereum.d.ts +0 -3
  25. package/dist/declarations/src/derivation/deriveSolana.d.ts +0 -3
  26. package/dist/declarations/src/derivation/deriveSr25519.d.ts +0 -4
  27. package/dist/declarations/src/derivation/index.d.ts +0 -1
  28. package/dist/declarations/src/derivation/utils.d.ts +0 -7
  29. package/dist/declarations/src/encryption/encryptKemAead.d.ts +0 -1
  30. package/dist/declarations/src/encryption/index.d.ts +0 -1
  31. package/dist/declarations/src/hashing/index.d.ts +0 -9
  32. package/dist/declarations/src/index.d.ts +0 -8
  33. package/dist/declarations/src/mnemonic/index.d.ts +0 -9
  34. package/dist/declarations/src/platform/index.d.ts +0 -4
  35. package/dist/declarations/src/types/index.d.ts +0 -9
  36. package/dist/declarations/src/utils/exports.d.ts +0 -2
  37. package/dist/declarations/src/utils/index.d.ts +0 -2
  38. package/dist/declarations/src/utils/pbkdf2.d.ts +0 -1
  39. package/dist/talismn-crypto.cjs.d.ts +0 -1
  40. package/dist/talismn-crypto.cjs.dev.js +0 -784
  41. package/dist/talismn-crypto.cjs.js +0 -7
  42. package/dist/talismn-crypto.cjs.prod.js +0 -784
  43. package/dist/talismn-crypto.esm.js +0 -716
@@ -0,0 +1,124 @@
1
+ import * as _noble_hashes_utils from '@noble/hashes/utils';
2
+ export { ed25519 } from '@noble/curves/ed25519';
3
+ export { base58, base64, hex, utf8 } from '@scure/base';
4
+
5
+ type KeypairCurve = "ecdsa" | "ed25519" | "sr25519" | "ethereum" | "bitcoin-ed25519" | "bitcoin-ecdsa" | "solana";
6
+ type AddressEncoding = "ss58" | "ethereum" | "bech32m" | "bech32" | "base58check" | "base58solana";
7
+ type Keypair = {
8
+ type: KeypairCurve;
9
+ secretKey: Uint8Array;
10
+ publicKey: Uint8Array;
11
+ address: string;
12
+ };
13
+ type AccountPlatform = "ethereum" | "polkadot" | "bitcoin" | "solana";
14
+
15
+ type EncodeAddressOptions$1 = {
16
+ ss58Prefix?: number;
17
+ };
18
+ declare const addressFromPublicKey: (publicKey: Uint8Array, encoding: AddressEncoding, options?: EncodeAddressOptions$1) => string;
19
+
20
+ type EncodeAddressOptions = {
21
+ ss58Format?: number | undefined;
22
+ };
23
+ declare const encodeAnyAddress: (address: string, options?: EncodeAddressOptions) => string;
24
+
25
+ /** NOTE: Try not to use this too much, it will need to change */
26
+ declare const addressEncodingFromCurve: (curve: KeypairCurve) => AddressEncoding;
27
+
28
+ declare const isBitcoinAddress: (address: string) => boolean;
29
+ declare function isBech32mAddress(address: string): boolean;
30
+ declare function isBech32Address(address: string): boolean;
31
+ declare function isBase58CheckAddress(address: string): boolean;
32
+ /**
33
+ * Converts a Bech32m encoded address to its corresponding data representation.
34
+ * @param address - The Bech32m encoded address.
35
+ * @returns An object containing the version, prefix, and data of the address.
36
+ * @throws {TypeError} If the address uses the wrong encoding.
37
+ */
38
+ declare function fromBech32m(address: string): {
39
+ version: number;
40
+ prefix: string;
41
+ data: Uint8Array<ArrayBuffer>;
42
+ };
43
+ /**
44
+ * Converts a Bech32 encoded address to its corresponding data representation.
45
+ * @param address - The Bech32 encoded address.
46
+ * @returns An object containing the version, prefix, and data of the address.
47
+ * @throws {TypeError} If the address uses the wrong encoding.
48
+ */
49
+ declare function fromBech32(address: string): {
50
+ version: number;
51
+ prefix: string;
52
+ data: Uint8Array<ArrayBuffer>;
53
+ };
54
+ /**
55
+ * Decodes a base58check encoded Bitcoin address and returns the version and hash.
56
+ *
57
+ * @param address - The base58check encoded Bitcoin address to decode.
58
+ * @returns An object containing the version and hash of the decoded address.
59
+ * @throws {TypeError} If the address is too short or too long.
60
+ */
61
+ declare function fromBase58Check(address: string): {
62
+ version: number;
63
+ hash: Uint8Array<ArrayBuffer>;
64
+ };
65
+
66
+ declare const detectAddressEncoding: (address: string) => AddressEncoding;
67
+
68
+ /**
69
+ * Encodes a public key using H160 encoding with Ethereum checksum.
70
+ */
71
+ declare const encodeAddressEthereum: (publicKey: Uint8Array) => `0x${string}`;
72
+ declare const checksumEthereumAddress: (address: string) => `0x${string}`;
73
+ declare function isEthereumAddress(address: string): address is `0x${string}`;
74
+
75
+ declare const encodeAddressSolana: (publicKey: Uint8Array) => string;
76
+ declare function isSolanaAddress(address: string): boolean;
77
+
78
+ declare const decodeSs58Address: (addressStr: string) => [publicKey: Uint8Array, prefix: number];
79
+ declare const encodeAddressSs58: (publicKey: Uint8Array | string, prefix?: number) => string;
80
+ declare function isSs58Address(address: string): boolean;
81
+
82
+ declare const isAddressEqual: (address1: string, address2: string) => boolean;
83
+
84
+ declare const isAddressValid: (address: string) => boolean;
85
+
86
+ declare const normalizeAddress: (address: string) => string;
87
+
88
+ declare const getPublicKeySolana: (secretKey: Uint8Array) => Uint8Array<ArrayBufferLike>;
89
+
90
+ declare const deriveKeypair: (seed: Uint8Array, derivationPath: string, curve: KeypairCurve) => Keypair;
91
+ declare const getPublicKeyFromSecret: (secretKey: Uint8Array, curve: KeypairCurve) => Uint8Array;
92
+ declare const addressFromMnemonic: (mnemonic: string, derivationPath: string, curve: KeypairCurve) => Promise<string>;
93
+ declare const removeHexPrefix: (secretKey: string) => string;
94
+ declare const parseSecretKey: (secretKey: string, platform: AccountPlatform) => Uint8Array<ArrayBufferLike>;
95
+ declare const isValidDerivationPath: (derivationPath: string, curve: KeypairCurve) => Promise<boolean>;
96
+
97
+ declare const encryptKemAead: (publicKey: Uint8Array, plaintext: Uint8Array) => Promise<Uint8Array<ArrayBufferLike>>;
98
+
99
+ declare const blake3: {
100
+ (msg: _noble_hashes_utils.Input, opts?: Object | undefined): Uint8Array;
101
+ outputLen: number;
102
+ blockLen: number;
103
+ create(opts?: Object | undefined): _noble_hashes_utils.HashXOF<_noble_hashes_utils.HashXOF<_noble_hashes_utils.HashXOF<any>>>;
104
+ };
105
+ declare const blake2b256: (msg: Uint8Array) => Uint8Array<ArrayBufferLike>;
106
+ declare const blake2b512: (msg: Uint8Array) => Uint8Array<ArrayBufferLike>;
107
+ declare const getSafeHash: (bytes: Uint8Array) => string;
108
+
109
+ declare const mnemonicToEntropy: (mnemonic: string) => Uint8Array<ArrayBufferLike>;
110
+ declare const entropyToMnemonic: (entropy: Uint8Array) => string;
111
+ declare const entropyToSeed: (entropy: Uint8Array, curve: KeypairCurve, password?: string) => Promise<Uint8Array<ArrayBuffer>>;
112
+ declare const isValidMnemonic: (mnemonic: string) => boolean;
113
+ declare const generateMnemonic: (words: 12 | 24) => string;
114
+ declare const DEV_MNEMONIC_POLKADOT = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
115
+ declare const DEV_MNEMONIC_ETHEREUM = "test test test test test test test test test test test junk";
116
+ declare const getDevSeed: (curve: KeypairCurve) => Promise<Uint8Array<ArrayBufferLike>>;
117
+
118
+ declare const getAccountPlatformFromCurve: (curve: KeypairCurve) => AccountPlatform;
119
+ declare const getAccountPlatformFromEncoding: (encoding: AddressEncoding) => AccountPlatform;
120
+ declare const getAccountPlatformFromAddress: (address: string) => AccountPlatform;
121
+
122
+ declare const pbkdf2: (hash: "SHA-256" | "SHA-512", entropy: Uint8Array, salt: Uint8Array, iterations: number, outputLenBytes: number) => Promise<Uint8Array<ArrayBuffer>>;
123
+
124
+ export { type AccountPlatform, type AddressEncoding, DEV_MNEMONIC_ETHEREUM, DEV_MNEMONIC_POLKADOT, type EncodeAddressOptions$1 as EncodeAddressOptions, type Keypair, type KeypairCurve, addressEncodingFromCurve, addressFromMnemonic, addressFromPublicKey, blake2b256, blake2b512, blake3, checksumEthereumAddress, decodeSs58Address, deriveKeypair, detectAddressEncoding, encodeAddressEthereum, encodeAddressSolana, encodeAddressSs58, encodeAnyAddress, encryptKemAead, entropyToMnemonic, entropyToSeed, fromBase58Check, fromBech32, fromBech32m, generateMnemonic, getAccountPlatformFromAddress, getAccountPlatformFromCurve, getAccountPlatformFromEncoding, getDevSeed, getPublicKeyFromSecret, getPublicKeySolana, getSafeHash, isAddressEqual, isAddressValid, isBase58CheckAddress, isBech32Address, isBech32mAddress, isBitcoinAddress, isEthereumAddress, isSolanaAddress, isSs58Address, isValidDerivationPath, isValidMnemonic, mnemonicToEntropy, normalizeAddress, parseSecretKey, pbkdf2, removeHexPrefix };
@@ -0,0 +1,124 @@
1
+ import * as _noble_hashes_utils from '@noble/hashes/utils';
2
+ export { ed25519 } from '@noble/curves/ed25519';
3
+ export { base58, base64, hex, utf8 } from '@scure/base';
4
+
5
+ type KeypairCurve = "ecdsa" | "ed25519" | "sr25519" | "ethereum" | "bitcoin-ed25519" | "bitcoin-ecdsa" | "solana";
6
+ type AddressEncoding = "ss58" | "ethereum" | "bech32m" | "bech32" | "base58check" | "base58solana";
7
+ type Keypair = {
8
+ type: KeypairCurve;
9
+ secretKey: Uint8Array;
10
+ publicKey: Uint8Array;
11
+ address: string;
12
+ };
13
+ type AccountPlatform = "ethereum" | "polkadot" | "bitcoin" | "solana";
14
+
15
+ type EncodeAddressOptions$1 = {
16
+ ss58Prefix?: number;
17
+ };
18
+ declare const addressFromPublicKey: (publicKey: Uint8Array, encoding: AddressEncoding, options?: EncodeAddressOptions$1) => string;
19
+
20
+ type EncodeAddressOptions = {
21
+ ss58Format?: number | undefined;
22
+ };
23
+ declare const encodeAnyAddress: (address: string, options?: EncodeAddressOptions) => string;
24
+
25
+ /** NOTE: Try not to use this too much, it will need to change */
26
+ declare const addressEncodingFromCurve: (curve: KeypairCurve) => AddressEncoding;
27
+
28
+ declare const isBitcoinAddress: (address: string) => boolean;
29
+ declare function isBech32mAddress(address: string): boolean;
30
+ declare function isBech32Address(address: string): boolean;
31
+ declare function isBase58CheckAddress(address: string): boolean;
32
+ /**
33
+ * Converts a Bech32m encoded address to its corresponding data representation.
34
+ * @param address - The Bech32m encoded address.
35
+ * @returns An object containing the version, prefix, and data of the address.
36
+ * @throws {TypeError} If the address uses the wrong encoding.
37
+ */
38
+ declare function fromBech32m(address: string): {
39
+ version: number;
40
+ prefix: string;
41
+ data: Uint8Array<ArrayBuffer>;
42
+ };
43
+ /**
44
+ * Converts a Bech32 encoded address to its corresponding data representation.
45
+ * @param address - The Bech32 encoded address.
46
+ * @returns An object containing the version, prefix, and data of the address.
47
+ * @throws {TypeError} If the address uses the wrong encoding.
48
+ */
49
+ declare function fromBech32(address: string): {
50
+ version: number;
51
+ prefix: string;
52
+ data: Uint8Array<ArrayBuffer>;
53
+ };
54
+ /**
55
+ * Decodes a base58check encoded Bitcoin address and returns the version and hash.
56
+ *
57
+ * @param address - The base58check encoded Bitcoin address to decode.
58
+ * @returns An object containing the version and hash of the decoded address.
59
+ * @throws {TypeError} If the address is too short or too long.
60
+ */
61
+ declare function fromBase58Check(address: string): {
62
+ version: number;
63
+ hash: Uint8Array<ArrayBuffer>;
64
+ };
65
+
66
+ declare const detectAddressEncoding: (address: string) => AddressEncoding;
67
+
68
+ /**
69
+ * Encodes a public key using H160 encoding with Ethereum checksum.
70
+ */
71
+ declare const encodeAddressEthereum: (publicKey: Uint8Array) => `0x${string}`;
72
+ declare const checksumEthereumAddress: (address: string) => `0x${string}`;
73
+ declare function isEthereumAddress(address: string): address is `0x${string}`;
74
+
75
+ declare const encodeAddressSolana: (publicKey: Uint8Array) => string;
76
+ declare function isSolanaAddress(address: string): boolean;
77
+
78
+ declare const decodeSs58Address: (addressStr: string) => [publicKey: Uint8Array, prefix: number];
79
+ declare const encodeAddressSs58: (publicKey: Uint8Array | string, prefix?: number) => string;
80
+ declare function isSs58Address(address: string): boolean;
81
+
82
+ declare const isAddressEqual: (address1: string, address2: string) => boolean;
83
+
84
+ declare const isAddressValid: (address: string) => boolean;
85
+
86
+ declare const normalizeAddress: (address: string) => string;
87
+
88
+ declare const getPublicKeySolana: (secretKey: Uint8Array) => Uint8Array<ArrayBufferLike>;
89
+
90
+ declare const deriveKeypair: (seed: Uint8Array, derivationPath: string, curve: KeypairCurve) => Keypair;
91
+ declare const getPublicKeyFromSecret: (secretKey: Uint8Array, curve: KeypairCurve) => Uint8Array;
92
+ declare const addressFromMnemonic: (mnemonic: string, derivationPath: string, curve: KeypairCurve) => Promise<string>;
93
+ declare const removeHexPrefix: (secretKey: string) => string;
94
+ declare const parseSecretKey: (secretKey: string, platform: AccountPlatform) => Uint8Array<ArrayBufferLike>;
95
+ declare const isValidDerivationPath: (derivationPath: string, curve: KeypairCurve) => Promise<boolean>;
96
+
97
+ declare const encryptKemAead: (publicKey: Uint8Array, plaintext: Uint8Array) => Promise<Uint8Array<ArrayBufferLike>>;
98
+
99
+ declare const blake3: {
100
+ (msg: _noble_hashes_utils.Input, opts?: Object | undefined): Uint8Array;
101
+ outputLen: number;
102
+ blockLen: number;
103
+ create(opts?: Object | undefined): _noble_hashes_utils.HashXOF<_noble_hashes_utils.HashXOF<_noble_hashes_utils.HashXOF<any>>>;
104
+ };
105
+ declare const blake2b256: (msg: Uint8Array) => Uint8Array<ArrayBufferLike>;
106
+ declare const blake2b512: (msg: Uint8Array) => Uint8Array<ArrayBufferLike>;
107
+ declare const getSafeHash: (bytes: Uint8Array) => string;
108
+
109
+ declare const mnemonicToEntropy: (mnemonic: string) => Uint8Array<ArrayBufferLike>;
110
+ declare const entropyToMnemonic: (entropy: Uint8Array) => string;
111
+ declare const entropyToSeed: (entropy: Uint8Array, curve: KeypairCurve, password?: string) => Promise<Uint8Array<ArrayBuffer>>;
112
+ declare const isValidMnemonic: (mnemonic: string) => boolean;
113
+ declare const generateMnemonic: (words: 12 | 24) => string;
114
+ declare const DEV_MNEMONIC_POLKADOT = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
115
+ declare const DEV_MNEMONIC_ETHEREUM = "test test test test test test test test test test test junk";
116
+ declare const getDevSeed: (curve: KeypairCurve) => Promise<Uint8Array<ArrayBufferLike>>;
117
+
118
+ declare const getAccountPlatformFromCurve: (curve: KeypairCurve) => AccountPlatform;
119
+ declare const getAccountPlatformFromEncoding: (encoding: AddressEncoding) => AccountPlatform;
120
+ declare const getAccountPlatformFromAddress: (address: string) => AccountPlatform;
121
+
122
+ declare const pbkdf2: (hash: "SHA-256" | "SHA-512", entropy: Uint8Array, salt: Uint8Array, iterations: number, outputLenBytes: number) => Promise<Uint8Array<ArrayBuffer>>;
123
+
124
+ export { type AccountPlatform, type AddressEncoding, DEV_MNEMONIC_ETHEREUM, DEV_MNEMONIC_POLKADOT, type EncodeAddressOptions$1 as EncodeAddressOptions, type Keypair, type KeypairCurve, addressEncodingFromCurve, addressFromMnemonic, addressFromPublicKey, blake2b256, blake2b512, blake3, checksumEthereumAddress, decodeSs58Address, deriveKeypair, detectAddressEncoding, encodeAddressEthereum, encodeAddressSolana, encodeAddressSs58, encodeAnyAddress, encryptKemAead, entropyToMnemonic, entropyToSeed, fromBase58Check, fromBech32, fromBech32m, generateMnemonic, getAccountPlatformFromAddress, getAccountPlatformFromCurve, getAccountPlatformFromEncoding, getDevSeed, getPublicKeyFromSecret, getPublicKeySolana, getSafeHash, isAddressEqual, isAddressValid, isBase58CheckAddress, isBech32Address, isBech32mAddress, isBitcoinAddress, isEthereumAddress, isSolanaAddress, isSs58Address, isValidDerivationPath, isValidMnemonic, mnemonicToEntropy, normalizeAddress, parseSecretKey, pbkdf2, removeHexPrefix };