wative-core 2.2.1 → 2.3.9

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 (36) hide show
  1. package/CHANGELOG.md +486 -13
  2. package/LICENSE +114 -0
  3. package/README.md +144 -5
  4. package/dist/artifacts/evm/index.cjs +1 -1
  5. package/dist/artifacts/evm/index.d.cts +2 -2
  6. package/dist/artifacts/evm/index.d.ts +2 -2
  7. package/dist/artifacts/evm/index.js +1 -1
  8. package/dist/artifacts/svm/index.cjs +1 -1
  9. package/dist/artifacts/svm/index.d.cts +3 -3
  10. package/dist/artifacts/svm/index.d.ts +3 -3
  11. package/dist/artifacts/svm/index.js +1 -1
  12. package/dist/{container-provider-i614LDE1.d.cts → container-provider-CkKGyHis.d.cts} +10 -3
  13. package/dist/{container-provider-C59yqd5Z.d.ts → container-provider-D_557LVN.d.ts} +10 -3
  14. package/dist/{evm-BLml33LX.d.cts → evm-Xw4zBLUH.d.ts} +2 -2
  15. package/dist/{evm-DTzqGlL6.d.ts → evm-gsdoVj16.d.cts} +2 -2
  16. package/dist/{file-sink-LS4hyXXi.d.ts → file-sink-C_SlT9IC.d.cts} +8 -5
  17. package/dist/{file-sink-B73MuigK.d.cts → file-sink-D33jvque.d.ts} +8 -5
  18. package/dist/index.cjs +1 -1
  19. package/dist/index.d.cts +20 -7
  20. package/dist/index.d.ts +20 -7
  21. package/dist/index.js +1 -1
  22. package/dist/index.node.cjs +1 -1
  23. package/dist/index.node.d.cts +6 -6
  24. package/dist/index.node.d.ts +6 -6
  25. package/dist/index.node.js +1 -1
  26. package/dist/node/index.cjs +1 -1
  27. package/dist/node/index.d.cts +3 -3
  28. package/dist/node/index.d.ts +3 -3
  29. package/dist/node/index.js +1 -1
  30. package/dist/{svm-DieFbh9k.d.ts → svm-CTCJsYri.d.cts} +2 -2
  31. package/dist/{svm-CCzqNAWM.d.cts → svm-CUuqpl1h.d.ts} +2 -2
  32. package/dist/{workspace-CamTHxso.d.cts → workspace-Du_jy51u.d.cts} +19 -4
  33. package/dist/{workspace-CamTHxso.d.ts → workspace-Du_jy51u.d.ts} +19 -4
  34. package/examples/15-package-resolution.test.cjs +187 -1
  35. package/examples/18-envelope-v3.test.cjs +106 -0
  36. package/package.json +6 -3
package/LICENSE CHANGED
@@ -53,3 +53,117 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53
53
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54
54
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55
55
  SOFTWARE.
