wative-core 2.4.1 → 2.4.2

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 (35) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +47 -32
  3. package/dist/artifacts/evm/index.cjs +1 -1
  4. package/dist/artifacts/evm/index.d.cts +2 -2
  5. package/dist/artifacts/evm/index.d.ts +2 -2
  6. package/dist/artifacts/evm/index.js +1 -1
  7. package/dist/artifacts/svm/index.cjs +1 -1
  8. package/dist/artifacts/svm/index.d.cts +3 -3
  9. package/dist/artifacts/svm/index.d.ts +3 -3
  10. package/dist/artifacts/svm/index.js +1 -1
  11. package/dist/{container-provider--npoeR2N.d.ts → container-provider-B8M0ylrK.d.ts} +1 -1
  12. package/dist/{container-provider-Ca_5z1uQ.d.cts → container-provider-YxyMpkhG.d.cts} +1 -1
  13. package/dist/{evm-EHpaW_sK.d.ts → evm-Bo3Dy492.d.ts} +1 -1
  14. package/dist/{evm-hSJJOVG3.d.cts → evm-DA6Sh6jv.d.cts} +1 -1
  15. package/dist/{file-sink-Bk5zYHw-.d.ts → file-sink-Be5iLbuT.d.ts} +2 -2
  16. package/dist/{file-sink-7ZAutH45.d.cts → file-sink-KCCpKHRj.d.cts} +2 -2
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.d.cts +6 -6
  19. package/dist/index.d.ts +6 -6
  20. package/dist/index.js +1 -1
  21. package/dist/index.node.cjs +1 -1
  22. package/dist/index.node.d.cts +5 -5
  23. package/dist/index.node.d.ts +5 -5
  24. package/dist/index.node.js +1 -1
  25. package/dist/node/index.cjs +1 -1
  26. package/dist/node/index.d.cts +3 -3
  27. package/dist/node/index.d.ts +3 -3
  28. package/dist/node/index.js +1 -1
  29. package/dist/{svm-B5q8YaV9.d.ts → svm-B51NevS8.d.ts} +1 -1
  30. package/dist/{svm-CXFwmeMo.d.cts → svm-DswX6XRv.d.cts} +1 -1
  31. package/dist/{workspace-kq3QyAgm.d.cts → workspace-CBxKR80D.d.cts} +2 -1
  32. package/dist/{workspace-kq3QyAgm.d.ts → workspace-CBxKR80D.d.ts} +2 -1
  33. package/examples/03-pk-account.test.cjs +65 -0
  34. package/examples/README.md +1 -1
  35. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { c as Address, G as SvmTxBuildParams, F as SvmTransaction } from './workspace-kq3QyAgm.js';
1
+ import { c as Address, G as SvmTxBuildParams, F as SvmTransaction } from './workspace-CBxKR80D.js';
2
2
 
