hd-wallet-wasm 2.0.20 → 2.0.26
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 +190 -0
- package/README.md +104 -407
- package/dist/hd-wallet-wasi.wasm +0 -0
- package/dist/hd-wallet.js +1 -1
- package/dist/runtime/epm-attestation.d.ts +105 -0
- package/{src → dist/runtime}/epm-attestation.mjs +26 -8
- package/dist/{index.d.ts → runtime/index.d.ts} +204 -78
- package/{src → dist/runtime}/index.mjs +59 -2
- package/dist/runtime/sdn-plugin-manifest-codec.mjs +567 -0
- package/dist/runtime/sdn-typed.mjs +928 -0
- package/dist/wasm-loader.d.ts +76 -0
- package/package.json +18 -23
- package/dist/hd-wallet.wasm +0 -0
- package/src/index.d.ts +0 -1025
- /package/{src → dist/runtime}/aligned.d.ts +0 -0
- /package/{src → dist/runtime}/aligned.mjs +0 -0
- /package/{src → dist/runtime}/generated/aligned/hd_wallet_aligned.mjs +0 -0
- /package/{src → dist/runtime}/generated/sdn_plugin_manifest.mjs +0 -0
- /package/{src → dist/runtime}/sdn-plugin-manifest-source.mjs +0 -0
- /package/{src → dist/runtime}/sdn-plugin.mjs +0 -0
package/README.md
CHANGED
|
@@ -1,463 +1,160 @@
|
|
|
1
1
|
# hd-wallet-wasm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
WebAssembly HD-wallet runtime with typed JavaScript APIs for hierarchical key
|
|
4
|
+
derivation, multi-curve signing, SDN identities, aligned batch operations, and
|
|
5
|
+
canonical EPM attestations.
|
|
4
6
|
|
|
5
|
-
##
|
|
7
|
+
## Install
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- **X.509 PKI** - P-256/P-384 certificate issuance, PEM/DER/PKCS#12 interop, wallet attestations
|
|
10
|
-
- **Multi-chain** - Bitcoin, Ethereum, Solana, Cosmos, Polkadot
|
|
11
|
-
- **AES-256-GCM** - Authenticated encryption via WASM (Crypto++/OpenSSL)
|
|
12
|
-
- **Hardware wallet ready** - Trezor, Ledger, KeepKey abstraction layer
|
|
13
|
-
- **Secure** - Crypto++ backend, secure memory handling
|
|
14
|
-
- **Fast** - WebAssembly performance, synchronous cryptographic operations
|
|
15
|
-
- **TypeScript** - Full type definitions included
|
|
16
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npm install hd-wallet-wasm
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Quick Start
|
|
24
|
-
|
|
25
|
-
```javascript
|
|
26
|
-
import init from 'hd-wallet-wasm';
|
|
27
|
-
|
|
28
|
-
// Initialize the WASM module
|
|
29
|
-
const wallet = await init();
|
|
30
|
-
|
|
31
|
-
// Inject entropy (required in WASI environments)
|
|
32
|
-
const entropy = crypto.getRandomValues(new Uint8Array(32));
|
|
33
|
-
wallet.injectEntropy(entropy);
|
|
34
|
-
|
|
35
|
-
// Generate a 24-word mnemonic
|
|
36
|
-
const mnemonic = wallet.mnemonic.generate(24);
|
|
37
|
-
console.log('Mnemonic:', mnemonic);
|
|
38
|
-
|
|
39
|
-
// Derive seed from mnemonic
|
|
40
|
-
const seed = wallet.mnemonic.toSeed(mnemonic, 'optional passphrase');
|
|
41
|
-
|
|
42
|
-
// Create master key
|
|
43
|
-
const master = wallet.hdkey.fromSeed(seed);
|
|
44
|
-
|
|
45
|
-
// Derive Bitcoin key (BIP-44: m/44'/0'/0'/0/0)
|
|
46
|
-
const btcKey = master.derivePath("m/44'/0'/0'/0/0");
|
|
47
|
-
console.log('Bitcoin public key:', wallet.utils.encodeHex(btcKey.publicKey()));
|
|
48
|
-
|
|
49
|
-
// Get Bitcoin address
|
|
50
|
-
const btcAddress = wallet.bitcoin.getAddress(btcKey.publicKey(), 0); // P2PKH
|
|
51
|
-
console.log('Bitcoin address:', btcAddress);
|
|
52
|
-
|
|
53
|
-
// Derive Ethereum key (BIP-44: m/44'/60'/0'/0/0)
|
|
54
|
-
const ethKey = master.derivePath("m/44'/60'/0'/0/0");
|
|
55
|
-
const ethAddress = wallet.ethereum.getAddress(ethKey.publicKey());
|
|
56
|
-
console.log('Ethereum address:', ethAddress);
|
|
57
|
-
|
|
58
|
-
// Sign a message
|
|
59
|
-
const signature = wallet.curves.secp256k1.sign(
|
|
60
|
-
wallet.utils.sha256(new TextEncoder().encode('Hello, World!')),
|
|
61
|
-
ethKey.privateKey()
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
// Clean up
|
|
65
|
-
btcKey.wipe();
|
|
66
|
-
ethKey.wipe();
|
|
67
|
-
master.wipe();
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## X.509 PKI
|
|
71
|
-
|
|
72
|
-
The package includes a native `wallet.x509` API for regular Web PKI workflows.
|
|
73
|
-
That means you can generate interoperable X.509 certificates for TLS or device
|
|
74
|
-
identity, then optionally bind those certificates to an HD-wallet-backed key.
|
|
75
|
-
|
|
76
|
-
Why this exists:
|
|
77
|
-
|
|
78
|
-
- X.509 is what browsers, load balancers, mTLS stacks, and enterprise PKI tools already use
|
|
79
|
-
- wallet ecosystems use different key types and trust models
|
|
80
|
-
- `hd-wallet-wasm` bridges the two by embedding a wallet attestation inside a standard certificate
|
|
81
|
-
|
|
82
|
-
What it supports:
|
|
83
|
-
|
|
84
|
-
- P-256 and P-384 certificate keys
|
|
85
|
-
- self-signed and issuer-signed certificate issuance
|
|
86
|
-
- PEM, DER, and PKCS#12 import/export
|
|
87
|
-
- certificate parsing and wallet-attestation verification
|
|
88
|
-
|
|
89
|
-
Wallet attestation is additive. Certificate validation still happens through the
|
|
90
|
-
normal X.509 chain. The attestation adds a second proof path showing that the
|
|
91
|
-
certificate was bound by a selected wallet key.
|
|
92
|
-
|
|
93
|
-
```javascript
|
|
94
|
-
import init, { Curve, X509Encoding } from 'hd-wallet-wasm';
|
|
95
|
-
|
|
96
|
-
const wallet = await init();
|
|
97
|
-
const now = Math.floor(Date.now() / 1000);
|
|
98
|
-
|
|
99
|
-
const certKey = wallet.x509.generatePrivateKey(Curve.P256);
|
|
100
|
-
const certPem = wallet.x509.createSelfSignedCertificate(
|
|
101
|
-
{
|
|
102
|
-
subjectDn: 'CN=wallet.example.com,O=Digital Arsenal,C=US',
|
|
103
|
-
serialHex: '1001',
|
|
104
|
-
notBeforeUnix: now - 300,
|
|
105
|
-
notAfterUnix: now + 31536000,
|
|
106
|
-
dnsNames: ['wallet.example.com'],
|
|
107
|
-
keyUsage: ['digitalSignature', 'keyEncipherment'],
|
|
108
|
-
extendedKeyUsage: ['serverAuth'],
|
|
109
|
-
walletAttestation: {
|
|
110
|
-
curve: Curve.SECP256K1,
|
|
111
|
-
privateKey: wallet.utils.decodeHex(
|
|
112
|
-
'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'
|
|
113
|
-
),
|
|
114
|
-
keyLabel: 'btc-root'
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
Curve.P256,
|
|
118
|
-
certKey,
|
|
119
|
-
X509Encoding.PEM
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
const parsed = wallet.x509.parseCertificate(certPem);
|
|
123
|
-
const valid = wallet.x509.verifyWalletAttestation(certPem);
|
|
124
|
-
const pkcs12 = wallet.x509.exportPkcs12(
|
|
125
|
-
certPem,
|
|
126
|
-
X509Encoding.PEM,
|
|
127
|
-
Curve.P256,
|
|
128
|
-
certKey,
|
|
129
|
-
'changeit',
|
|
130
|
-
'wallet-example'
|
|
131
|
-
);
|
|
9
|
+
```sh
|
|
10
|
+
npm install hd-wallet-wasm@2.0.26
|
|
132
11
|
```
|
|
133
12
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
13
|
+
Use the package through a standards-compliant ESM bundler or from an installed
|
|
14
|
+
Node project. Production deployments should serve only artifacts emitted by a
|
|
15
|
+
verified package build over HTTPS.
|
|
137
16
|
|
|
138
|
-
##
|
|
17
|
+
## Published surfaces
|
|
139
18
|
|
|
140
|
-
|
|
19
|
+
| Import | Purpose |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| `hd-wallet-wasm` | High-level wallet initializer and typed runtime API |
|
|
22
|
+
| `hd-wallet-wasm/aligned` | Aligned batch-operation API |
|
|
23
|
+
| `hd-wallet-wasm/attestation` | Canonical EPM payload, signing, and verification helpers |
|
|
24
|
+
| `hd-wallet-wasm/wasm` | Low-level Emscripten module factory |
|
|
25
|
+
| `hd-wallet-wasm/wasi.wasm` | Canonical WASI binary |
|
|
26
|
+
| `hd-wallet-wasm/dist/hd-wallet-wasi.wasm` | Compatibility name for the same WASI binary |
|
|
141
27
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
28
|
+
All JavaScript and declaration dependencies needed by these surfaces are
|
|
29
|
+
included under the package's staged `dist/runtime/` tree. Repository source,
|
|
30
|
+
tests, maps, and build tarballs are excluded from the published package.
|
|
145
31
|
|
|
146
|
-
|
|
147
|
-
const isValid = wallet.mnemonic.validate(mnemonic);
|
|
32
|
+
## Initialize the wallet
|
|
148
33
|
|
|
149
|
-
|
|
150
|
-
|
|
34
|
+
```js
|
|
35
|
+
import initializeWallet from 'hd-wallet-wasm';
|
|
151
36
|
|
|
152
|
-
|
|
153
|
-
const entropy = wallet.mnemonic.toEntropy(mnemonic);
|
|
154
|
-
const recovered = wallet.mnemonic.fromEntropy(entropy);
|
|
37
|
+
const wallet = await initializeWallet();
|
|
155
38
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const japanese = wallet.mnemonic.generate(24, Language.JAPANESE);
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### HD Keys (BIP-32)
|
|
162
|
-
|
|
163
|
-
```javascript
|
|
164
|
-
// From seed
|
|
165
|
-
const master = wallet.hdkey.fromSeed(seed);
|
|
166
|
-
|
|
167
|
-
// From extended key
|
|
168
|
-
const restored = wallet.hdkey.fromXprv('xprv...');
|
|
169
|
-
const watchOnly = wallet.hdkey.fromXpub('xpub...');
|
|
170
|
-
|
|
171
|
-
// Derivation
|
|
172
|
-
const child = master.deriveChild(0);
|
|
173
|
-
const hardened = master.deriveHardened(0);
|
|
174
|
-
const path = master.derivePath("m/44'/0'/0'/0/0");
|
|
175
|
-
|
|
176
|
-
// Serialization
|
|
177
|
-
const xprv = master.toXprv();
|
|
178
|
-
const xpub = master.toXpub();
|
|
179
|
-
|
|
180
|
-
// Get neutered (public only) version
|
|
181
|
-
const pubOnly = master.neutered();
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
### Signing & Encryption Keys (BIP-44)
|
|
185
|
-
|
|
186
|
-
The library provides dedicated helpers for deriving separate signing and encryption
|
|
187
|
-
keypairs from a single HD root. Signing keys use BIP-44 change=0 (external chain);
|
|
188
|
-
encryption keys use change=1 (internal chain).
|
|
189
|
-
|
|
190
|
-
```javascript
|
|
191
|
-
import { getSigningKey, getEncryptionKey, buildSigningPath, buildEncryptionPath, WellKnownCoinType } from 'hd-wallet-wasm';
|
|
39
|
+
const entropy = crypto.getRandomValues(new Uint8Array(32));
|
|
40
|
+
wallet.injectEntropy(entropy);
|
|
192
41
|
|
|
42
|
+
const phrase = wallet.mnemonic.generate(24);
|
|
43
|
+
const seed = wallet.mnemonic.toSeed(phrase, 'optional passphrase');
|
|
193
44
|
const master = wallet.hdkey.fromSeed(seed);
|
|
45
|
+
const child = master.derivePath("m/44'/0'/0'/0/0");
|
|
194
46
|
|
|
195
|
-
|
|
196
|
-
const
|
|
197
|
-
console.log('Signing pubkey:', wallet.utils.encodeHex(signing.publicKey));
|
|
198
|
-
console.log('Path:', signing.path); // "m/44'/60'/0'/0/0"
|
|
199
|
-
|
|
200
|
-
// Get encryption keypair for SDN (m/44'/0'/0'/1/0)
|
|
201
|
-
const encryption = getEncryptionKey(master, WellKnownCoinType.SDN);
|
|
202
|
-
console.log('Encryption pubkey:', wallet.utils.encodeHex(encryption.publicKey));
|
|
203
|
-
|
|
204
|
-
// Use encryption key for ECDH key agreement
|
|
205
|
-
const shared = wallet.curves.secp256k1.ecdh(encryption.privateKey, otherPublicKey);
|
|
47
|
+
const digest = wallet.utils.sha256(new TextEncoder().encode('example'));
|
|
48
|
+
const signature = wallet.curves.secp256k1.sign(digest, child.privateKey());
|
|
206
49
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const plugin1Key = getEncryptionKey(master, 0, '0', '1');
|
|
210
|
-
|
|
211
|
-
// Path helpers are also available directly
|
|
212
|
-
const sigPath = buildSigningPath(60); // "m/44'/60'/0'/0/0"
|
|
213
|
-
const encPath = buildEncryptionPath(0); // "m/44'/0'/0'/1/0"
|
|
214
|
-
|
|
215
|
-
// Clean up
|
|
216
|
-
wallet.utils.secureWipe(signing.privateKey);
|
|
217
|
-
wallet.utils.secureWipe(encryption.privateKey);
|
|
50
|
+
wallet.utils.secureWipe(seed);
|
|
51
|
+
child.wipe();
|
|
218
52
|
master.wipe();
|
|
219
53
|
```
|
|
220
54
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
```javascript
|
|
224
|
-
const signing = wallet.getSigningKey(master, 60);
|
|
225
|
-
const encryption = wallet.getEncryptionKey(master, 0);
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
### Multi-Curve Cryptography
|
|
55
|
+
`createHDWallet()` is an equivalent named initializer:
|
|
229
56
|
|
|
230
|
-
```
|
|
231
|
-
import {
|
|
57
|
+
```js
|
|
58
|
+
import { createHDWallet } from 'hd-wallet-wasm';
|
|
232
59
|
|
|
233
|
-
|
|
234
|
-
const sig = wallet.curves.secp256k1.sign(message, privateKey);
|
|
235
|
-
const valid = wallet.curves.secp256k1.verify(message, sig, publicKey);
|
|
236
|
-
const shared = wallet.curves.secp256k1.ecdh(myPrivate, theirPublic);
|
|
237
|
-
|
|
238
|
-
// Ed25519 (Solana)
|
|
239
|
-
const edSig = wallet.curves.ed25519.sign(message, privateKey);
|
|
240
|
-
const edValid = wallet.curves.ed25519.verify(message, edSig, publicKey);
|
|
241
|
-
|
|
242
|
-
// P-256, P-384 (FIPS compliant)
|
|
243
|
-
const p256Sig = wallet.curves.p256.sign(message, privateKey);
|
|
244
|
-
const p384Sig = wallet.curves.p384.sign(message, privateKey);
|
|
245
|
-
|
|
246
|
-
// X25519 (key exchange only)
|
|
247
|
-
const x25519Shared = wallet.curves.x25519.ecdh(myPrivate, theirPublic);
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
### Bitcoin
|
|
251
|
-
|
|
252
|
-
```javascript
|
|
253
|
-
import { BitcoinAddressType, Network } from 'hd-wallet-wasm';
|
|
254
|
-
|
|
255
|
-
// Address generation
|
|
256
|
-
const p2pkh = wallet.bitcoin.getAddress(pubKey, BitcoinAddressType.P2PKH);
|
|
257
|
-
const p2wpkh = wallet.bitcoin.getAddress(pubKey, BitcoinAddressType.P2WPKH);
|
|
258
|
-
const p2tr = wallet.bitcoin.getAddress(pubKey, BitcoinAddressType.P2TR);
|
|
259
|
-
|
|
260
|
-
// Testnet
|
|
261
|
-
const testAddr = wallet.bitcoin.getAddress(pubKey, BitcoinAddressType.P2WPKH, Network.TESTNET);
|
|
262
|
-
|
|
263
|
-
// Message signing (Bitcoin Signed Message format)
|
|
264
|
-
const sig = wallet.bitcoin.signMessage('Hello', privateKey);
|
|
265
|
-
const valid = wallet.bitcoin.verifyMessage('Hello', sig, address);
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
### Ethereum
|
|
269
|
-
|
|
270
|
-
```javascript
|
|
271
|
-
// Address (EIP-55 checksummed)
|
|
272
|
-
const address = wallet.ethereum.getAddress(publicKey);
|
|
273
|
-
|
|
274
|
-
// Message signing (EIP-191)
|
|
275
|
-
const sig = wallet.ethereum.signMessage('Hello', privateKey);
|
|
276
|
-
|
|
277
|
-
// Typed data signing (EIP-712)
|
|
278
|
-
const typedSig = wallet.ethereum.signTypedData(typedData, privateKey);
|
|
279
|
-
|
|
280
|
-
// Verify and recover signer
|
|
281
|
-
const signer = wallet.ethereum.verifyMessage('Hello', sig);
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
### Solana
|
|
285
|
-
|
|
286
|
-
```javascript
|
|
287
|
-
// Address (Base58)
|
|
288
|
-
const address = wallet.solana.getAddress(publicKey);
|
|
289
|
-
|
|
290
|
-
// Message signing
|
|
291
|
-
const sig = wallet.solana.signMessage(message, privateKey);
|
|
292
|
-
const valid = wallet.solana.verifyMessage(message, sig, publicKey);
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
### Cosmos
|
|
296
|
-
|
|
297
|
-
```javascript
|
|
298
|
-
// Address with custom prefix
|
|
299
|
-
const cosmosAddr = wallet.cosmos.getAddress(publicKey, 'cosmos');
|
|
300
|
-
const osmoAddr = wallet.cosmos.getAddress(publicKey, 'osmo');
|
|
301
|
-
|
|
302
|
-
// Amino signing (legacy)
|
|
303
|
-
const aminoSig = wallet.cosmos.signAmino(aminoDoc, privateKey);
|
|
304
|
-
|
|
305
|
-
// Direct signing (protobuf)
|
|
306
|
-
const directSig = wallet.cosmos.signDirect(bodyBytes, authInfoBytes, chainId, accountNumber, privateKey);
|
|
60
|
+
const wallet = await createHDWallet();
|
|
307
61
|
```
|
|
308
62
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
```javascript
|
|
312
|
-
// SS58 address
|
|
313
|
-
const dotAddr = wallet.polkadot.getAddress(publicKey, 0); // Polkadot
|
|
314
|
-
const ksmAddr = wallet.polkadot.getAddress(publicKey, 2); // Kusama
|
|
315
|
-
|
|
316
|
-
// Message signing
|
|
317
|
-
const sig = wallet.polkadot.signMessage(message, privateKey);
|
|
318
|
-
```
|
|
63
|
+
Both initializers take no configuration arguments. Package staging keeps the
|
|
64
|
+
high-level wrapper bound to its verified adjacent loader.
|
|
319
65
|
|
|
320
|
-
|
|
66
|
+
## SDN wallet-origin capability
|
|
321
67
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const keccak = wallet.utils.keccak256(data);
|
|
326
|
-
const blake2b = wallet.utils.blake2b(data, 32);
|
|
68
|
+
The high-level initializer installs an immutable capability on the exact module
|
|
69
|
+
instance it creates. Resolve it with `getWalletOriginCapabilities()` when
|
|
70
|
+
mounting `hd-wallet-ui/wallet-origin`:
|
|
327
71
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
const base58 = wallet.utils.encodeBase58(data);
|
|
331
|
-
const bech32 = wallet.utils.encodeBech32('bc', data);
|
|
72
|
+
```js
|
|
73
|
+
import initializeWallet, { getWalletOriginCapabilities } from 'hd-wallet-wasm';
|
|
332
74
|
|
|
333
|
-
|
|
334
|
-
const
|
|
335
|
-
const pbkdf2 = wallet.utils.pbkdf2(password, salt, 100000, 32);
|
|
336
|
-
|
|
337
|
-
// Secure wipe
|
|
338
|
-
wallet.utils.secureWipe(sensitiveData);
|
|
75
|
+
const wallet = await initializeWallet();
|
|
76
|
+
const capability = getWalletOriginCapabilities(wallet);
|
|
339
77
|
```
|
|
340
78
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
```javascript
|
|
344
|
-
// Generate key and IV
|
|
345
|
-
const key = wallet.utils.generateAesKey(256); // 32 bytes for AES-256
|
|
346
|
-
const iv = wallet.utils.generateIv(); // 12 bytes
|
|
79
|
+
Copied or forged objects are rejected. Keep the initialized module and its
|
|
80
|
+
capability private to the wallet origin.
|
|
347
81
|
|
|
348
|
-
|
|
349
|
-
const plaintext = new TextEncoder().encode('Secret data');
|
|
350
|
-
const { ciphertext, tag } = wallet.utils.aesGcm.encrypt(key, plaintext, iv);
|
|
82
|
+
## Aligned operations
|
|
351
83
|
|
|
352
|
-
|
|
353
|
-
|
|
84
|
+
```ts
|
|
85
|
+
import initializeWallet from 'hd-wallet-wasm';
|
|
86
|
+
import type { AlignedAPI } from 'hd-wallet-wasm/aligned';
|
|
354
87
|
|
|
355
|
-
|
|
356
|
-
const
|
|
357
|
-
const enc = wallet.utils.aesGcm.encrypt(key, plaintext, iv, aad);
|
|
358
|
-
const dec = wallet.utils.aesGcm.decrypt(key, enc.ciphertext, enc.tag, iv, aad);
|
|
88
|
+
const wallet = await initializeWallet();
|
|
89
|
+
const aligned: AlignedAPI = wallet.aligned;
|
|
359
90
|
```
|
|
360
91
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
```javascript
|
|
364
|
-
// Generate cryptographically secure random bytes
|
|
365
|
-
const randomBytes = wallet.utils.getRandomBytes(32);
|
|
92
|
+
The initialized high-level module also exposes its aligned API. Refer to the
|
|
93
|
+
shipped TypeScript declarations for the complete batch surface.
|
|
366
94
|
|
|
367
|
-
|
|
368
|
-
const iv = wallet.utils.generateIv();
|
|
369
|
-
|
|
370
|
-
// Generate random AES key (128, 192, or 256 bits)
|
|
371
|
-
const aes128Key = wallet.utils.generateAesKey(128);
|
|
372
|
-
const aes256Key = wallet.utils.generateAesKey(256);
|
|
373
|
-
```
|
|
95
|
+
## Canonical attestations
|
|
374
96
|
|
|
375
|
-
|
|
97
|
+
```js
|
|
98
|
+
import {
|
|
99
|
+
buildCanonicalPayload,
|
|
100
|
+
signEPMContent,
|
|
101
|
+
verifyEPMSignature,
|
|
102
|
+
} from 'hd-wallet-wasm/attestation';
|
|
376
103
|
|
|
377
|
-
|
|
378
|
-
|
|
104
|
+
const canonicalPayload = buildCanonicalPayload({
|
|
105
|
+
xpub,
|
|
106
|
+
signingPubKeyHex,
|
|
107
|
+
encryptionPubKeyHex,
|
|
108
|
+
issuedAt: Math.floor(Date.now() / 1000),
|
|
109
|
+
});
|
|
379
110
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
CoinType.SOLANA // 501
|
|
387
|
-
// ... and 50+ more
|
|
111
|
+
const result = signEPMContent(wallet, epm, privateKey, {
|
|
112
|
+
curve: 'ed25519',
|
|
113
|
+
});
|
|
114
|
+
const valid = verifyEPMSignature(wallet, epm, publicKey, {
|
|
115
|
+
curve: 'ed25519',
|
|
116
|
+
});
|
|
388
117
|
```
|
|
389
118
|
|
|
390
|
-
|
|
119
|
+
The dedicated attestation subpath and root package expose the same declaration
|
|
120
|
+
surface for these helpers.
|
|
391
121
|
|
|
392
|
-
|
|
393
|
-
<script type="module">
|
|
394
|
-
import init from 'https://unpkg.com/hd-wallet-wasm/src/index.mjs';
|
|
122
|
+
## Low-level module
|
|
395
123
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
</script>
|
|
399
|
-
```
|
|
400
|
-
|
|
401
|
-
## Security Notes
|
|
402
|
-
|
|
403
|
-
- Always inject entropy from a cryptographically secure source before generating mnemonics
|
|
404
|
-
- Use `wipe()` to securely clear sensitive key material when done
|
|
405
|
-
- Never log or expose private keys or mnemonics
|
|
406
|
-
- Consider using hardware wallets for high-value operations
|
|
407
|
-
- The library enforces key separation: external chain (0) for signing, internal chain (1) for encryption
|
|
408
|
-
|
|
409
|
-
## FIPS 140-3 Mode
|
|
410
|
-
|
|
411
|
-
The published NPM package includes OpenSSL 3.0.9 FIPS Provider support for compliance-critical applications.
|
|
124
|
+
Consumers that intentionally need the raw Emscripten API may initialize it
|
|
125
|
+
directly:
|
|
412
126
|
|
|
413
|
-
|
|
127
|
+
```js
|
|
128
|
+
import initializeRawModule from 'hd-wallet-wasm/wasm';
|
|
414
129
|
|
|
415
|
-
|
|
416
|
-
import init from 'hd-wallet-wasm';
|
|
417
|
-
|
|
418
|
-
const wallet = await init();
|
|
419
|
-
|
|
420
|
-
// Check if OpenSSL is available
|
|
421
|
-
console.log('OpenSSL compiled:', wallet.isOpenSSL());
|
|
422
|
-
|
|
423
|
-
// Initialize FIPS mode
|
|
424
|
-
const fipsEnabled = wallet.initFips();
|
|
425
|
-
console.log('FIPS active:', wallet.isOpenSSLFips());
|
|
130
|
+
const raw = await initializeRawModule();
|
|
426
131
|
```
|
|
427
132
|
|
|
428
|
-
|
|
133
|
+
Prefer the root package for normal wallet work. Its wrapper owns module
|
|
134
|
+
construction, typed APIs, and wallet-origin capability binding.
|
|
429
135
|
|
|
430
|
-
|
|
136
|
+
## WASI artifact
|
|
431
137
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
| ECDSA P-256/P-384 | OpenSSL FIPS | Crypto++ |
|
|
437
|
-
| HKDF/PBKDF2 | OpenSSL FIPS | Crypto++ |
|
|
438
|
-
| secp256k1 | Crypto++ | Crypto++ |
|
|
439
|
-
| Ed25519 | Crypto++ | Crypto++ |
|
|
440
|
-
| Keccak-256 | Crypto++ | Crypto++ |
|
|
138
|
+
`hd-wallet-wasm/wasi.wasm` and
|
|
139
|
+
`hd-wallet-wasm/dist/hd-wallet-wasi.wasm` resolve to the same file. Select the
|
|
140
|
+
name required by the host runtime, and validate the installed artifact before
|
|
141
|
+
executing it. The package includes only the canonical release binary.
|
|
441
142
|
|
|
442
|
-
|
|
143
|
+
## Security
|
|
443
144
|
|
|
444
|
-
|
|
145
|
+
- Supply entropy only from the platform cryptographic random source.
|
|
146
|
+
- Keep credential and private-key operations inside a trusted origin or process.
|
|
147
|
+
- Clear mutable secret buffers and call key `wipe()` methods after use.
|
|
148
|
+
- Pin a reviewed package version and preserve integrity metadata when self-hosting.
|
|
149
|
+
- Do not load executable wallet artifacts from third-party CDNs.
|
|
445
150
|
|
|
446
|
-
|
|
447
|
-
|--------|-------------|
|
|
448
|
-
| `wallet.isOpenSSL()` | Check if OpenSSL backend is compiled in |
|
|
449
|
-
| `wallet.initFips()` | Initialize FIPS mode; returns true if successful |
|
|
450
|
-
| `wallet.isOpenSSLFips()` | Check if FIPS provider is currently active |
|
|
451
|
-
| `wallet.isFipsMode()` | Check if compiled with FIPS mode enabled |
|
|
151
|
+
## Verification
|
|
452
152
|
|
|
453
|
-
|
|
153
|
+
The repository release lane stages an exact runtime inventory, validates the
|
|
154
|
+
WebAssembly header, packs the package with scripts disabled, installs it into a
|
|
155
|
+
clean external project, resolves every export inside that installation, and
|
|
156
|
+
type-checks representative NodeNext usage.
|
|
454
157
|
|
|
455
158
|
## License
|
|
456
159
|
|
|
457
|
-
Apache-2.0
|
|
458
|
-
|
|
459
|
-
## Links
|
|
460
|
-
|
|
461
|
-
- [Documentation](https://digitalarsenal.github.io/hd-wallet-wasm/)
|
|
462
|
-
- [GitHub](https://github.com/DigitalArsenal/hd-wallet-wasm)
|
|
463
|
-
- [API Reference](https://digitalarsenal.github.io/hd-wallet-wasm/api/)
|
|
160
|
+
Apache-2.0. See `LICENSE`.
|
package/dist/hd-wallet-wasi.wasm
CHANGED
|
Binary file
|