56
+
57
+ ================================================================================
58
+ THIRD-PARTY NOTICES
59
+ ================================================================================
60
+
61
+ The terms above are the terms under which the copyright holder licenses the
62
+ portions of the Software that the copyright holder authored.
63
+
64
+ The distributed form of the Software (the files under `dist/`) additionally
65
+ embeds compiled components authored by third parties, listed below. Each is
66
+ governed by its own license, reproduced here as those licenses require. Nothing
67
+ in this section alters the terms above as they apply to the copyright holder's
68
+ own work, and nothing in the terms above — including the attribution condition —
69
+ imposes any obligation on the third-party components beyond what their own
70
+ licenses state. A recipient who obtains those components from their original
71
+ authors receives them under their original terms alone.
72
+
73
+ --------------------------------------------------------------------------------
74
+ 1. hash-wasm — MIT License
75
+ --------------------------------------------------------------------------------
76
+
77
+ Two compiled WebAssembly modules (Argon2 and BLAKE2b) extracted from hash-wasm
78
+ 4.12.0 are embedded in the distributed bundles as base64 constants.
79
+
80
+ https://github.com/Daninet/hash-wasm
81
+
82
+ MIT License
83
+
84
+ Copyright (c) 2020 Dani Biró
85
+
86
+ Permission is hereby granted, free of charge, to any person obtaining a copy
87
+ of this software and associated documentation files (the "Software"), to deal
88
+ in the Software without restriction, including without limitation the rights
89
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
90
+ copies of the Software, and to permit persons to whom the Software is
91
+ furnished to do so, subject to the following conditions:
92
+
93
+ The above copyright notice and this permission notice shall be included in all
94
+ copies or substantial portions of the Software.
95
+
96
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
97
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
98
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
99
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
100
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
101
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
102
+ SOFTWARE.
103
+
104
+ Embedded C implementations might use other, similarly permissive licenses.
105
+ Check the beginning of the files from the /src directory.
106
+
107
+ --------------------------------------------------------------------------------
108
+ 2. The Go Authors — BSD 3-Clause License
109
+ --------------------------------------------------------------------------------
110
+
111
+ The embedded Argon2 WebAssembly module is compiled from hash-wasm's
112
+ `src/argon2.c`, which states: "Based on Golang's Argon2 implementation from
113
+ crypto package". That implementation is golang.org/x/crypto/argon2, distributed
114
+ under the following license. Clause 2 requires this notice to accompany
115
+ redistribution in binary form.
116
+
117
+ Copyright (c) 2009 The Go Authors. All rights reserved.
118
+
119
+ Redistribution and use in source and binary forms, with or without
120
+ modification, are permitted provided that the following conditions are
121
+ met:
122
+
123
+ * Redistributions of source code must retain the above copyright
124
+ notice, this list of conditions and the following disclaimer.
125
+ * Redistributions in binary form must reproduce the above
126
+ copyright notice, this list of conditions and the following disclaimer
127
+ in the documentation and/or other materials provided with the
128
+ distribution.
129
+ * Neither the name of Google Inc. nor the names of its
130
+ contributors may be used to endorse or promote products derived from
131
+ this software without specific prior written permission.
132
+
133
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
134
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
135
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
136
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
137
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
138
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
139
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
140
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
141
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
142
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
143
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
144
+
145
+ --------------------------------------------------------------------------------
146
+ 3. BLAKE2 reference implementation — CC0 1.0 Universal (credit only)
147
+ --------------------------------------------------------------------------------
148
+
149
+ The embedded BLAKE2b WebAssembly module is compiled from hash-wasm's
150
+ `src/blake2b.c`, the BLAKE2 reference C implementation. Its author offers it
151
+ under CC0 1.0, the OpenSSL License, or the Apache License 2.0, at the
152
+ recipient's option. CC0 1.0 is elected here, which waives all attribution
153
+ requirements. The credit is retained regardless:
154
+
155
+ BLAKE2 reference source code package - reference C implementations
156
+ Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.
157
+ Released under CC0 1.0 Universal.
158
+ https://creativecommons.org/publicdomain/zero/1.0/
159
+ https://blake2.net
160
+
161
+ --------------------------------------------------------------------------------
162
+ Other dependencies
163
+ --------------------------------------------------------------------------------
164
+
165
+ Every other third-party library this package uses is a declared runtime
166
+ dependency, resolved from `node_modules` at load time and not embedded in
167
+ `dist/`. Each ships its own license with its own package; no reproduction is
168
+ required or attempted here.
169
+ ================================================================================
package/README.md CHANGED
@@ -152,9 +152,25 @@ await ws.lock();
152
152
  | Extra setup | none | `Buffer` polyfill |
153
153
  | Keys can vanish| no | yes — storage is evictable |
154
154
 
155
- `HybridProvider` and `FileSink` are also re-exported from the package root in
156
- Node, so existing imports keep working. New code should take them from
157
- `wative-core/node`.
155
+ `HybridProvider`, `HybridProviderV3` and `FileSink` are re-exported from the
156
+ package root in Node.
157
+
158
+ Take the provider from the **same entry point** as `Workspace`:
159
+
160
+ ```ts
161
+ // Right — one entry point.
162
+ import { Workspace, HybridProvider } from "wative-core";
163
+ const ws = await Workspace.open(new HybridProvider("~/wallets"), password);
164
+
165
+ // Wrong — rejected with a PARAMETER_ERROR naming the fix.
166
+ import { Workspace } from "wative-core";
167
+ import { HybridProvider } from "wative-core/node";
168
+ ```
169
+
170
+ Each entry point is a separate bundle with its own class identities and module
171
+ state, so a provider built by one is not recognised by a `Workspace` from the
172
+ other. `Workspace.open` rejects it with an error naming the fix. A bare
173
+ `import "wative-core/node"` for its side-effects is unaffected.
158
174
 
159
175
  ### Browser: the Buffer polyfill
160
176
 
@@ -207,6 +223,128 @@ const backup = await provider.exportContainer(); // still encrypted
207
223
  await otherProvider.importContainer(backup); // same password opens it
