@talismn/crypto 0.3.4 → 1.0.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.
- package/LICENSE +253 -674
- package/dist/index.d.mts +118 -52
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +118 -52
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +847 -784
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +748 -707
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
package/dist/index.d.mts
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
2
|
+
import { base58, base64, hex, utf8 } from "@scure/base";
|
|
3
|
+
//#region src/types/index.d.ts
|
|
5
4
|
type KeypairCurve = "ecdsa" | "ed25519" | "sr25519" | "ethereum" | "bitcoin-ed25519" | "bitcoin-ecdsa" | "solana";
|
|
6
5
|
type AddressEncoding = "ss58" | "ethereum" | "bech32m" | "bech32" | "base58check" | "base58solana";
|
|
7
6
|
type Keypair = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
type: KeypairCurve;
|
|
8
|
+
secretKey: Uint8Array;
|
|
9
|
+
publicKey: Uint8Array;
|
|
10
|
+
address: string;
|
|
12
11
|
};
|
|
13
12
|
type AccountPlatform = "ethereum" | "polkadot" | "bitcoin" | "solana";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ss58Prefix?: number;
|
|
17
|
-
};
|
|
18
|
-
declare const addressFromPublicKey: (publicKey: Uint8Array, encoding: AddressEncoding, options?: EncodeAddressOptions$1) => string;
|
|
19
|
-
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/address/addressFromPublicKey.d.ts
|
|
20
15
|
type EncodeAddressOptions = {
|
|
21
|
-
|
|
16
|
+
ss58Prefix?: number;
|
|
17
|
+
};
|
|
18
|
+
declare const addressFromPublicKey: (publicKey: Uint8Array, encoding: AddressEncoding, options?: EncodeAddressOptions) => string;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/address/encodeAnyAddress.d.ts
|
|
21
|
+
type EncodeAddressOptions$1 = {
|
|
22
|
+
ss58Format?: number | undefined;
|
|
22
23
|
};
|
|
23
|
-
declare const encodeAnyAddress: (address: string, options?: EncodeAddressOptions) => string;
|
|
24
|
-
|
|
24
|
+
declare const encodeAnyAddress: (address: string, options?: EncodeAddressOptions$1) => string;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/address/encoding/addressEncodingFromCurve.d.ts
|
|
25
27
|
/** NOTE: Try not to use this too much, it will need to change */
|
|
26
28
|
declare const addressEncodingFromCurve: (curve: KeypairCurve) => AddressEncoding;
|
|
27
|
-
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/address/encoding/bitcoin.d.ts
|
|
28
31
|
declare const isBitcoinAddress: (address: string) => boolean;
|
|
29
32
|
declare function isBech32mAddress(address: string): boolean;
|
|
30
33
|
declare function isBech32Address(address: string): boolean;
|
|
@@ -36,9 +39,9 @@ declare function isBase58CheckAddress(address: string): boolean;
|
|
|
36
39
|
* @throws {TypeError} If the address uses the wrong encoding.
|
|
37
40
|
*/
|
|
38
41
|
declare function fromBech32m(address: string): {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
version: number;
|
|
43
|
+
prefix: string;
|
|
44
|
+
data: Uint8Array<ArrayBuffer>;
|
|
42
45
|
};
|
|
43
46
|
/**
|
|
44
47
|
* Converts a Bech32 encoded address to its corresponding data representation.
|
|
@@ -47,9 +50,9 @@ declare function fromBech32m(address: string): {
|
|
|
47
50
|
* @throws {TypeError} If the address uses the wrong encoding.
|
|
48
51
|
*/
|
|
49
52
|
declare function fromBech32(address: string): {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
version: number;
|
|
54
|
+
prefix: string;
|
|
55
|
+
data: Uint8Array<ArrayBuffer>;
|
|
53
56
|
};
|
|
54
57
|
/**
|
|
55
58
|
* Decodes a base58check encoded Bitcoin address and returns the version and hash.
|
|
@@ -59,41 +62,60 @@ declare function fromBech32(address: string): {
|
|
|
59
62
|
* @throws {TypeError} If the address is too short or too long.
|
|
60
63
|
*/
|
|
61
64
|
declare function fromBase58Check(address: string): {
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
version: number;
|
|
66
|
+
hash: Uint8Array<ArrayBuffer>;
|
|
64
67
|
};
|
|
65
|
-
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/address/encoding/detectAddressEncoding.d.ts
|
|
66
70
|
declare const detectAddressEncoding: (address: string) => AddressEncoding;
|
|
67
|
-
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/address/encoding/ethereum.d.ts
|
|
68
73
|
/**
|
|
69
74
|
* Encodes a public key using H160 encoding with Ethereum checksum.
|
|
75
|
+
* Accepts both uncompressed (65 bytes) and compressed (33 bytes) public keys -
|
|
76
|
+
* polkadot-js keystores store the compressed form as the account address.
|
|
70
77
|
*/
|
|
71
78
|
declare const encodeAddressEthereum: (publicKey: Uint8Array) => `0x${string}`;
|
|
72
79
|
declare const checksumEthereumAddress: (address: string) => `0x${string}`;
|
|
73
80
|
declare function isEthereumAddress(address: string): address is `0x${string}`;
|
|
74
|
-
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/address/encoding/solana.d.ts
|
|
75
83
|
declare const encodeAddressSolana: (publicKey: Uint8Array) => string;
|
|
76
84
|
declare function isSolanaAddress(address: string): boolean;
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Whether the address is a valid ed25519 public key (on-curve).
|
|
87
|
+
*
|
|
88
|
+
* Program-derived addresses (PDAs) are off-curve by construction: no private key can exist
|
|
89
|
+
* for them, so a regular wallet cannot recover tokens sent to an account they own.
|
|
90
|
+
*/
|
|
91
|
+
declare function isOnCurveSolanaAddress(address: string): boolean;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/address/encoding/ss58.d.ts
|
|
94
|
+
declare const decodeSs58Address: (addressStr: string, ignoreChecksum?: boolean) => [publicKey: Uint8Array, prefix: number];
|
|
79
95
|
declare const encodeAddressSs58: (publicKey: Uint8Array | string, prefix?: number) => string;
|
|
80
96
|
declare function isSs58Address(address: string): boolean;
|
|
81
|
-
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/address/isAddressEqual.d.ts
|
|
82
99
|
declare const isAddressEqual: (address1: string, address2: string) => boolean;
|
|
83
|
-
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/address/isAddressValid.d.ts
|
|
84
102
|
declare const isAddressValid: (address: string) => boolean;
|
|
85
|
-
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/address/normalizeAddress.d.ts
|
|
86
105
|
declare const normalizeAddress: (address: string) => string;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/derivation/deriveSolana.d.ts
|
|
108
|
+
declare const getPublicKeySolana: (secretKey: Uint8Array) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/derivation/utils.d.ts
|
|
90
111
|
declare const deriveKeypair: (seed: Uint8Array, derivationPath: string, curve: KeypairCurve) => Keypair;
|
|
91
112
|
declare const getPublicKeyFromSecret: (secretKey: Uint8Array, curve: KeypairCurve) => Uint8Array;
|
|
92
113
|
declare const addressFromMnemonic: (mnemonic: string, derivationPath: string, curve: KeypairCurve) => Promise<string>;
|
|
93
114
|
declare const removeHexPrefix: (secretKey: string) => string;
|
|
94
115
|
declare const parseSecretKey: (secretKey: string, platform: AccountPlatform) => Uint8Array<ArrayBufferLike>;
|
|
95
116
|
declare const isValidDerivationPath: (derivationPath: string, curve: KeypairCurve) => Promise<boolean>;
|
|
96
|
-
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/encryption/encryptKemAead.d.ts
|
|
97
119
|
/**
|
|
98
120
|
* Encrypts plaintext using ML-KEM-768 + XChaCha20-Poly1305 (KEM-AEAD).
|
|
99
121
|
*
|
|
@@ -104,19 +126,44 @@ declare const isValidDerivationPath: (derivationPath: string, curve: KeypairCurv
|
|
|
104
126
|
* @param publicKey ML-KEM-768 encapsulation key bytes
|
|
105
127
|
* @param plaintext Data to encrypt (typically a signed extrinsic)
|
|
106
128
|
*/
|
|
107
|
-
declare const encryptKemAead: (keyHash: Uint8Array, publicKey: Uint8Array, plaintext: Uint8Array) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
108
|
-
|
|
129
|
+
declare const encryptKemAead: (keyHash: Uint8Array, publicKey: Uint8Array, plaintext: Uint8Array) => Promise<Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>>;
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/hashing/index.d.ts
|
|
109
132
|
declare const blake3: {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
133
|
+
outputLen: number;
|
|
134
|
+
blockLen: number;
|
|
135
|
+
canXOF: boolean;
|
|
136
|
+
} & import("@noble/hashes/utils.js").HashInfo & {
|
|
137
|
+
(msg: import("@noble/hashes/utils.js").TArg<Uint8Array>, opts?: import("@noble/hashes/utils.js").TArg<import("@noble/hashes/blake3.js").Blake3Opts> | undefined): import("@noble/hashes/utils.js").TRet<Uint8Array>;
|
|
138
|
+
create(opts?: import("@noble/hashes/blake3.js").Blake3Opts | undefined): import("@noble/hashes/blake3.js")._BLAKE3;
|
|
139
|
+
} & ((msg: import("@noble/hashes/utils.js").TArg<import("@noble/hashes/utils.js").TArg<Uint8Array<ArrayBufferLike>>>, opts?: import("@noble/hashes/utils.js").TArg<import("@noble/hashes/utils.js").TArg<import("@noble/hashes/blake3.js").Blake3Opts> | undefined>) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>) & {
|
|
140
|
+
oid?: import("@noble/hashes/utils.js").TRet<Uint8Array>;
|
|
141
|
+
outputLen: number;
|
|
142
|
+
blockLen: number;
|
|
143
|
+
canXOF: boolean;
|
|
144
|
+
create: (opts?: import("@noble/hashes/blake3.js").Blake3Opts | undefined) => import("@noble/hashes/blake3.js")._BLAKE3;
|
|
114
145
|
};
|
|
115
|
-
declare const blake2b256: (msg: Uint8Array) => Uint8Array<ArrayBufferLike>;
|
|
116
|
-
declare const blake2b512: (msg: Uint8Array) => Uint8Array<ArrayBufferLike>;
|
|
146
|
+
declare const blake2b256: (msg: Uint8Array) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
147
|
+
declare const blake2b512: (msg: Uint8Array) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
117
148
|
declare const getSafeHash: (bytes: Uint8Array) => string;
|
|
118
|
-
|
|
119
|
-
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/keystore/index.d.ts
|
|
151
|
+
type PjsKeystoreEncoding = {
|
|
152
|
+
content: string[];
|
|
153
|
+
type: string[];
|
|
154
|
+
version: string;
|
|
155
|
+
};
|
|
156
|
+
type PjsKeystore = {
|
|
157
|
+
encoded: string;
|
|
158
|
+
encoding: PjsKeystoreEncoding;
|
|
159
|
+
};
|
|
160
|
+
/** Decrypts a polkadot-js encrypted keystore (`jsonDecrypt` equivalent) */
|
|
161
|
+
declare const decryptPjsKeystore: ({ encoded, encoding }: PjsKeystore, password: string) => Uint8Array;
|
|
162
|
+
/** Encrypts data as a polkadot-js keystore (`jsonEncrypt` equivalent, always scrypt + v3) */
|
|
163
|
+
declare const encryptPjsKeystore: (data: Uint8Array, contentType: string[], password: string) => PjsKeystore;
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/mnemonic/index.d.ts
|
|
166
|
+
declare const mnemonicToEntropy: (mnemonic: string) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
120
167
|
declare const entropyToMnemonic: (entropy: Uint8Array) => string;
|
|
121
168
|
declare const entropyToSeed: (entropy: Uint8Array, curve: KeypairCurve, password?: string) => Promise<Uint8Array<ArrayBuffer>>;
|
|
122
169
|
declare const isValidMnemonic: (mnemonic: string) => boolean;
|
|
@@ -124,11 +171,30 @@ declare const generateMnemonic: (words: 12 | 24) => string;
|
|
|
124
171
|
declare const DEV_MNEMONIC_POLKADOT = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
|
|
125
172
|
declare const DEV_MNEMONIC_ETHEREUM = "test test test test test test test test test test test junk";
|
|
126
173
|
declare const getDevSeed: (curve: KeypairCurve) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
127
|
-
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/platform/index.d.ts
|
|
128
176
|
declare const getAccountPlatformFromCurve: (curve: KeypairCurve) => AccountPlatform;
|
|
129
177
|
declare const getAccountPlatformFromEncoding: (encoding: AddressEncoding) => AccountPlatform;
|
|
130
178
|
declare const getAccountPlatformFromAddress: (address: string) => AccountPlatform;
|
|
131
|
-
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/signing/index.d.ts
|
|
181
|
+
/**
|
|
182
|
+
* Signs a substrate payload with the given curve.
|
|
183
|
+
*
|
|
184
|
+
* Output is byte-compatible with polkadot-js `KeyringPair.sign` (without type prefix):
|
|
185
|
+
* - sr25519/ed25519: 64-byte signature over the raw message
|
|
186
|
+
* - ecdsa: 65-byte recoverable signature (r||s||v) over blake2b-256(message)
|
|
187
|
+
* - ethereum: 65-byte recoverable signature (r||s||v) over keccak-256(message)
|
|
188
|
+
*
|
|
189
|
+
* Note: callers are responsible for the substrate >256-byte rule (hash the payload
|
|
190
|
+
* with blake2b-256 before signing) — this matches where polkadot-js applies it.
|
|
191
|
+
*/
|
|
192
|
+
declare const signSubstrate: (curve: KeypairCurve, secretKey: Uint8Array, message: Uint8Array) => Uint8Array;
|
|
193
|
+
/** MultiSignature enum variant index per signature scheme, used to type-prefix signatures */
|
|
194
|
+
declare const SIGNATURE_TYPE_PREFIX: Partial<Record<KeypairCurve, number>>;
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/utils/pbkdf2.d.ts
|
|
132
197
|
declare const pbkdf2: (hash: "SHA-256" | "SHA-512", entropy: Uint8Array, salt: Uint8Array, iterations: number, outputLenBytes: number) => Promise<Uint8Array<ArrayBuffer>>;
|
|
133
|
-
|
|
134
|
-
export {
|
|
198
|
+
//#endregion
|
|
199
|
+
export { AccountPlatform, AddressEncoding, DEV_MNEMONIC_ETHEREUM, DEV_MNEMONIC_POLKADOT, EncodeAddressOptions, Keypair, KeypairCurve, PjsKeystore, PjsKeystoreEncoding, SIGNATURE_TYPE_PREFIX, addressEncodingFromCurve, addressFromMnemonic, addressFromPublicKey, base58, base64, blake2b256, blake2b512, blake3, checksumEthereumAddress, decodeSs58Address, decryptPjsKeystore, deriveKeypair, detectAddressEncoding, ed25519, encodeAddressEthereum, encodeAddressSolana, encodeAddressSs58, encodeAnyAddress, encryptKemAead, encryptPjsKeystore, entropyToMnemonic, entropyToSeed, fromBase58Check, fromBech32, fromBech32m, generateMnemonic, getAccountPlatformFromAddress, getAccountPlatformFromCurve, getAccountPlatformFromEncoding, getDevSeed, getPublicKeyFromSecret, getPublicKeySolana, getSafeHash, hex, isAddressEqual, isAddressValid, isBase58CheckAddress, isBech32Address, isBech32mAddress, isBitcoinAddress, isEthereumAddress, isOnCurveSolanaAddress, isSolanaAddress, isSs58Address, isValidDerivationPath, isValidMnemonic, mnemonicToEntropy, normalizeAddress, parseSecretKey, pbkdf2, removeHexPrefix, signSubstrate, utf8 };
|
|
200
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/index.ts","../src/address/addressFromPublicKey.ts","../src/address/encodeAnyAddress.ts","../src/address/encoding/addressEncodingFromCurve.ts","../src/address/encoding/bitcoin.ts","../src/address/encoding/detectAddressEncoding.ts","../src/address/encoding/ethereum.ts","../src/address/encoding/solana.ts","../src/address/encoding/ss58.ts","../src/address/isAddressEqual.ts","../src/address/isAddressValid.ts","../src/address/normalizeAddress.ts","../src/derivation/deriveSolana.ts","../src/derivation/utils.ts","../src/encryption/encryptKemAead.ts","../src/hashing/index.ts","../src/keystore/index.ts","../src/mnemonic/index.ts","../src/platform/index.ts","../src/signing/index.ts","../src/utils/pbkdf2.ts"],"mappings":";;;KAeY;KAcA;KAQA;EACV,MAAM;EACN,WAAW;EACX,WAAW;EACX;;KAGU;;;KCzCA;EACV;;cAGW,uBAAoB,WACpB,YAAU,UACX,iBAAe,UACf;;;KCPP;EACH;;cAGW,mBAAgB,iBAAmB,UAAY;;;;cCJ/C,2BAAwB,OAAW,iBAAe;;;cCAlD,mBAAgB;iBAGb,iBAAiB;iBASjB,gBAAgB;iBAShB,qBAAqB;;;;;;;iBAerB,YAAY;;;QAAZ,WAAA;;;;;;;;iBAkBA,WAAW;;;QAAX,WAAA;;;;;;;;;iBAmBA,gBAAgB;;QAAhB,WAAA;;;;cC1DH,wBAAqB,oBAAsB;;;;;;;;cCT3C,wBAAqB,WAAe;cAoBpC,0BAAuB;iBAapB,kBAAkB,kBAAkB;;;cCvCvC,sBAAmB,WAAe;iBAK/B,gBAAgB;;;;;;;iBAehB,uBAAuB;;;cCY1B,oBAAiB,oBACV,8BAGhB,WAAW,YAAY;cAoBd,oBAAiB,WAAe,qBAAmB;iBAKhD,cAAc;;;cC9DjB,iBAAc,kBAAoB;;;cCAlC,iBAAc;;;cCQd,mBAAgB;;;cC6ChB,qBAAkB,WAAe,eAAU,WAAA,mBAAA,WAAA;;;cC7C3C,gBAAa,MAAU,YAAU,wBAAwB,OAAS,iBAAA;cAkBlE,yBAAsB,WAAe,YAAU,OAAS,iBAAe;cAkBvE,sBAAmB,kBACd,wBACM,OACf,iBAAY;cAQR,kBAAe;cAKf,iBAAc,mBAAqB,UAAY,oBAAe,WAAA;cA+B9D,wBAAqB,wBAAgC,OAAS,iBAAY;;;;;;;;;;;;;cC/E1E,iBAAc,SAChB,YAAU,WACR,YAAU,WACV,eAAU,QAAA,WAAA,mBAAA,WAAA;;;cCbV;;;;;;;;;;;;;;cAEA,aAAU,KAAS,eAAU,WAAA,mBAAA,WAAA;cAC7B,aAAU,KAAS,eAAU,WAAA,mBAAA,WAAA;cAE7B,cAAW,OAAW;;;KCuBvB;EACV;EACA;EACA;;KAGU;EACV;EACA,UAAU;;;cAoBC,uBAAkB,SAAA,YACN,aAAW,qBAEjC;;cAqCU,qBAAkB,MACvB,YAAU,uBACK,qBAEpB;;;cC7FU,oBAAiB,qBAAoB,WAAA,mBAAA,WAAA;cAIrC,oBAAiB,SAAa;cA+C9B,gBAAa,SACf,YAAU,OACZ,cAAY,sBACF,QAAA,WAAA;cAYN,kBAAe;cAIf,mBAAgB;cAUhB;cAIA;cAKA,aAAU,OAAiB,iBAAY,QAAA,WAAA;;;cCjGvC,8BAA2B,OAAW,iBAAe;cAgBrD,iCAA8B,UAAc,oBAAkB;cAe9D,gCAA6B,oBAAsB;;;;;;;;;;;;;;cCPnD,gBAAa,OACjB,cAAY,WACR,YAAU,SACZ,eACR;;cAsBU,uBAAuB,QAAQ,OAAO;;;cCrDtC,SAAM,6BACU,SAClB,YAAU,MACb,YAAU,oBACE,2BACI,QAAA,WAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { ed25519 } from "@noble/curves/ed25519.js";
|
|
2
|
+
import { base58, base64, hex, utf8 } from "@scure/base";
|
|
3
|
+
//#region src/types/index.d.ts
|
|
5
4
|
type KeypairCurve = "ecdsa" | "ed25519" | "sr25519" | "ethereum" | "bitcoin-ed25519" | "bitcoin-ecdsa" | "solana";
|
|
6
5
|
type AddressEncoding = "ss58" | "ethereum" | "bech32m" | "bech32" | "base58check" | "base58solana";
|
|
7
6
|
type Keypair = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
type: KeypairCurve;
|
|
8
|
+
secretKey: Uint8Array;
|
|
9
|
+
publicKey: Uint8Array;
|
|
10
|
+
address: string;
|
|
12
11
|
};
|
|
13
12
|
type AccountPlatform = "ethereum" | "polkadot" | "bitcoin" | "solana";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ss58Prefix?: number;
|
|
17
|
-
};
|
|
18
|
-
declare const addressFromPublicKey: (publicKey: Uint8Array, encoding: AddressEncoding, options?: EncodeAddressOptions$1) => string;
|
|
19
|
-
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/address/addressFromPublicKey.d.ts
|
|
20
15
|
type EncodeAddressOptions = {
|
|
21
|
-
|
|
16
|
+
ss58Prefix?: number;
|
|
17
|
+
};
|
|
18
|
+
declare const addressFromPublicKey: (publicKey: Uint8Array, encoding: AddressEncoding, options?: EncodeAddressOptions) => string;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/address/encodeAnyAddress.d.ts
|
|
21
|
+
type EncodeAddressOptions$1 = {
|
|
22
|
+
ss58Format?: number | undefined;
|
|
22
23
|
};
|
|
23
|
-
declare const encodeAnyAddress: (address: string, options?: EncodeAddressOptions) => string;
|
|
24
|
-
|
|
24
|
+
declare const encodeAnyAddress: (address: string, options?: EncodeAddressOptions$1) => string;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/address/encoding/addressEncodingFromCurve.d.ts
|
|
25
27
|
/** NOTE: Try not to use this too much, it will need to change */
|
|
26
28
|
declare const addressEncodingFromCurve: (curve: KeypairCurve) => AddressEncoding;
|
|
27
|
-
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/address/encoding/bitcoin.d.ts
|
|
28
31
|
declare const isBitcoinAddress: (address: string) => boolean;
|
|
29
32
|
declare function isBech32mAddress(address: string): boolean;
|
|
30
33
|
declare function isBech32Address(address: string): boolean;
|
|
@@ -36,9 +39,9 @@ declare function isBase58CheckAddress(address: string): boolean;
|
|
|
36
39
|
* @throws {TypeError} If the address uses the wrong encoding.
|
|
37
40
|
*/
|
|
38
41
|
declare function fromBech32m(address: string): {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
version: number;
|
|
43
|
+
prefix: string;
|
|
44
|
+
data: Uint8Array<ArrayBuffer>;
|
|
42
45
|
};
|
|
43
46
|
/**
|
|
44
47
|
* Converts a Bech32 encoded address to its corresponding data representation.
|
|
@@ -47,9 +50,9 @@ declare function fromBech32m(address: string): {
|
|
|
47
50
|
* @throws {TypeError} If the address uses the wrong encoding.
|
|
48
51
|
*/
|
|
49
52
|
declare function fromBech32(address: string): {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
version: number;
|
|
54
|
+
prefix: string;
|
|
55
|
+
data: Uint8Array<ArrayBuffer>;
|
|
53
56
|
};
|
|
54
57
|
/**
|
|
55
58
|
* Decodes a base58check encoded Bitcoin address and returns the version and hash.
|
|
@@ -59,41 +62,60 @@ declare function fromBech32(address: string): {
|
|
|
59
62
|
* @throws {TypeError} If the address is too short or too long.
|
|
60
63
|
*/
|
|
61
64
|
declare function fromBase58Check(address: string): {
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
version: number;
|
|
66
|
+
hash: Uint8Array<ArrayBuffer>;
|
|
64
67
|
};
|
|
65
|
-
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/address/encoding/detectAddressEncoding.d.ts
|
|
66
70
|
declare const detectAddressEncoding: (address: string) => AddressEncoding;
|
|
67
|
-
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/address/encoding/ethereum.d.ts
|
|
68
73
|
/**
|
|
69
74
|
* Encodes a public key using H160 encoding with Ethereum checksum.
|
|
75
|
+
* Accepts both uncompressed (65 bytes) and compressed (33 bytes) public keys -
|
|
76
|
+
* polkadot-js keystores store the compressed form as the account address.
|
|
70
77
|
*/
|
|
71
78
|
declare const encodeAddressEthereum: (publicKey: Uint8Array) => `0x${string}`;
|
|
72
79
|
declare const checksumEthereumAddress: (address: string) => `0x${string}`;
|
|
73
80
|
declare function isEthereumAddress(address: string): address is `0x${string}`;
|
|
74
|
-
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/address/encoding/solana.d.ts
|
|
75
83
|
declare const encodeAddressSolana: (publicKey: Uint8Array) => string;
|
|
76
84
|
declare function isSolanaAddress(address: string): boolean;
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Whether the address is a valid ed25519 public key (on-curve).
|
|
87
|
+
*
|
|
88
|
+
* Program-derived addresses (PDAs) are off-curve by construction: no private key can exist
|
|
89
|
+
* for them, so a regular wallet cannot recover tokens sent to an account they own.
|
|
90
|
+
*/
|
|
91
|
+
declare function isOnCurveSolanaAddress(address: string): boolean;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/address/encoding/ss58.d.ts
|
|
94
|
+
declare const decodeSs58Address: (addressStr: string, ignoreChecksum?: boolean) => [publicKey: Uint8Array, prefix: number];
|
|
79
95
|
declare const encodeAddressSs58: (publicKey: Uint8Array | string, prefix?: number) => string;
|
|
80
96
|
declare function isSs58Address(address: string): boolean;
|
|
81
|
-
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/address/isAddressEqual.d.ts
|
|
82
99
|
declare const isAddressEqual: (address1: string, address2: string) => boolean;
|
|
83
|
-
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/address/isAddressValid.d.ts
|
|
84
102
|
declare const isAddressValid: (address: string) => boolean;
|
|
85
|
-
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/address/normalizeAddress.d.ts
|
|
86
105
|
declare const normalizeAddress: (address: string) => string;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/derivation/deriveSolana.d.ts
|
|
108
|
+
declare const getPublicKeySolana: (secretKey: Uint8Array) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/derivation/utils.d.ts
|
|
90
111
|
declare const deriveKeypair: (seed: Uint8Array, derivationPath: string, curve: KeypairCurve) => Keypair;
|
|
91
112
|
declare const getPublicKeyFromSecret: (secretKey: Uint8Array, curve: KeypairCurve) => Uint8Array;
|
|
92
113
|
declare const addressFromMnemonic: (mnemonic: string, derivationPath: string, curve: KeypairCurve) => Promise<string>;
|
|
93
114
|
declare const removeHexPrefix: (secretKey: string) => string;
|
|
94
115
|
declare const parseSecretKey: (secretKey: string, platform: AccountPlatform) => Uint8Array<ArrayBufferLike>;
|
|
95
116
|
declare const isValidDerivationPath: (derivationPath: string, curve: KeypairCurve) => Promise<boolean>;
|
|
96
|
-
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/encryption/encryptKemAead.d.ts
|
|
97
119
|
/**
|
|
98
120
|
* Encrypts plaintext using ML-KEM-768 + XChaCha20-Poly1305 (KEM-AEAD).
|
|
99
121
|
*
|
|
@@ -104,19 +126,44 @@ declare const isValidDerivationPath: (derivationPath: string, curve: KeypairCurv
|
|
|
104
126
|
* @param publicKey ML-KEM-768 encapsulation key bytes
|
|
105
127
|
* @param plaintext Data to encrypt (typically a signed extrinsic)
|
|
106
128
|
*/
|
|
107
|
-
declare const encryptKemAead: (keyHash: Uint8Array, publicKey: Uint8Array, plaintext: Uint8Array) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
108
|
-
|
|
129
|
+
declare const encryptKemAead: (keyHash: Uint8Array, publicKey: Uint8Array, plaintext: Uint8Array) => Promise<Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>>;
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/hashing/index.d.ts
|
|
109
132
|
declare const blake3: {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
133
|
+
outputLen: number;
|
|
134
|
+
blockLen: number;
|
|
135
|
+
canXOF: boolean;
|
|
136
|
+
} & import("@noble/hashes/utils.js").HashInfo & {
|
|
137
|
+
(msg: import("@noble/hashes/utils.js").TArg<Uint8Array>, opts?: import("@noble/hashes/utils.js").TArg<import("@noble/hashes/blake3.js").Blake3Opts> | undefined): import("@noble/hashes/utils.js").TRet<Uint8Array>;
|
|
138
|
+
create(opts?: import("@noble/hashes/blake3.js").Blake3Opts | undefined): import("@noble/hashes/blake3.js")._BLAKE3;
|
|
139
|
+
} & ((msg: import("@noble/hashes/utils.js").TArg<import("@noble/hashes/utils.js").TArg<Uint8Array<ArrayBufferLike>>>, opts?: import("@noble/hashes/utils.js").TArg<import("@noble/hashes/utils.js").TArg<import("@noble/hashes/blake3.js").Blake3Opts> | undefined>) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>) & {
|
|
140
|
+
oid?: import("@noble/hashes/utils.js").TRet<Uint8Array>;
|
|
141
|
+
outputLen: number;
|
|
142
|
+
blockLen: number;
|
|
143
|
+
canXOF: boolean;
|
|
144
|
+
create: (opts?: import("@noble/hashes/blake3.js").Blake3Opts | undefined) => import("@noble/hashes/blake3.js")._BLAKE3;
|
|
114
145
|
};
|
|
115
|
-
declare const blake2b256: (msg: Uint8Array) => Uint8Array<ArrayBufferLike>;
|
|
116
|
-
declare const blake2b512: (msg: Uint8Array) => Uint8Array<ArrayBufferLike>;
|
|
146
|
+
declare const blake2b256: (msg: Uint8Array) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
147
|
+
declare const blake2b512: (msg: Uint8Array) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
117
148
|
declare const getSafeHash: (bytes: Uint8Array) => string;
|
|
118
|
-
|
|
119
|
-
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/keystore/index.d.ts
|
|
151
|
+
type PjsKeystoreEncoding = {
|
|
152
|
+
content: string[];
|
|
153
|
+
type: string[];
|
|
154
|
+
version: string;
|
|
155
|
+
};
|
|
156
|
+
type PjsKeystore = {
|
|
157
|
+
encoded: string;
|
|
158
|
+
encoding: PjsKeystoreEncoding;
|
|
159
|
+
};
|
|
160
|
+
/** Decrypts a polkadot-js encrypted keystore (`jsonDecrypt` equivalent) */
|
|
161
|
+
declare const decryptPjsKeystore: ({ encoded, encoding }: PjsKeystore, password: string) => Uint8Array;
|
|
162
|
+
/** Encrypts data as a polkadot-js keystore (`jsonEncrypt` equivalent, always scrypt + v3) */
|
|
163
|
+
declare const encryptPjsKeystore: (data: Uint8Array, contentType: string[], password: string) => PjsKeystore;
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/mnemonic/index.d.ts
|
|
166
|
+
declare const mnemonicToEntropy: (mnemonic: string) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
120
167
|
declare const entropyToMnemonic: (entropy: Uint8Array) => string;
|
|
121
168
|
declare const entropyToSeed: (entropy: Uint8Array, curve: KeypairCurve, password?: string) => Promise<Uint8Array<ArrayBuffer>>;
|
|
122
169
|
declare const isValidMnemonic: (mnemonic: string) => boolean;
|
|
@@ -124,11 +171,30 @@ declare const generateMnemonic: (words: 12 | 24) => string;
|
|
|
124
171
|
declare const DEV_MNEMONIC_POLKADOT = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
|
|
125
172
|
declare const DEV_MNEMONIC_ETHEREUM = "test test test test test test test test test test test junk";
|
|
126
173
|
declare const getDevSeed: (curve: KeypairCurve) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
127
|
-
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/platform/index.d.ts
|
|
128
176
|
declare const getAccountPlatformFromCurve: (curve: KeypairCurve) => AccountPlatform;
|
|
129
177
|
declare const getAccountPlatformFromEncoding: (encoding: AddressEncoding) => AccountPlatform;
|
|
130
178
|
declare const getAccountPlatformFromAddress: (address: string) => AccountPlatform;
|
|
131
|
-
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/signing/index.d.ts
|
|
181
|
+
/**
|
|
182
|
+
* Signs a substrate payload with the given curve.
|
|
183
|
+
*
|
|
184
|
+
* Output is byte-compatible with polkadot-js `KeyringPair.sign` (without type prefix):
|
|
185
|
+
* - sr25519/ed25519: 64-byte signature over the raw message
|
|
186
|
+
* - ecdsa: 65-byte recoverable signature (r||s||v) over blake2b-256(message)
|
|
187
|
+
* - ethereum: 65-byte recoverable signature (r||s||v) over keccak-256(message)
|
|
188
|
+
*
|
|
189
|
+
* Note: callers are responsible for the substrate >256-byte rule (hash the payload
|
|
190
|
+
* with blake2b-256 before signing) — this matches where polkadot-js applies it.
|
|
191
|
+
*/
|
|
192
|
+
declare const signSubstrate: (curve: KeypairCurve, secretKey: Uint8Array, message: Uint8Array) => Uint8Array;
|
|
193
|
+
/** MultiSignature enum variant index per signature scheme, used to type-prefix signatures */
|
|
194
|
+
declare const SIGNATURE_TYPE_PREFIX: Partial<Record<KeypairCurve, number>>;
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/utils/pbkdf2.d.ts
|
|
132
197
|
declare const pbkdf2: (hash: "SHA-256" | "SHA-512", entropy: Uint8Array, salt: Uint8Array, iterations: number, outputLenBytes: number) => Promise<Uint8Array<ArrayBuffer>>;
|
|
133
|
-
|
|
134
|
-
export {
|
|
198
|
+
//#endregion
|
|
199
|
+
export { AccountPlatform, AddressEncoding, DEV_MNEMONIC_ETHEREUM, DEV_MNEMONIC_POLKADOT, EncodeAddressOptions, Keypair, KeypairCurve, PjsKeystore, PjsKeystoreEncoding, SIGNATURE_TYPE_PREFIX, addressEncodingFromCurve, addressFromMnemonic, addressFromPublicKey, base58, base64, blake2b256, blake2b512, blake3, checksumEthereumAddress, decodeSs58Address, decryptPjsKeystore, deriveKeypair, detectAddressEncoding, ed25519, encodeAddressEthereum, encodeAddressSolana, encodeAddressSs58, encodeAnyAddress, encryptKemAead, encryptPjsKeystore, entropyToMnemonic, entropyToSeed, fromBase58Check, fromBech32, fromBech32m, generateMnemonic, getAccountPlatformFromAddress, getAccountPlatformFromCurve, getAccountPlatformFromEncoding, getDevSeed, getPublicKeyFromSecret, getPublicKeySolana, getSafeHash, hex, isAddressEqual, isAddressValid, isBase58CheckAddress, isBech32Address, isBech32mAddress, isBitcoinAddress, isEthereumAddress, isOnCurveSolanaAddress, isSolanaAddress, isSs58Address, isValidDerivationPath, isValidMnemonic, mnemonicToEntropy, normalizeAddress, parseSecretKey, pbkdf2, removeHexPrefix, signSubstrate, utf8 };
|
|
200
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types/index.ts","../src/address/addressFromPublicKey.ts","../src/address/encodeAnyAddress.ts","../src/address/encoding/addressEncodingFromCurve.ts","../src/address/encoding/bitcoin.ts","../src/address/encoding/detectAddressEncoding.ts","../src/address/encoding/ethereum.ts","../src/address/encoding/solana.ts","../src/address/encoding/ss58.ts","../src/address/isAddressEqual.ts","../src/address/isAddressValid.ts","../src/address/normalizeAddress.ts","../src/derivation/deriveSolana.ts","../src/derivation/utils.ts","../src/encryption/encryptKemAead.ts","../src/hashing/index.ts","../src/keystore/index.ts","../src/mnemonic/index.ts","../src/platform/index.ts","../src/signing/index.ts","../src/utils/pbkdf2.ts"],"mappings":";;;KAeY;KAcA;KAQA;EACV,MAAM;EACN,WAAW;EACX,WAAW;EACX;;KAGU;;;KCzCA;EACV;;cAGW,uBAAoB,WACpB,YAAU,UACX,iBAAe,UACf;;;KCPP;EACH;;cAGW,mBAAgB,iBAAmB,UAAY;;;;cCJ/C,2BAAwB,OAAW,iBAAe;;;cCAlD,mBAAgB;iBAGb,iBAAiB;iBASjB,gBAAgB;iBAShB,qBAAqB;;;;;;;iBAerB,YAAY;;;QAAZ,WAAA;;;;;;;;iBAkBA,WAAW;;;QAAX,WAAA;;;;;;;;;iBAmBA,gBAAgB;;QAAhB,WAAA;;;;cC1DH,wBAAqB,oBAAsB;;;;;;;;cCT3C,wBAAqB,WAAe;cAoBpC,0BAAuB;iBAapB,kBAAkB,kBAAkB;;;cCvCvC,sBAAmB,WAAe;iBAK/B,gBAAgB;;;;;;;iBAehB,uBAAuB;;;cCY1B,oBAAiB,oBACV,8BAGhB,WAAW,YAAY;cAoBd,oBAAiB,WAAe,qBAAmB;iBAKhD,cAAc;;;cC9DjB,iBAAc,kBAAoB;;;cCAlC,iBAAc;;;cCQd,mBAAgB;;;cC6ChB,qBAAkB,WAAe,eAAU,WAAA,mBAAA,WAAA;;;cC7C3C,gBAAa,MAAU,YAAU,wBAAwB,OAAS,iBAAA;cAkBlE,yBAAsB,WAAe,YAAU,OAAS,iBAAe;cAkBvE,sBAAmB,kBACd,wBACM,OACf,iBAAY;cAQR,kBAAe;cAKf,iBAAc,mBAAqB,UAAY,oBAAe,WAAA;cA+B9D,wBAAqB,wBAAgC,OAAS,iBAAY;;;;;;;;;;;;;cC/E1E,iBAAc,SAChB,YAAU,WACR,YAAU,WACV,eAAU,QAAA,WAAA,mBAAA,WAAA;;;cCbV;;;;;;;;;;;;;;cAEA,aAAU,KAAS,eAAU,WAAA,mBAAA,WAAA;cAC7B,aAAU,KAAS,eAAU,WAAA,mBAAA,WAAA;cAE7B,cAAW,OAAW;;;KCuBvB;EACV;EACA;EACA;;KAGU;EACV;EACA,UAAU;;;cAoBC,uBAAkB,SAAA,YACN,aAAW,qBAEjC;;cAqCU,qBAAkB,MACvB,YAAU,uBACK,qBAEpB;;;cC7FU,oBAAiB,qBAAoB,WAAA,mBAAA,WAAA;cAIrC,oBAAiB,SAAa;cA+C9B,gBAAa,SACf,YAAU,OACZ,cAAY,sBACF,QAAA,WAAA;cAYN,kBAAe;cAIf,mBAAgB;cAUhB;cAIA;cAKA,aAAU,OAAiB,iBAAY,QAAA,WAAA;;;cCjGvC,8BAA2B,OAAW,iBAAe;cAgBrD,iCAA8B,UAAc,oBAAkB;cAe9D,gCAA6B,oBAAsB;;;;;;;;;;;;;;cCPnD,gBAAa,OACjB,cAAY,WACR,YAAU,SACZ,eACR;;cAsBU,uBAAuB,QAAQ,OAAO;;;cCrDtC,SAAM,6BACU,SAClB,YAAU,MACb,YAAU,oBACE,2BACI,QAAA,WAAA"}
|