3
3
  interface SvmInstruction {
4
4
  readonly programId: string;
@@ -1,4 +1,4 @@
1
- import { c as Address, G as SvmTxBuildParams, F as SvmTransaction } from './workspace-kq3QyAgm.cjs';
1
+ import { c as Address, G as SvmTxBuildParams, F as SvmTransaction } from './workspace-CBxKR80D.cjs';
2
2
 
3
3
  interface SvmInstruction {
4
4
  readonly programId: string;
@@ -622,7 +622,8 @@ declare class Account {
622
622
  after: number;
623
623
  dropped: number;
624
624
  }>;
625
- importPrivateKey(pk: string, vm: ChainVM): Promise<Wallet>;
625
+
626
+ importPrivateKey(pk: string, vm?: ChainVM): Promise<Wallet>;
626
627
  drop(): Promise<void>;
627
628
 
628
629
  filterAddress(network: NetworkLike, addr?: string): Address | null;
@@ -622,7 +622,8 @@ declare class Account {
622
622
  after: number;
623
623
  dropped: number;
624
624
  }>;
625
- importPrivateKey(pk: string, vm: ChainVM): Promise<Wallet>;
625
+
626
+ importPrivateKey(pk: string, vm?: ChainVM): Promise<Wallet>;
626
627
  drop(): Promise<void>;
627
628
 
628
629
  filterAddress(network: NetworkLike, addr?: string): Address | null;
@@ -1,4 +1,18 @@
1
1
  // 03 — PK account flows. Heterogeneous private keys, one wallet per import.
2
+ //
3
+ // Two things worth noticing as you read:
4
+ //
5
+ // * `vm` is optional. The key formats do not overlap — 64 hex characters for
6
+ // EVM, 80–96 base58 (or a solana-keygen JSON array) for Solana — so the
7
+ // chain is read off the key. Pass it anyway when you want the mismatch to
8
+ // be an error rather than an inference.
9
+ //
10
+ // * One import gives you TWO addresses. The key signs on its own chain, and
11
+ // the same 32 secret bytes seed a keypair on the other one, so the wallet
12
+ // has an address on both. The chain you imported for stays first.
13
+ // ⚠️ One secret controls both addresses. That is different from an HD
14
+ // account, where a slot's two addresses come from two derivation paths and
15
+ // are independent keys.
2
16
 
3
17
  const test = require("node:test");
4
18
  const assert = require("node:assert");
@@ -10,6 +24,16 @@ const { Workspace } = require("wative-core");
10
24
 
11
25
  const EVM_PK = "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d";
12
26
  const SVM_PK = "xtGWcHvQsr5ue8zG2F5fm31bW8vyn597Y92gUWaZZg3S1Z6FeJMATL8KU3xJMGbLfALnokcct9y5wYtCRrwNXZW";
27
+ // A second Solana key, base58 of its 64-byte secret key.
28
+ const SVM_PK_2 = "gaiC7Rnf9J6tV3SGwJyzvMDdz9RMmreSWZDyDK682MUKZHaWdZbbqgf35qD7FSwXka2Rf2o4MuhbWQTg82W9mbV";
29
+ // A third, in the shape `solana-keygen` writes: the 64 secret-key bytes as
30
+ // JSON. This is literally the contents of ~/.config/solana/id.json.
31
+ const SVM_KEYGEN_BYTES = [
32
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
33
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
34
+ 23, 203, 121, 251, 43, 65, 32, 242, 177, 236, 101, 228, 25, 141, 110, 8,
35
+ 178, 142, 129, 63, 235, 1, 228, 164, 0, 131, 155, 133, 225, 128, 128, 206,
36
+ ];
13
37
 
14
38
  test("PK account — create from EVM key + import a Solana key", async () => {
15
39
  const root = mkdtempSync(join(tmpdir(), "wative-pk-"));
@@ -24,11 +48,52 @@ test("PK account — create from EVM key + import a Solana key", async () => {
24
48
  );
25
49
  assert.strictEqual(acc.organizationType, "PK");
26
50
  assert.strictEqual(acc.wallets.length, 1);
51
+ // The chain the key is for comes first; its sibling follows.
27
52
  assert.strictEqual(acc.wallets[0].addresses[0].vm, "evm");
53
+ assert.strictEqual(acc.wallets[0].addresses[1].vm, "svm");
28
54
 
29
55
  await acc.importPrivateKey(SVM_PK, "svm");
30
56
  assert.strictEqual(acc.wallets.length, 2);
31
57
  assert.strictEqual(acc.wallets[1].addresses[0].vm, "svm");
58
+ assert.strictEqual(acc.wallets[1].addresses[1].vm, "evm");
59
+
60
+ await ws.lock();
61
+ });
62
+
63
+ // The three ways you are likely to be holding a private key, and what each
64
+ // one does without being told which chain it belongs to.
65
+ test("PK account — the key formats importPrivateKey accepts", async () => {
66
+ const root = mkdtempSync(join(tmpdir(), "wative-pk-fmt-"));
67
+ const ws = await Workspace.open({ path: root, password: "wsp-pwd" });
68
+ const acc = await ws.accounts.create("Formats", "wsp-pwd", EVM_PK, undefined, { kind: "PK" });
69
+
70
+ // 1. EVM: 32 bytes of hex, 0x-prefix optional. No vm argument needed.
71
+ const evm = await acc.importPrivateKey(
72
+ "0x6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1",
73
+ );
74
+ assert.strictEqual(evm.addresses[0].vm, "evm");
75
+
76
+ // 2. Solana: base58 of the 64-byte secret key.
77
+ const svm = await acc.importPrivateKey(SVM_PK_2);
78
+ assert.strictEqual(svm.addresses[0].vm, "svm");
79
+
80
+ // 3. Solana: the JSON byte array `solana-keygen` writes to id.json. This is
81
+ // what you get from `cat ~/.config/solana/id.json`, usable as-is.
82
+ const fromKeygen = await acc.importPrivateKey(JSON.stringify(SVM_KEYGEN_BYTES));
83
+ assert.strictEqual(fromKeygen.addresses[0].vm, "svm");
84
+
85
+ // A value that is neither is refused rather than guessed at.
86
+ await assert.rejects(
87
+ acc.importPrivateKey("definitely-not-a-key"),
88
+ (err) => err.code === "INVALID_PRIVATE_KEY",
89
+ );
90
+
91
+ // So is 32 bytes of hex that is not a valid secp256k1 scalar — being the
92
+ // right length is not the same as being a key.
93
+ await assert.rejects(
94
+ acc.importPrivateKey("0x" + "0".repeat(64), "evm"),
95
+ (err) => err.code === "INVALID_PRIVATE_KEY",
96
+ );
32
97
 
33
98
  await ws.lock();
34
99
  });
@@ -33,7 +33,7 @@ All tests work fully offline — no RPC calls, no real networks. Each test creat
33
33
  |---|---|
34
34
  | [01-quick-start.test.cjs](01-quick-start.test.cjs) | Open a workspace, create an HD account, derive 5 wallets, inspect EVM + Solana addresses, lock. |
35
35
  | [02-hd-account.test.cjs](02-hd-account.test.cjs) | HD-specific flows — deriving / slicing wallets, dumping the mnemonic, account-level passwords with `resetPassword`, round-trip across lock + reopen. |
36
- | [03-pk-account.test.cjs](03-pk-account.test.cjs) | PK accounts — creating from a private key, importing more keys (mix EVM + Solana under one account), duplicate-import rejection, dropping wallets. |
36
+ | [03-pk-account.test.cjs](03-pk-account.test.cjs) | PK accounts — creating from a private key, importing more keys, and the three key formats accepted (EVM hex, Solana base58, `solana-keygen` JSON) with the chain inferred from the key. Also shows each import producing an address on both chains, duplicate-import rejection, and dropping wallets. |
37
37
  | [04-network-management.test.cjs](04-network-management.test.cjs) | The 10 pre-loaded networks, adding a brand-new network, overriding a pre-loaded RPC URL via `update()`, dropping user networks, the built-in protection guard. |
38
38
  | [05-asset-management.test.cjs](05-asset-management.test.cjs) | The 25 pre-loaded tokens, adding a custom user token, id collision rejection, contract-address collision rejection, dropping user tokens, `workspace.filter(q, "Asset")` search. |
39
39
  | [06-address-signing.test.cjs](06-address-signing.test.cjs) | Personal-message signing on EVM and Solana, building a transaction fully offline (no RPC). |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wative-core",
3
- "version": "2.4.1",
3
+ "version": "2.4.2",
4
4
  "description": "Hyperscale crypto wallet management library — multi-workspace, multi-chain, originally designed for on-chain market makers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.node.cjs",