208
224
  ```
209
225
 
226
+ ## Key derivation
227
+
228
+ Passwords are stretched with Argon2id (RFC 9106) at t=3, m=64 MiB, p=1 before
229
+ they ever touch a key. That is deliberately expensive, and an account unlock
230
+ runs one derivation per sealed secret — so the implementation matters.
231
+
232
+ By default it runs on a vendored WebAssembly build: no native binary, no build
233
+ step, nothing to install. Measured over a full workspace lifecycle it is about
234
+ **25x** faster than the pure-JS implementation it replaced.
235
+
236
+ ### Browser: grant `'wasm-unsafe-eval'`
237
+
238
+ ```
239
+ Content-Security-Policy: script-src 'self' 'wasm-unsafe-eval'
240
+ ```
241
+
242
+ Without it the browser blocks WebAssembly compilation entirely — synchronously
243
+ and asynchronously, main thread and worker alike. **Nothing throws.** Key
244
+ derivation quietly falls back to a pure-JS implementation that produces
245
+ identical bytes roughly 17x slower, so unlocking a wallet with a dozen addresses
246
+ goes from under a second to tens of seconds. The fallback is announced once on
247
+ the console and reported permanently by `argon2BackendInfo()`.
248
+
249
+ ## Upgrading to 2.3.0
250
+
251
+ **v1 containers can no longer be opened.** Support for the v1 envelope
252
+ (PBKDF2-HMAC-SHA256, written by wative-core 1.x) was removed and there is no
253
+ migration path in this release. Containers written by any 2.x version are v2 and
254
+ open unchanged.
255
+
256
+ If you hold a v1 container, recover it with **2.2.x or earlier** before
257
+ upgrading. `exportContainer()` will not do it — it copies sealed bytes without
258
+ decrypting, so the export is as unreadable as the original. Use the accessors
259
+ that return plaintext:
260
+
261
+ ```ts
262
+ // under wative-core 2.2.x — NOT 2.3.0, which can no longer open a v1 container
263
+ import { Workspace, HybridProvider } from "wative-core";
264
+
265
+ const ws = await Workspace.open(new HybridProvider("~/wallets"), password);
266
+
267
+ for (const account of ws.accounts) {
268
+ await account.tryUnlock(password);
269
+
270
+ // HD accounts: the mnemonic regenerates every derived key, so it is the only
271
+ // thing you need.
272
+ if (account.organizationType === "HD") {
273
+ console.log(account.slug, "mnemonic:", account.dumpMnemonic());
274
+ continue;
275
+ }
276
+
277
+ // PK accounts: there is no mnemonic, so every imported key must be kept.
278
+ // `dumpPrivateKey` lives on the WALLET and takes the VM of the address you
279
+ // want — a wallet holds at most one address per VM.
280
+ for (const wallet of account.wallets) {
281
+ for (const address of wallet.addresses) {
282
+ console.log(account.slug, wallet.id, address.vm, wallet.dumpPrivateKey(address.vm));
283
+ }
284
+ }
285
+ }
286
+ ```
287
+
288
+ Keep that material somewhere safe, upgrade, then re-import it with
289
+ `accounts.create(...)` and `importPrivateKey(...)`.
290
+
291
+ Three public members were removed with v1: `Provider.passwordTanren`,
292
+ `ContainerProvider.passwordTanren` and `HybridProvider.kdfIterations`. All three
293
+ existed only to expose the PBKDF2 derivation.
294
+
295
+ ### One derivation per container: `HybridProviderV3` (Node only)
296
+
297
+ ```ts
298
+ import { Workspace, HybridProviderV3 } from "wative-core";
299
+
300
+ const ws = await Workspace.open(new HybridProviderV3("~/wallets"), password);
301
+ ```
302
+
303
+ The default provider derives an Argon2 key per sealed secret, so unlocking an
304
+ account costs one derivation per address — at production parameters that is
305
+ essentially the whole cost, and it grows with the account. `HybridProviderV3`
306
+ derives once per container instead. Measured: unlocking a 50-address account
307
+ goes from 7.3 s to 144 ms, and the v3 figure does not grow with the address
308
+ count.
309
+
310
+ It is opt-in, and Node-only: it derives through native `@node-rs/argon2`, which
311
+ has no browser build. In a browser use `HybridProvider`, which needs no binary
312
+ and no install and is already about 25x faster than what preceded it.
313
+
314
+ ⚠️ **The speedup applies to records written as v3, not to ones you already
315
+ have.** Pointing `HybridProviderV3` at a container built by 2.x keeps every
316
+ existing secret on its own salt, so it keeps costing one derivation each — the
317
+ container still opens, it just does not get faster. Rewriting an account's
318
+ secrets with `account.resetPassword(old, new)` converts them. A container
319
+ reaches one derivation once all of its records have been written as v3, which
320
+ happens on its own only for containers created under v3.
321
+
322
+ The first v3 unlock of an existing container costs one extra derivation, once,
323
+ and converts its CONFIG record to v3 — after which wative-core 2.2.x and earlier
324
+ can no longer open it.
325
+
326
+ Reads do not depend on the choice — every record carries its own version byte,
327
+ so either 2.3.0 provider opens either format, in both directions. ⚠️ But **older
328
+ library versions cannot read v3**: wative-core 2.2.x and earlier know only v1 and
329
+ v2 and will fail with `Unknown envelope version: 3`. Adopting v3 is a one-way
330
+ door with respect to the library version.
331
+
332
+ ### Checking which implementation ran
333
+
334
+ ```ts
335
+ import { argon2BackendInfo } from "wative-core";
336
+
337
+ argon2BackendInfo();
338
+ // { backend: "wasm", wasm: true, overrides: [] }
339
+ // { backend: "noble", wasm: false, reason: "...", overrides: [] } ← degraded
340
+ // { backend: "unresolved", wasm: false, ..., overrides: ["node-rs"] }
341
+ ```
342
+
343
+ `backend` is the process-wide default. A provider may carry its own — a
344
+ `HybridProviderV3` does — so check **`overrides`** to confirm the native path
345
+ took. It is a pure read and resolves nothing, so before the first unlock it
346
+ honestly answers `"unresolved"`.
347
+
210
348
  ## Runnable examples
211
349
 
212
350
  An `examples/` folder ships with the package — runnable JavaScript files demonstrating every domain's use cases. Read them top-to-bottom as walkthroughs, or run them as integration tests via Node's built-in test runner.
@@ -236,7 +374,7 @@ The library is organized around seven things you'll work with:
236
374
  - **`Address`** — an on-chain identity. Sign messages, build transactions, send them.
237
375
  - **`Network`** — chain metadata. 10 networks ship pre-loaded.
238
376
  - **`Asset`** — token metadata. 25 tokens ship pre-loaded.
239
- - **`Transaction`** — `EvmTransaction` or `SvmTransaction`. Subscribe to lifecycle events (`change` / `confirmed` / `failed`) or await terminal states (`whenSubmitted` / `whenMined` / `whenConfirmed` / `whenFinalized`).
377
+ - **`Transaction`** — `EvmTransaction` or `SvmTransaction`. Subscribe to lifecycle events (`change` / `confirmed` / `failed`) or await terminal states (`whenSubmitted` / `whenMined` / `whenConfirmed` / `whenFinalized`). Tracking stops at first inclusion, so `whenFinalized()` rejects `UNSUPPORTED_OP` unless the node reported finality directly.
240
378
 
241
379
  Everything is encrypted on disk under your workspace password.
242
380
 
@@ -568,10 +706,11 @@ import { TokenProgram, Token2022Program } from "wative-core/artifacts/svm";
568
706
 
569
707
  ## Compatibility notes
570
708
 
709
+ - **Content-Security-Policy (browser)**: grant `'wasm-unsafe-eval'` in `script-src`, or key derivation silently degrades to a ~17x slower pure-JS path. See [Key derivation](#key-derivation).
571
710
  - **Runtime**: Node.js 22.12+. Deno / Bun / browser support is partial. Some chain libraries that ship as compiled dependencies do not have universal builds yet.
572
711
  - **Platform builds**: a few compiled dependencies lack pre-built binaries for Windows-ARM64 and Alpine-musl. Most installs on macOS / Linux x64 / Linux ARM64 won't notice.
573
712
  - **One process at a time**: opening the same workspace from two Node processes simultaneously isn't supported.
574
713
 
575
714
  ## License
576
715
 
577
- [BUSL-1.1](./LICENSE) — Business Source License 1.1.
716
+ [Modified MIT](./LICENSE) — MIT terms with one added condition: products or services earning over US$50,000 monthly revenue must display "Wative" in their user interface. Everything else is standard MIT. The `LICENSE` file also carries third-party notices for the compiled components embedded in `dist/`.