wative-core 2.5.0 → 2.5.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.
- package/CHANGELOG.md +9 -0
- package/README.md +9 -7
- package/dist/artifacts/evm/index.cjs +1 -1
- package/dist/artifacts/evm/index.d.cts +2 -2
- package/dist/artifacts/evm/index.d.ts +2 -2
- package/dist/artifacts/evm/index.js +1 -1
- package/dist/artifacts/svm/index.cjs +1 -1
- package/dist/artifacts/svm/index.d.cts +3 -3
- package/dist/artifacts/svm/index.d.ts +3 -3
- package/dist/artifacts/svm/index.js +1 -1
- package/dist/{container-provider-DMZGR5MP.d.ts → container-provider-CBBJbpUn.d.ts} +1 -1
- package/dist/{container-provider-BCG7wTYx.d.cts → container-provider-COvXmCLM.d.cts} +1 -1
- package/dist/{evm-BZoe2IFx.d.ts → evm-Dk4ceFz0.d.ts} +1 -1
- package/dist/{evm-BeI4m7M5.d.cts → evm-V5Fn53uW.d.cts} +1 -1
- package/dist/{file-sink-CuPr45EN.d.ts → file-sink-Bf9mpegF.d.ts} +2 -2
- package/dist/{file-sink-BLqWAqHB.d.cts → file-sink-BjbtAHUL.d.cts} +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +1 -1
- package/dist/index.node.cjs +1 -1
- package/dist/index.node.d.cts +5 -5
- package/dist/index.node.d.ts +5 -5
- package/dist/index.node.js +1 -1
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.d.cts +3 -3
- package/dist/node/index.d.ts +3 -3
- package/dist/node/index.js +1 -1
- package/dist/{svm-Bi74PhrA.d.cts → svm-CjNIJZ4l.d.cts} +1 -1
- package/dist/{svm-BQMaUXEA.d.ts → svm-D8zsWS64.d.ts} +1 -1
- package/dist/{workspace-ZNpsa6W7.d.cts → workspace-DqUdScht.d.cts} +14 -2
- package/dist/{workspace-ZNpsa6W7.d.ts → workspace-DqUdScht.d.ts} +14 -2
- package/examples/20-custom-chain-dialect.test.cjs +6 -6
- package/examples/21-token-transfer.test.cjs +13 -13
- package/examples/README.md +2 -2
- package/package.json +1 -1
|
@@ -248,6 +248,18 @@ interface TransferRequest {
|
|
|
248
248
|
asset?: AssetRef;
|
|
249
249
|
amount: bigint;
|
|
250
250
|
}
|
|
251
|
+
|
|
252
|
+
type TransferPayload = {
|
|
253
|
+
readonly vm: "evm";
|
|
254
|
+
readonly to: string;
|
|
255
|
+
readonly value: bigint;
|
|
256
|
+
readonly data: string;
|
|
257
|
+
} | {
|
|
258
|
+
readonly vm: "svm";
|
|
259
|
+
readonly recipient: string;
|
|
260
|
+
readonly amount: bigint;
|
|
261
|
+
readonly instructions?: ReadonlyArray<unknown>;
|
|
262
|
+
};
|
|
251
263
|
interface Transaction {
|
|
252
264
|
readonly vm: VmToken;
|
|
253
265
|
readonly status: TransactionStatus;
|
|
@@ -486,7 +498,7 @@ declare class Address {
|
|
|
486
498
|
buildTransaction(params: EvmTxBuildParams): EvmTransaction;
|
|
487
499
|
buildTransaction(params: SvmTxBuildParams): SvmTransaction;
|
|
488
500
|
|
|
489
|
-
|
|
501
|
+
buildTransferPayload(req: TransferRequest): TransferPayload;
|
|
490
502
|
|
|
491
503
|
signTransaction<T extends Transaction>(transaction: T): T;
|
|
492
504
|
|
|
@@ -799,4 +811,4 @@ declare class Workspace {
|
|
|
799
811
|
} | null;
|
|
800
812
|
}
|
|
801
813
|
|
|
802
|
-
export { type
|
|
814
|
+
export { type WativeErrorCode as $, Account as A, type SimulationResult as B, type ChainId as C, type SinkConfig as D, type EvmAddress as E, type Slug as F, type SvmAddress as G, SvmSigner as H, SvmTransaction as I, type SvmTxBuildParams as J, type TransactionReceipt as K, type LogLevel as L, type TransactionStateChange as M, Network as N, type OpenOptions as O, Provider as P, type TransactionStatus as Q, Record$1 as R, type Settling as S, type Transaction as T, type TransactionTracker as U, type TransferPayload as V, type TransferRequest as W, type VmToken as X, Wallet as Y, type WalletCollection as Z, WativeError as _, type AccountCollection as a, type WativeErrorOpts as a0, Workspace as a1, type WorkspaceConfig as a2, newMnemonic as a3, type SuiAddress as a4, type AccountOrgType as b, Address as c, Asset as d, type AssetBalance as e, type AssetCollection as f, type AssetId as g, type AssetInitObject as h, type AssetRef as i, type ChainVM as j, ConsoleSink as k, type ContainerState as l, type EvmRawTx as m, EvmSigner as n, EvmTransaction as o, type EvmTxBuildParams as p, EvmTxType as q, type LogRecord as r, type LogSink as s, Logger as t, type LoggerConfig as u, type NetworkCollection as v, type NetworkInit as w, type NetworkLike as x, type RecordInit as y, type RecordType as z };
|
|
@@ -248,6 +248,18 @@ interface TransferRequest {
|
|
|
248
248
|
asset?: AssetRef;
|
|
249
249
|
amount: bigint;
|
|
250
250
|
}
|
|
251
|
+
|
|
252
|
+
type TransferPayload = {
|
|
253
|
+
readonly vm: "evm";
|
|
254
|
+
readonly to: string;
|
|
255
|
+
readonly value: bigint;
|
|
256
|
+
readonly data: string;
|
|
257
|
+
} | {
|
|
258
|
+
readonly vm: "svm";
|
|
259
|
+
readonly recipient: string;
|
|
260
|
+
readonly amount: bigint;
|
|
261
|
+
readonly instructions?: ReadonlyArray<unknown>;
|
|
262
|
+
};
|
|
251
263
|
interface Transaction {
|
|
252
264
|
readonly vm: VmToken;
|
|
253
265
|
readonly status: TransactionStatus;
|
|
@@ -486,7 +498,7 @@ declare class Address {
|
|
|
486
498
|
buildTransaction(params: EvmTxBuildParams): EvmTransaction;
|
|
487
499
|
buildTransaction(params: SvmTxBuildParams): SvmTransaction;
|
|
488
500
|
|
|
489
|
-
|
|
501
|
+
buildTransferPayload(req: TransferRequest): TransferPayload;
|
|
490
502
|
|
|
491
503
|
signTransaction<T extends Transaction>(transaction: T): T;
|
|
492
504
|
|
|
@@ -799,4 +811,4 @@ declare class Workspace {
|
|
|
799
811
|
} | null;
|
|
800
812
|
}
|
|
801
813
|
|
|
802
|
-
export { type
|
|
814
|
+
export { type WativeErrorCode as $, Account as A, type SimulationResult as B, type ChainId as C, type SinkConfig as D, type EvmAddress as E, type Slug as F, type SvmAddress as G, SvmSigner as H, SvmTransaction as I, type SvmTxBuildParams as J, type TransactionReceipt as K, type LogLevel as L, type TransactionStateChange as M, Network as N, type OpenOptions as O, Provider as P, type TransactionStatus as Q, Record$1 as R, type Settling as S, type Transaction as T, type TransactionTracker as U, type TransferPayload as V, type TransferRequest as W, type VmToken as X, Wallet as Y, type WalletCollection as Z, WativeError as _, type AccountCollection as a, type WativeErrorOpts as a0, Workspace as a1, type WorkspaceConfig as a2, newMnemonic as a3, type SuiAddress as a4, type AccountOrgType as b, Address as c, Asset as d, type AssetBalance as e, type AssetCollection as f, type AssetId as g, type AssetInitObject as h, type AssetRef as i, type ChainVM as j, ConsoleSink as k, type ContainerState as l, type EvmRawTx as m, EvmSigner as n, EvmTransaction as o, type EvmTxBuildParams as p, EvmTxType as q, type LogRecord as r, type LogSink as s, Logger as t, type LoggerConfig as u, type NetworkCollection as v, type NetworkInit as w, type NetworkLike as x, type RecordInit as y, type RecordType as z };
|
|
@@ -48,10 +48,10 @@ class XvmDialect extends ChainDialect {
|
|
|
48
48
|
buildTransaction(ctx, params) {
|
|
49
49
|
return { vm: "xvm", from: String(ctx.publicKey), to: params.to, value: params.value ?? 0n, nonce: params.nonce ?? 0 };
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
if (req.asset && req.asset.address)
|
|
54
|
-
return
|
|
51
|
+
buildTransferPayload(ctx, req) {
|
|
52
|
+
const payload = { vm: "xvm", from: String(ctx.publicKey), to: req.to, amount: req.amount };
|
|
53
|
+
if (req.asset && req.asset.address) payload.token = req.asset.address;
|
|
54
|
+
return payload;
|
|
55
55
|
}
|
|
56
56
|
derive(seed, index) {
|
|
57
57
|
const h = toyHash(`${Buffer.from(seed).toString("hex")}:${index}`);
|
|
@@ -125,12 +125,12 @@ test("the custom dialect signs, builds a tx, and transfers via a keyless ctx", (
|
|
|
125
125
|
assert.strictEqual(tx.to, "xvm1recipient");
|
|
126
126
|
assert.strictEqual(tx.nonce, 7);
|
|
127
127
|
|
|
128
|
-
const native = dialect.
|
|
128
|
+
const native = dialect.buildTransferPayload(ctx, { to: "xvm1bob", amount: 500n });
|
|
129
129
|
assert.strictEqual(native.to, "xvm1bob");
|
|
130
130
|
assert.strictEqual(native.amount, 500n);
|
|
131
131
|
assert.strictEqual(native.token, undefined);
|
|
132
132
|
|
|
133
|
-
const token = dialect.
|
|
133
|
+
const token = dialect.buildTransferPayload(ctx, { to: "xvm1bob", asset: { address: "xtoken1" }, amount: 5n });
|
|
134
134
|
assert.strictEqual(token.token, "xtoken1");
|
|
135
135
|
});
|
|
136
136
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// 21 — Token-aware
|
|
1
|
+
// 21 — Token-aware buildTransferPayload(): one intent lowered per chain into the buildTransaction payload — native value, ERC-20 by address, SPL by mint, and by symbol. Payload only (does not send); amounts are raw base units.
|
|
2
2
|
|
|
3
3
|
const test = require("node:test");
|
|
4
4
|
const assert = require("node:assert");
|
|
@@ -24,22 +24,22 @@ async function twoWallets() {
|
|
|
24
24
|
return { ws, w0: acc.wallets[0], w1: acc.wallets[1] };
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
test("
|
|
27
|
+
test("buildTransferPayload() —native value on EVM and SVM (asset omitted)", async () => {
|
|
28
28
|
const { ws, w0, w1 } = await twoWallets();
|
|
29
29
|
|
|
30
|
-
const evmTx = w0.evm.
|
|
30
|
+
const evmTx = w0.evm.buildTransferPayload({ to: String(w1.evm.publicKey), amount: 1_000_000_000_000_000n });
|
|
31
31
|
assert.strictEqual(String(evmTx.to).toLowerCase(), String(w1.evm.publicKey).toLowerCase());
|
|
32
32
|
assert.strictEqual(evmTx.value, 1_000_000_000_000_000n);
|
|
33
33
|
|
|
34
|
-
const svmTx = w0.svm.
|
|
34
|
+
const svmTx = w0.svm.buildTransferPayload({ to: String(w1.svm.publicKey), amount: 5000n });
|
|
35
35
|
assert.ok(svmTx);
|
|
36
36
|
|
|
37
37
|
await ws.lock();
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
test("
|
|
40
|
+
test("buildTransferPayload() —EVM ERC-20 by contract address", async () => {
|
|
41
41
|
const { ws, w0, w1 } = await twoWallets();
|
|
42
|
-
const tx = w0.evm.
|
|
42
|
+
const tx = w0.evm.buildTransferPayload({ to: String(w1.evm.publicKey), asset: { address: USDC_EVM }, amount: 1_000_000n });
|
|
43
43
|
|
|
44
44
|
assert.strictEqual(String(tx.to).toLowerCase(), USDC_EVM.toLowerCase());
|
|
45
45
|
assert.strictEqual(tx.value, 0n);
|
|
@@ -49,9 +49,9 @@ test("transfer() — EVM ERC-20 by contract address", async () => {
|
|
|
49
49
|
await ws.lock();
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
test("
|
|
52
|
+
test("buildTransferPayload() —SVM SPL by mint prepends an idempotent recipient-ATA create", async () => {
|
|
53
53
|
const { ws, w0, w1 } = await twoWallets();
|
|
54
|
-
const tx = w0.svm.
|
|
54
|
+
const tx = w0.svm.buildTransferPayload({ to: String(w1.svm.publicKey), asset: { address: USDC_SVM_MINT }, amount: 1_000_000n });
|
|
55
55
|
|
|
56
56
|
assert.ok(Array.isArray(tx.instructions));
|
|
57
57
|
assert.strictEqual(tx.instructions.length, 2);
|
|
@@ -59,23 +59,23 @@ test("transfer() — SVM SPL by mint prepends an idempotent recipient-ATA create
|
|
|
59
59
|
await ws.lock();
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
test("
|
|
62
|
+
test("buildTransferPayload() —by token symbol resolves to native vs token", async () => {
|
|
63
63
|
const { ws, w0, w1 } = await twoWallets();
|
|
64
64
|
|
|
65
|
-
const usdc = w0.evm.
|
|
65
|
+
const usdc = w0.evm.buildTransferPayload({ to: String(w1.evm.publicKey), asset: { symbol: "USDC" }, amount: 1_000_000n });
|
|
66
66
|
assert.strictEqual(String(usdc.data).slice(0, 10), "0xa9059cbb");
|
|
67
67
|
|
|
68
|
-
const eth = w0.evm.
|
|
68
|
+
const eth = w0.evm.buildTransferPayload({ to: String(w1.evm.publicKey), asset: { symbol: "ETH" }, amount: 777n });
|
|
69
69
|
assert.strictEqual(eth.value, 777n);
|
|
70
70
|
|
|
71
71
|
await ws.lock();
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
test("
|
|
74
|
+
test("buildTransferPayload() —an out-of-range amount is a PARAMETER_ERROR", async () => {
|
|
75
75
|
const { ws, w0, w1 } = await twoWallets();
|
|
76
76
|
let code;
|
|
77
77
|
try {
|
|
78
|
-
w0.evm.
|
|
78
|
+
w0.evm.buildTransferPayload({ to: String(w1.evm.publicKey), asset: { address: USDC_EVM }, amount: -1n });
|
|
79
79
|
} catch (e) {
|
|
80
80
|
code = e.code;
|
|
81
81
|
}
|
package/examples/README.md
CHANGED
|
@@ -50,8 +50,8 @@ All tests work fully offline — no RPC calls, no real networks. Each test creat
|
|
|
50
50
|
| [17-locked-state.test.cjs](17-locked-state.test.cjs) | What locking enforces — which operations refuse and with which error code, that a locked account holds no mnemonic in the clear, and that unlocking restores identical behaviour. |
|
|
51
51
|
| [18-envelope-v3.test.cjs](18-envelope-v3.test.cjs) | `HybridProviderV3` — writing a workspace that derives one key for the whole workspace instead of one per stored secret, reopening it, and confirming a wrong password is still refused. |
|
|
52
52
|
| [19-simple-provider.test.cjs](19-simple-provider.test.cjs) | The short way to write a storage backend — extend `ContainerProvider` and implement six methods that move bytes. Runs a whole workspace on a `Map`, signs from a derived address, reopens it, and checks that nothing readable reaches the store. |
|
|
53
|
-
| [20-custom-chain-dialect.test.cjs](20-custom-chain-dialect.test.cjs) | Adding a whole new blockchain — subclass `ChainDialect` and `registerDialect` its vm, the same shape as extending `Provider`. A fictional `xvm` chain becomes a first-class network (and an unregistered vm is still refused), its dialect signs / builds a transaction /
|
|
54
|
-
| [21-token-transfer.test.cjs](21-token-transfer.test.cjs) | `address.
|
|
53
|
+
| [20-custom-chain-dialect.test.cjs](20-custom-chain-dialect.test.cjs) | Adding a whole new blockchain — subclass `ChainDialect` and `registerDialect` its vm, the same shape as extending `Provider`. A fictional `xvm` chain becomes a first-class network (and an unregistered vm is still refused), its dialect signs / builds a transaction / builds transfer payloads / derives through the keyless `ChainCtx`, and `XvmSigner` names the per-chain signer just as `EvmSigner` / `SvmSigner` do. |
|
|
54
|
+
| [21-token-transfer.test.cjs](21-token-transfer.test.cjs) | `address.buildTransferPayload({ to, asset, amount })` — one intent lowered per chain into the payload for `buildTransaction`: native value, EVM ERC-20 by contract address, SVM SPL by mint (with an idempotent recipient-ATA create), and by token `symbol`. Payload only (does not send); `amount` is raw base units. |
|
|
55
55
|
|
|
56
56
|
## Adapting for your project
|
|
57
57
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wative-core",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1",
|
|
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",
|