@kynesyslabs/demosdk 2.12.2 → 3.1.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/build/bridge/nativeBridgeTypes.d.ts +4 -3
- package/build/bridge/nativeBridgeTypes.js.map +1 -1
- package/build/d402/client/types.d.ts +6 -3
- package/build/d402/server/D402Server.d.ts +25 -0
- package/build/d402/server/D402Server.js +63 -2
- package/build/d402/server/D402Server.js.map +1 -1
- package/build/d402/server/middleware.d.ts +7 -4
- package/build/d402/server/middleware.js.map +1 -1
- package/build/d402/server/types.d.ts +15 -7
- package/build/denomination/conversion.test.js +1 -1
- package/build/denomination/conversion.test.js.map +1 -1
- package/build/denomination/index.d.ts +3 -0
- package/build/denomination/index.js +6 -0
- package/build/denomination/index.js.map +1 -1
- package/build/denomination/networkInfo.d.ts +69 -0
- package/build/denomination/networkInfo.js +38 -0
- package/build/denomination/networkInfo.js.map +1 -0
- package/build/denomination/networkInfo.test.d.ts +1 -0
- package/build/denomination/networkInfo.test.js +28 -0
- package/build/denomination/networkInfo.test.js.map +1 -0
- package/build/denomination/roundTripHash.test.d.ts +1 -0
- package/build/denomination/roundTripHash.test.js +227 -0
- package/build/denomination/roundTripHash.test.js.map +1 -0
- package/build/denomination/serializerGate.d.ts +46 -0
- package/build/denomination/serializerGate.js +283 -0
- package/build/denomination/serializerGate.js.map +1 -0
- package/build/denomination/serializerGate.test.d.ts +1 -0
- package/build/denomination/serializerGate.test.js +245 -0
- package/build/denomination/serializerGate.test.js.map +1 -0
- package/build/escrow/EscrowTransaction.d.ts +36 -5
- package/build/escrow/EscrowTransaction.js +91 -10
- package/build/escrow/EscrowTransaction.js.map +1 -1
- package/build/ipfs/IPFSOperations.d.ts +37 -10
- package/build/ipfs/IPFSOperations.js +38 -8
- package/build/ipfs/IPFSOperations.js.map +1 -1
- package/build/storage/StorageProgram.d.ts +16 -8
- package/build/storage/StorageProgram.js +16 -8
- package/build/storage/StorageProgram.js.map +1 -1
- package/build/tlsnotary/TLSNotaryService.d.ts +19 -8
- package/build/tlsnotary/TLSNotaryService.js +22 -7
- package/build/tlsnotary/TLSNotaryService.js.map +1 -1
- package/build/tlsnotary/helpers.d.ts +11 -5
- package/build/tlsnotary/helpers.js +17 -5
- package/build/tlsnotary/helpers.js.map +1 -1
- package/build/types/blockchain/CustomCharges.d.ts +28 -16
- package/build/types/blockchain/CustomCharges.js +15 -5
- package/build/types/blockchain/CustomCharges.js.map +1 -1
- package/build/types/blockchain/GCREdit.d.ts +26 -2
- package/build/types/blockchain/Transaction.d.ts +14 -1
- package/build/types/blockchain/Transaction.js.map +1 -1
- package/build/types/blockchain/TransactionSubtypes/D402PaymentTransaction.d.ts +8 -3
- package/build/types/blockchain/TransactionSubtypes/StorageProgramTransaction.d.ts +6 -5
- package/build/types/blockchain/TransactionSubtypes/StorageProgramTransaction.js +15 -3
- package/build/types/blockchain/TransactionSubtypes/StorageProgramTransaction.js.map +1 -1
- package/build/types/blockchain/TxFee.d.ts +16 -3
- package/build/types/blockchain/address.d.ts +23 -0
- package/build/types/blockchain/rawTransaction.d.ts +13 -4
- package/build/types/blockchain/statusNative.d.ts +9 -1
- package/build/types/bridge/bridgeTradePayload.d.ts +1 -1
- package/build/types/gls/StateChange.d.ts +29 -3
- package/build/types/native/INativePayload.d.ts +6 -1
- package/build/wallet/Wallet.d.ts +27 -1
- package/build/wallet/Wallet.js +30 -17
- package/build/wallet/Wallet.js.map +1 -1
- package/build/websdk/DemosTransactions.d.ts +30 -4
- package/build/websdk/DemosTransactions.js +88 -9
- package/build/websdk/DemosTransactions.js.map +1 -1
- package/build/websdk/GCRGeneration.d.ts +10 -2
- package/build/websdk/GCRGeneration.js +30 -14
- package/build/websdk/GCRGeneration.js.map +1 -1
- package/build/websdk/demosclass.d.ts +152 -23
- package/build/websdk/demosclass.js +305 -38
- package/build/websdk/demosclass.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { describe, test, expect } from "@jest/globals";
|
|
2
|
+
import { serializeTransactionContent } from "./serializerGate.js";
|
|
3
|
+
// REVIEW: P4 commit 2 — load-bearing wire boundary. Tests assert byte
|
|
4
|
+
// identity for the pre-fork branch (must equal legacy `JSON.stringify`)
|
|
5
|
+
// and the canonical post-fork shape (`amount`, `transaction_fee.*`, and
|
|
6
|
+
// targeted `gcr_edits[].amount` carriers as OS strings; key order
|
|
7
|
+
// preserved).
|
|
8
|
+
/**
|
|
9
|
+
* Build a `TransactionContent` fixture in the canonical key order, with
|
|
10
|
+
* a mix of `gcr_edits` entries to exercise the per-variant transformer.
|
|
11
|
+
*/
|
|
12
|
+
function buildFixture() {
|
|
13
|
+
const gcr_edits = [
|
|
14
|
+
{
|
|
15
|
+
type: "balance",
|
|
16
|
+
isRollback: false,
|
|
17
|
+
operation: "remove",
|
|
18
|
+
account: "0xsender",
|
|
19
|
+
amount: 100, // legacy DEM number
|
|
20
|
+
txhash: "",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: "nonce",
|
|
24
|
+
isRollback: false,
|
|
25
|
+
operation: "add",
|
|
26
|
+
account: "0xsender",
|
|
27
|
+
amount: 1,
|
|
28
|
+
txhash: "",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: "balance",
|
|
32
|
+
isRollback: false,
|
|
33
|
+
operation: "add",
|
|
34
|
+
account: "0xreceiver",
|
|
35
|
+
amount: 100,
|
|
36
|
+
txhash: "",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: "escrow",
|
|
40
|
+
operation: "deposit",
|
|
41
|
+
account: "0xescrow",
|
|
42
|
+
data: {
|
|
43
|
+
sender: "0xsender",
|
|
44
|
+
platform: "twitter",
|
|
45
|
+
username: "@bob",
|
|
46
|
+
amount: 100, // legacy DEM number — should become OS string post-fork
|
|
47
|
+
expiryDays: 30,
|
|
48
|
+
},
|
|
49
|
+
txhash: "",
|
|
50
|
+
isRollback: false,
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
const content = {
|
|
54
|
+
type: "native",
|
|
55
|
+
from: "0xsender",
|
|
56
|
+
to: "0xreceiver",
|
|
57
|
+
amount: 100, // legacy DEM
|
|
58
|
+
data: [
|
|
59
|
+
"native",
|
|
60
|
+
{
|
|
61
|
+
nativeOperation: "send",
|
|
62
|
+
args: ["0xreceiver", 100],
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
nonce: 1,
|
|
66
|
+
timestamp: 1700000000000,
|
|
67
|
+
transaction_fee: {
|
|
68
|
+
network_fee: 1,
|
|
69
|
+
rpc_fee: 0,
|
|
70
|
+
additional_fee: 0,
|
|
71
|
+
},
|
|
72
|
+
from_ed25519_address: "0xsender",
|
|
73
|
+
gcr_edits,
|
|
74
|
+
};
|
|
75
|
+
return content;
|
|
76
|
+
}
|
|
77
|
+
describe("serializerGate — pre-fork branch", () => {
|
|
78
|
+
test("output is byte-identical to legacy JSON.stringify for current SDK content", () => {
|
|
79
|
+
const content = buildFixture();
|
|
80
|
+
const expected = JSON.stringify(content);
|
|
81
|
+
expect(serializeTransactionContent(content, false)).toBe(expected);
|
|
82
|
+
});
|
|
83
|
+
test("normalises stray bigint amount back to legacy DEM number", () => {
|
|
84
|
+
const content = buildFixture();
|
|
85
|
+
// Simulate an internal bigint OS amount leaking into content.
|
|
86
|
+
// 100 DEM = 100_000_000_000n OS.
|
|
87
|
+
content.amount = 100000000000n;
|
|
88
|
+
const out = serializeTransactionContent(content, false);
|
|
89
|
+
const parsed = JSON.parse(out);
|
|
90
|
+
expect(parsed.amount).toBe(100);
|
|
91
|
+
});
|
|
92
|
+
test("normalises stray OS-string amount back to DEM number", () => {
|
|
93
|
+
const content = buildFixture();
|
|
94
|
+
content.amount = "100000000000";
|
|
95
|
+
const out = serializeTransactionContent(content, false);
|
|
96
|
+
const parsed = JSON.parse(out);
|
|
97
|
+
expect(parsed.amount).toBe(100);
|
|
98
|
+
});
|
|
99
|
+
test("normalises bigint balance edit back to DEM number", () => {
|
|
100
|
+
const content = buildFixture();
|
|
101
|
+
content.gcr_edits[0].amount = 100000000000n;
|
|
102
|
+
const out = serializeTransactionContent(content, false);
|
|
103
|
+
const parsed = JSON.parse(out);
|
|
104
|
+
expect(parsed.gcr_edits[0].amount).toBe(100);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe("serializerGate — post-fork branch", () => {
|
|
108
|
+
test("amount becomes OS string", () => {
|
|
109
|
+
const content = buildFixture();
|
|
110
|
+
const out = serializeTransactionContent(content, true);
|
|
111
|
+
const parsed = JSON.parse(out);
|
|
112
|
+
expect(parsed.amount).toBe("100000000000");
|
|
113
|
+
});
|
|
114
|
+
test("transaction_fee fields all become OS strings", () => {
|
|
115
|
+
const content = buildFixture();
|
|
116
|
+
const out = serializeTransactionContent(content, true);
|
|
117
|
+
const parsed = JSON.parse(out);
|
|
118
|
+
expect(parsed.transaction_fee.network_fee).toBe("1000000000");
|
|
119
|
+
expect(parsed.transaction_fee.rpc_fee).toBe("0");
|
|
120
|
+
expect(parsed.transaction_fee.additional_fee).toBe("0");
|
|
121
|
+
});
|
|
122
|
+
test("gcr_edits balance amounts become OS strings; nonce stays a number", () => {
|
|
123
|
+
const content = buildFixture();
|
|
124
|
+
const out = serializeTransactionContent(content, true);
|
|
125
|
+
const parsed = JSON.parse(out);
|
|
126
|
+
expect(parsed.gcr_edits[0].amount).toBe("100000000000");
|
|
127
|
+
expect(parsed.gcr_edits[1].amount).toBe(1); // nonce — counter, untouched
|
|
128
|
+
expect(parsed.gcr_edits[2].amount).toBe("100000000000");
|
|
129
|
+
});
|
|
130
|
+
test("escrow nested amount becomes OS string", () => {
|
|
131
|
+
const content = buildFixture();
|
|
132
|
+
const out = serializeTransactionContent(content, true);
|
|
133
|
+
const parsed = JSON.parse(out);
|
|
134
|
+
expect(parsed.gcr_edits[3].data.amount).toBe("100000000000");
|
|
135
|
+
});
|
|
136
|
+
test("post-fork output preserves canonical top-level key order", () => {
|
|
137
|
+
const content = buildFixture();
|
|
138
|
+
const out = serializeTransactionContent(content, true);
|
|
139
|
+
const parsed = JSON.parse(out);
|
|
140
|
+
// Canonical order from SPEC_P4 §3.5.
|
|
141
|
+
expect(Object.keys(parsed)).toEqual([
|
|
142
|
+
"type",
|
|
143
|
+
"from",
|
|
144
|
+
"to",
|
|
145
|
+
"amount",
|
|
146
|
+
"data",
|
|
147
|
+
"nonce",
|
|
148
|
+
"timestamp",
|
|
149
|
+
"transaction_fee",
|
|
150
|
+
"from_ed25519_address",
|
|
151
|
+
"gcr_edits",
|
|
152
|
+
]);
|
|
153
|
+
});
|
|
154
|
+
test("post-fork output preserves transaction_fee key order", () => {
|
|
155
|
+
const content = buildFixture();
|
|
156
|
+
const out = serializeTransactionContent(content, true);
|
|
157
|
+
const parsed = JSON.parse(out);
|
|
158
|
+
expect(Object.keys(parsed.transaction_fee)).toEqual([
|
|
159
|
+
"network_fee",
|
|
160
|
+
"rpc_fee",
|
|
161
|
+
"additional_fee",
|
|
162
|
+
]);
|
|
163
|
+
});
|
|
164
|
+
test("non-canonical OS string is normalised", () => {
|
|
165
|
+
const content = buildFixture();
|
|
166
|
+
// "00100" must become "100" after re-emit.
|
|
167
|
+
content.amount = "00100";
|
|
168
|
+
const out = serializeTransactionContent(content, true);
|
|
169
|
+
const parsed = JSON.parse(out);
|
|
170
|
+
expect(parsed.amount).toBe("100");
|
|
171
|
+
});
|
|
172
|
+
test("bigint amount round-trips through the wire", () => {
|
|
173
|
+
const content = buildFixture();
|
|
174
|
+
content.amount = 1500000000n;
|
|
175
|
+
const out = serializeTransactionContent(content, true);
|
|
176
|
+
const parsed = JSON.parse(out);
|
|
177
|
+
expect(parsed.amount).toBe("1500000000");
|
|
178
|
+
});
|
|
179
|
+
test("sub-DEM precision preserved via OS string", () => {
|
|
180
|
+
const content = buildFixture();
|
|
181
|
+
// 0.000000001 DEM = 1n OS.
|
|
182
|
+
content.amount = 1n;
|
|
183
|
+
const out = serializeTransactionContent(content, true);
|
|
184
|
+
const parsed = JSON.parse(out);
|
|
185
|
+
expect(parsed.amount).toBe("1");
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
describe("serializerGate — input invariance", () => {
|
|
189
|
+
test("does not mutate the input content object", () => {
|
|
190
|
+
const content = buildFixture();
|
|
191
|
+
const before = JSON.stringify(content);
|
|
192
|
+
serializeTransactionContent(content, true);
|
|
193
|
+
expect(JSON.stringify(content)).toBe(before);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
describe("serializerGate — transaction_fee key order (myc#19)", () => {
|
|
197
|
+
test("post-fork preserves non-canonical fee insertion order", () => {
|
|
198
|
+
const content = buildFixture();
|
|
199
|
+
// Construct fee with `additional_fee` first to break the old
|
|
200
|
+
// hard-coded literal order.
|
|
201
|
+
content.transaction_fee = {
|
|
202
|
+
additional_fee: 0,
|
|
203
|
+
rpc_fee: 0,
|
|
204
|
+
network_fee: 1,
|
|
205
|
+
};
|
|
206
|
+
const out = serializeTransactionContent(content, true);
|
|
207
|
+
const parsed = JSON.parse(out);
|
|
208
|
+
expect(Object.keys(parsed.transaction_fee)).toEqual([
|
|
209
|
+
"additional_fee",
|
|
210
|
+
"rpc_fee",
|
|
211
|
+
"network_fee",
|
|
212
|
+
]);
|
|
213
|
+
});
|
|
214
|
+
test("pre-fork preserves non-canonical fee insertion order", () => {
|
|
215
|
+
const content = buildFixture();
|
|
216
|
+
content.transaction_fee = {
|
|
217
|
+
additional_fee: 0,
|
|
218
|
+
rpc_fee: 0,
|
|
219
|
+
network_fee: 1,
|
|
220
|
+
};
|
|
221
|
+
const out = serializeTransactionContent(content, false);
|
|
222
|
+
const parsed = JSON.parse(out);
|
|
223
|
+
expect(Object.keys(parsed.transaction_fee)).toEqual([
|
|
224
|
+
"additional_fee",
|
|
225
|
+
"rpc_fee",
|
|
226
|
+
"network_fee",
|
|
227
|
+
]);
|
|
228
|
+
});
|
|
229
|
+
test("post-fork passes through unknown extra fee fields verbatim", () => {
|
|
230
|
+
const content = buildFixture();
|
|
231
|
+
content.transaction_fee = {
|
|
232
|
+
network_fee: 1,
|
|
233
|
+
rpc_fee: 0,
|
|
234
|
+
additional_fee: 0,
|
|
235
|
+
// Future extension field the SDK doesn't know about — must
|
|
236
|
+
// not be dropped (consensus would diverge if the node knows
|
|
237
|
+
// it and we strip it).
|
|
238
|
+
future_field: "abc",
|
|
239
|
+
};
|
|
240
|
+
const out = serializeTransactionContent(content, true);
|
|
241
|
+
const parsed = JSON.parse(out);
|
|
242
|
+
expect(parsed.transaction_fee.future_field).toBe("abc");
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
//# sourceMappingURL=serializerGate.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializerGate.test.js","sourceRoot":"","sources":["../../../src/denomination/serializerGate.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAA;AAI9D,sEAAsE;AACtE,wEAAwE;AACxE,wEAAwE;AACxE,kEAAkE;AAClE,cAAc;AAEd;;;GAGG;AACH,SAAS,YAAY;IACjB,MAAM,SAAS,GAAc;QACzB;YACI,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,KAAK;YACjB,SAAS,EAAE,QAAQ;YACnB,OAAO,EAAE,UAAU;YACnB,MAAM,EAAE,GAAG,EAAE,oBAAoB;YACjC,MAAM,EAAE,EAAE;SACb;QACD;YACI,IAAI,EAAE,OAAO;YACb,UAAU,EAAE,KAAK;YACjB,SAAS,EAAE,KAAK;YAChB,OAAO,EAAE,UAAU;YACnB,MAAM,EAAE,CAAC;YACT,MAAM,EAAE,EAAE;SACb;QACD;YACI,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,KAAK;YACjB,SAAS,EAAE,KAAK;YAChB,OAAO,EAAE,YAAY;YACrB,MAAM,EAAE,GAAG;YACX,MAAM,EAA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EAAE,CAAC;SACV,CAAA;QACR,MAAM,GAAG,GAAG,2BAA2B,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QACvD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC9B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC;YAChD,gBAAgB;YAChB,SAAS;YACT,aAAa;SAChB,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,4DAA4D,EAAE,GAAG,EAAE;QACpE,MAAM,OAAO,GAAG,YAAY,EAAE,CAAA;QAC9B,OAAO,CAAC,eAAe,GAAG;YACtB,WAAW,EAAE,CAAC;YACd,OAAO,EAAE,CAAC;YACV,cAAc,EAAE,CAAC;YACjB,2DAA2D;YAC3D,4DAA4D;YAC5D,uBAAuB;YACvB,YAAY,EAAE,KAAK;SACf,CAAA;QACR,MAAM,GAAG,GAAG,2BAA2B,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACtD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC9B,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC3D,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
|
@@ -15,31 +15,62 @@ export declare class EscrowTransaction {
|
|
|
15
15
|
*/
|
|
16
16
|
static getEscrowAddress(platform: string, username: string): string;
|
|
17
17
|
/**
|
|
18
|
-
* Creates a transaction to send DEM to a social identity escrow
|
|
18
|
+
* Creates a transaction to send DEM to a social identity escrow.
|
|
19
|
+
*
|
|
20
|
+
* P4 dual-input:
|
|
21
|
+
* - `bigint` (preferred, post-v3): OS amount.
|
|
22
|
+
* - `number` (deprecated, v2 callers): DEM amount, auto-converted.
|
|
23
|
+
*
|
|
24
|
+
* Internal carrier in `tx.content.amount` and `gcr_edits[].amount`
|
|
25
|
+
* is bigint OS; the serializerGate (called from `demos.sign`)
|
|
26
|
+
* picks the wire shape per fork status. Sub-DEM precision against
|
|
27
|
+
* a pre-fork node throws `SubDemPrecisionError`.
|
|
19
28
|
*
|
|
20
29
|
* @example
|
|
21
30
|
* ```typescript
|
|
31
|
+
* import { denomination } from "@kynesyslabs/demosdk"
|
|
22
32
|
* const tx = await EscrowTransaction.sendToIdentity(
|
|
23
33
|
* demos,
|
|
24
34
|
* "twitter",
|
|
25
35
|
* "@bob",
|
|
26
|
-
* 100,
|
|
36
|
+
* denomination.demToOs(100), // 100 DEM
|
|
27
37
|
* { expiryDays: 30, message: "Welcome to Demos!" }
|
|
28
38
|
* )
|
|
29
|
-
* await demos.
|
|
39
|
+
* await demos.confirm(tx)
|
|
30
40
|
* ```
|
|
31
41
|
*
|
|
32
42
|
* @param demos - Demos SDK instance (must have keypair set)
|
|
33
43
|
* @param platform - Social platform ("twitter", "github", "telegram")
|
|
34
44
|
* @param username - Username on that platform
|
|
35
|
-
* @param amount -
|
|
45
|
+
* @param amount - DEM `number` (legacy) or OS `bigint` (preferred).
|
|
36
46
|
* @param options - Optional parameters
|
|
37
47
|
* @returns Signed transaction ready to submit
|
|
38
48
|
*/
|
|
39
|
-
static sendToIdentity(demos: Demos, platform: "twitter" | "github" | "telegram", username: string, amount: number, options?: {
|
|
49
|
+
static sendToIdentity(demos: Demos, platform: "twitter" | "github" | "telegram", username: string, amount: number | bigint, options?: {
|
|
40
50
|
expiryDays?: number;
|
|
41
51
|
message?: string;
|
|
42
52
|
}): Promise<Transaction>;
|
|
53
|
+
/**
|
|
54
|
+
* Normalise a public-API amount input (`number` legacy DEM or
|
|
55
|
+
* `bigint` OS) into both forms. Used at every boundary that needs
|
|
56
|
+
* dual-shape support during the pre-/post-fork rollout.
|
|
57
|
+
*
|
|
58
|
+
* - `number` input: must be a non-negative integer DEM amount;
|
|
59
|
+
* converted to OS via `OS_PER_DEM`. Fractional DEM `number` is
|
|
60
|
+
* rejected — silently flooring (the previous behaviour) discarded
|
|
61
|
+
* up to ~10^9 OS per call. Callers who need sub-DEM precision
|
|
62
|
+
* must pass a `bigint` OS amount (e.g. `denomination.demToOs("1.5")`).
|
|
63
|
+
* - `bigint` input: treated as OS; DEM form is the integer division
|
|
64
|
+
* `amountOs / OS_PER_DEM`. The pre-fork sub-DEM precision rejection
|
|
65
|
+
* lives in `Demos._assertAmountAcceptableOnTargetNode` (called by
|
|
66
|
+
* `sendToIdentity` before this helper runs).
|
|
67
|
+
*
|
|
68
|
+
* @internal Exposed only to keep the migration paths discoverable.
|
|
69
|
+
*/
|
|
70
|
+
static normalizeAmountInput(amount: number | bigint): {
|
|
71
|
+
amountDem: number;
|
|
72
|
+
amountOs: bigint;
|
|
73
|
+
};
|
|
43
74
|
/**
|
|
44
75
|
* Creates a transaction to claim escrowed funds
|
|
45
76
|
*
|
|
@@ -11,6 +11,7 @@ KyneSys Labs: https://www.kynesys.xyz/
|
|
|
11
11
|
import { Hashing } from "../encryption/Hashing.js";
|
|
12
12
|
import { uint8ArrayToHex } from "../encryption/unifiedCrypto.js";
|
|
13
13
|
import * as skeletons from "../websdk/utils/skeletons.js";
|
|
14
|
+
import { OS_PER_DEM } from "../denomination/index.js";
|
|
14
15
|
/**
|
|
15
16
|
* High-level API for creating escrow transactions
|
|
16
17
|
* Enables trustless sending of DEM to unclaimed social identities
|
|
@@ -31,28 +32,51 @@ export class EscrowTransaction {
|
|
|
31
32
|
return Hashing.sha3_256(identity);
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
|
-
* Creates a transaction to send DEM to a social identity escrow
|
|
35
|
+
* Creates a transaction to send DEM to a social identity escrow.
|
|
36
|
+
*
|
|
37
|
+
* P4 dual-input:
|
|
38
|
+
* - `bigint` (preferred, post-v3): OS amount.
|
|
39
|
+
* - `number` (deprecated, v2 callers): DEM amount, auto-converted.
|
|
40
|
+
*
|
|
41
|
+
* Internal carrier in `tx.content.amount` and `gcr_edits[].amount`
|
|
42
|
+
* is bigint OS; the serializerGate (called from `demos.sign`)
|
|
43
|
+
* picks the wire shape per fork status. Sub-DEM precision against
|
|
44
|
+
* a pre-fork node throws `SubDemPrecisionError`.
|
|
35
45
|
*
|
|
36
46
|
* @example
|
|
37
47
|
* ```typescript
|
|
48
|
+
* import { denomination } from "@kynesyslabs/demosdk"
|
|
38
49
|
* const tx = await EscrowTransaction.sendToIdentity(
|
|
39
50
|
* demos,
|
|
40
51
|
* "twitter",
|
|
41
52
|
* "@bob",
|
|
42
|
-
* 100,
|
|
53
|
+
* denomination.demToOs(100), // 100 DEM
|
|
43
54
|
* { expiryDays: 30, message: "Welcome to Demos!" }
|
|
44
55
|
* )
|
|
45
|
-
* await demos.
|
|
56
|
+
* await demos.confirm(tx)
|
|
46
57
|
* ```
|
|
47
58
|
*
|
|
48
59
|
* @param demos - Demos SDK instance (must have keypair set)
|
|
49
60
|
* @param platform - Social platform ("twitter", "github", "telegram")
|
|
50
61
|
* @param username - Username on that platform
|
|
51
|
-
* @param amount -
|
|
62
|
+
* @param amount - DEM `number` (legacy) or OS `bigint` (preferred).
|
|
52
63
|
* @param options - Optional parameters
|
|
53
64
|
* @returns Signed transaction ready to submit
|
|
54
65
|
*/
|
|
55
66
|
static async sendToIdentity(demos, platform, username, amount, options) {
|
|
67
|
+
// P4 commit 3: bigint OS is the canonical internal carrier; the
|
|
68
|
+
// serializerGate (run via demos.sign) emits the right wire shape
|
|
69
|
+
// per the connected node's fork status.
|
|
70
|
+
const { amountOs } = EscrowTransaction.normalizeAmountInput(amount);
|
|
71
|
+
// Sub-DEM precision guard — runs before tx construction so the
|
|
72
|
+
// caller never produces a tx that a pre-fork node will silently
|
|
73
|
+
// truncate. Calls into the cached `getNetworkInfo` fork status.
|
|
74
|
+
// The helper is `private` on Demos but reachable at runtime;
|
|
75
|
+
// cast through `any` to bypass the access modifier (escrow is
|
|
76
|
+
// package-internal — the alternative is to widen Demos's
|
|
77
|
+
// public surface, which we don't want).
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
await demos._assertAmountAcceptableOnTargetNode(amountOs);
|
|
56
80
|
// Get sender address from demos instance
|
|
57
81
|
const { publicKey } = await demos.crypto.getIdentity("ed25519");
|
|
58
82
|
const sender = uint8ArrayToHex(publicKey);
|
|
@@ -62,14 +86,25 @@ export class EscrowTransaction {
|
|
|
62
86
|
const nonce = await demos.getAddressNonce(sender);
|
|
63
87
|
// Create empty transaction
|
|
64
88
|
let tx = structuredClone(skeletons.transaction);
|
|
65
|
-
// Build GCREdits
|
|
89
|
+
// Build GCREdits. NOTE: `demos.sign()` calls `GCRGeneration.generate`
|
|
90
|
+
// which currently overwrites `gcr_edits` with edits derived from
|
|
91
|
+
// the tx content; the inline edits here are dead code today
|
|
92
|
+
// (flagged in SPEC_P4 §2.1). Kept type-correct so they still
|
|
93
|
+
// match the (now-widened) `GCREditBalance.amount` type if/when
|
|
94
|
+
// the dead-code path is wired up.
|
|
95
|
+
//
|
|
96
|
+
// P4 commit 3: edits carry bigint OS internally. The
|
|
97
|
+
// serializerGate normalises them to the right wire shape per
|
|
98
|
+
// fork status. The `GCREditBalance.amount` static type is
|
|
99
|
+
// `number | string`; bigints are passed through `unknown` to
|
|
100
|
+
// satisfy TS — the runtime serializer handles all three shapes.
|
|
66
101
|
const gcrEdits = [
|
|
67
102
|
// 1. Deduct from sender's balance
|
|
68
103
|
{
|
|
69
104
|
type: "balance",
|
|
70
105
|
operation: "remove",
|
|
71
106
|
account: sender,
|
|
72
|
-
amount:
|
|
107
|
+
amount: amountOs,
|
|
73
108
|
txhash: "",
|
|
74
109
|
isRollback: false,
|
|
75
110
|
},
|
|
@@ -82,7 +117,7 @@ export class EscrowTransaction {
|
|
|
82
117
|
sender,
|
|
83
118
|
platform,
|
|
84
119
|
username,
|
|
85
|
-
amount:
|
|
120
|
+
amount: amountOs,
|
|
86
121
|
expiryDays: options?.expiryDays || 30,
|
|
87
122
|
message: options?.message,
|
|
88
123
|
},
|
|
@@ -90,11 +125,13 @@ export class EscrowTransaction {
|
|
|
90
125
|
isRollback: false,
|
|
91
126
|
},
|
|
92
127
|
];
|
|
93
|
-
// Fill transaction content
|
|
128
|
+
// Fill transaction content. Internal carrier is bigint OS; the
|
|
129
|
+
// serializerGate emits the right wire shape (DEM number pre-fork,
|
|
130
|
+
// OS string post-fork) when `demos.sign` hashes.
|
|
94
131
|
tx.content.from = sender;
|
|
95
132
|
tx.content.to = escrowAddress;
|
|
96
133
|
tx.content.nonce = nonce + 1;
|
|
97
|
-
tx.content.amount =
|
|
134
|
+
tx.content.amount = amountOs;
|
|
98
135
|
tx.content.type = "escrow";
|
|
99
136
|
tx.content.timestamp = Date.now();
|
|
100
137
|
tx.content.gcr_edits = gcrEdits;
|
|
@@ -103,13 +140,57 @@ export class EscrowTransaction {
|
|
|
103
140
|
{
|
|
104
141
|
platform,
|
|
105
142
|
username,
|
|
106
|
-
amount
|
|
143
|
+
// The escrow payload's `amount` is a free-form string here;
|
|
144
|
+
// emit canonical OS for forward compatibility with the
|
|
145
|
+
// post-fork node's escrow handler. Pre-fork node tolerates
|
|
146
|
+
// arbitrary strings on this nested field.
|
|
147
|
+
amount: amountOs.toString(),
|
|
107
148
|
operation: "deposit",
|
|
108
149
|
},
|
|
109
150
|
];
|
|
110
151
|
// Sign transaction
|
|
111
152
|
return await demos.sign(tx);
|
|
112
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Normalise a public-API amount input (`number` legacy DEM or
|
|
156
|
+
* `bigint` OS) into both forms. Used at every boundary that needs
|
|
157
|
+
* dual-shape support during the pre-/post-fork rollout.
|
|
158
|
+
*
|
|
159
|
+
* - `number` input: must be a non-negative integer DEM amount;
|
|
160
|
+
* converted to OS via `OS_PER_DEM`. Fractional DEM `number` is
|
|
161
|
+
* rejected — silently flooring (the previous behaviour) discarded
|
|
162
|
+
* up to ~10^9 OS per call. Callers who need sub-DEM precision
|
|
163
|
+
* must pass a `bigint` OS amount (e.g. `denomination.demToOs("1.5")`).
|
|
164
|
+
* - `bigint` input: treated as OS; DEM form is the integer division
|
|
165
|
+
* `amountOs / OS_PER_DEM`. The pre-fork sub-DEM precision rejection
|
|
166
|
+
* lives in `Demos._assertAmountAcceptableOnTargetNode` (called by
|
|
167
|
+
* `sendToIdentity` before this helper runs).
|
|
168
|
+
*
|
|
169
|
+
* @internal Exposed only to keep the migration paths discoverable.
|
|
170
|
+
*/
|
|
171
|
+
static normalizeAmountInput(amount) {
|
|
172
|
+
if (typeof amount === "bigint") {
|
|
173
|
+
if (amount < 0n) {
|
|
174
|
+
throw new Error(`[EscrowTransaction] amount must be non-negative, got ${amount}`);
|
|
175
|
+
}
|
|
176
|
+
const amountOs = amount;
|
|
177
|
+
// Sub-DEM precision is allowed at the bigint level — the
|
|
178
|
+
// public API rejection lives in `_assertAmountAcceptableOnTargetNode`,
|
|
179
|
+
// gated on pre-fork node detection. The `amountDem` returned
|
|
180
|
+
// here is integer-truncated; callers that need exact DEM
|
|
181
|
+
// should branch on `amountOs % OS_PER_DEM === 0n` first.
|
|
182
|
+
const amountDem = Number(amountOs / OS_PER_DEM);
|
|
183
|
+
return { amountDem, amountOs };
|
|
184
|
+
}
|
|
185
|
+
if (!Number.isFinite(amount) || amount < 0) {
|
|
186
|
+
throw new Error(`[EscrowTransaction] amount must be a non-negative finite number or bigint, got ${amount}`);
|
|
187
|
+
}
|
|
188
|
+
if (!Number.isInteger(amount)) {
|
|
189
|
+
throw new Error(`[EscrowTransaction] fractional DEM not supported on the number path (got ${amount}); pass a bigint OS amount via denomination.demToOs("${amount}") instead`);
|
|
190
|
+
}
|
|
191
|
+
const amountOs = BigInt(amount) * OS_PER_DEM;
|
|
192
|
+
return { amountDem: amount, amountOs };
|
|
193
|
+
}
|
|
113
194
|
/**
|
|
114
195
|
* Creates a transaction to claim escrowed funds
|
|
115
196
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EscrowTransaction.js","sourceRoot":"","sources":["../../../src/escrow/EscrowTransaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AAIF,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"EscrowTransaction.js","sourceRoot":"","sources":["../../../src/escrow/EscrowTransaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AAIF,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAC1B;;;;;;;OAOG;IACH,MAAM,CAAC,gBAAgB,CAAC,QAAgB,EAAE,QAAgB;QACtD,gDAAgD;QAChD,MAAM,QAAQ,GAAG,GAAG,QAAQ,IAAI,QAAQ,EAAE,CAAC,WAAW,EAAE,CAAA;QACxD,oDAAoD;QACpD,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IACrC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,MAAM,CAAC,KAAK,CAAC,cAAc,CACvB,KAAY,EACZ,QAA2C,EAC3C,QAAgB,EAChB,MAAuB,EACvB,OAGC;QAED,gEAAgE;QAChE,iEAAiE;QACjE,wCAAwC;QACxC,MAAM,EAAE,QAAQ,EAAE,GAAG,iBAAiB,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAA;QAEnE,+DAA+D;QAC/D,gEAAgE;QAChE,gEAAgE;QAChE,6DAA6D;QAC7D,8DAA8D;QAC9D,yDAAyD;QACzD,wCAAwC;QACxC,8DAA8D;QAC9D,MAAO,KAAa,CAAC,m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AQ;aACtB;SACJ,CAAA;QAED,mBAAmB;QACnB,OAAO,MAAM,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC/B,CAAC;CACJ"}
|
|
@@ -118,11 +118,28 @@ export interface IPFSPinsResponse {
|
|
|
118
118
|
* Response from ipfsQuote nodeCall
|
|
119
119
|
*
|
|
120
120
|
* Provides cost estimation before transaction is built and signed.
|
|
121
|
-
* Use this to populate custom_charges in the transaction.
|
|
121
|
+
* Use this to populate `custom_charges` in the transaction.
|
|
122
|
+
*
|
|
123
|
+
* P4 dual-shape compatibility:
|
|
124
|
+
* - Pre-fork node returns `cost_dem` (decimal string, DEM).
|
|
125
|
+
* - Post-fork node returns `cost_os` (decimal string, OS).
|
|
126
|
+
*
|
|
127
|
+
* SDK helpers (`quoteToCustomCharges`, `createCustomCharges`) prefer
|
|
128
|
+
* `cost_os` when present and otherwise convert `cost_dem` via
|
|
129
|
+
* `denomination.demToOs`. Likewise `breakdown.{base_cost,size_cost}` is
|
|
130
|
+
* shape-stable across the fork.
|
|
122
131
|
*/
|
|
123
132
|
export interface IpfsQuoteResponse {
|
|
124
|
-
/**
|
|
125
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Estimated cost in DEM as a decimal string (legacy/pre-fork shape).
|
|
135
|
+
* Kept for back-compat with current node responses.
|
|
136
|
+
*/
|
|
137
|
+
cost_dem?: string;
|
|
138
|
+
/**
|
|
139
|
+
* Estimated cost in OS as a decimal string (post-fork shape).
|
|
140
|
+
* Preferred when present.
|
|
141
|
+
*/
|
|
142
|
+
cost_os?: string;
|
|
126
143
|
/** File size used for calculation */
|
|
127
144
|
file_size_bytes: number;
|
|
128
145
|
/** Whether sender is a genesis account */
|
|
@@ -147,8 +164,8 @@ export interface IpfsQuoteResponse {
|
|
|
147
164
|
export interface AddOptionsWithCharges extends AddOptions {
|
|
148
165
|
/** Optional custom charges configuration for cost control */
|
|
149
166
|
customCharges?: {
|
|
150
|
-
/** Maximum cost user agrees to pay (from ipfsQuote response) */
|
|
151
|
-
|
|
167
|
+
/** Maximum cost user agrees to pay, decimal-string OS (from ipfsQuote response). */
|
|
168
|
+
maxCostOs: string;
|
|
152
169
|
/** Optional cost breakdown for reference */
|
|
153
170
|
estimatedBreakdown?: IPFSCostBreakdown;
|
|
154
171
|
};
|
|
@@ -161,8 +178,8 @@ export interface PinOptionsWithCharges extends PinOptions {
|
|
|
161
178
|
fileSize?: number;
|
|
162
179
|
/** Optional custom charges configuration for cost control */
|
|
163
180
|
customCharges?: {
|
|
164
|
-
/** Maximum cost user agrees to pay (from ipfsQuote response) */
|
|
165
|
-
|
|
181
|
+
/** Maximum cost user agrees to pay, decimal-string OS (from ipfsQuote response). */
|
|
182
|
+
maxCostOs: string;
|
|
166
183
|
/** Optional cost breakdown for reference */
|
|
167
184
|
estimatedBreakdown?: IPFSCostBreakdown;
|
|
168
185
|
};
|
|
@@ -221,7 +238,7 @@ export declare class IPFSOperations {
|
|
|
221
238
|
* content,
|
|
222
239
|
* {
|
|
223
240
|
* filename: 'data.json',
|
|
224
|
-
* customCharges:
|
|
241
|
+
* customCharges: IPFSOperations.quoteToCustomCharges(quote)
|
|
225
242
|
* }
|
|
226
243
|
* )
|
|
227
244
|
* ```
|
|
@@ -251,7 +268,7 @@ export declare class IPFSOperations {
|
|
|
251
268
|
* const quote = await demos.ipfs.quote(fileSize, 'IPFS_PIN')
|
|
252
269
|
* const chargedPayload = IPFSOperations.createPinPayload('QmExample...', {
|
|
253
270
|
* fileSize: 1024,
|
|
254
|
-
* customCharges:
|
|
271
|
+
* customCharges: IPFSOperations.quoteToCustomCharges(quote)
|
|
255
272
|
* })
|
|
256
273
|
* ```
|
|
257
274
|
*/
|
|
@@ -365,9 +382,19 @@ export declare class IPFSOperations {
|
|
|
365
382
|
* ```
|
|
366
383
|
*/
|
|
367
384
|
static quoteToCustomCharges(quote: IpfsQuoteResponse): {
|
|
368
|
-
|
|
385
|
+
maxCostOs: string;
|
|
369
386
|
estimatedBreakdown: IPFSCostBreakdown;
|
|
370
387
|
};
|
|
388
|
+
/**
|
|
389
|
+
* Normalise an `IpfsQuoteResponse` into a single canonical OS-decimal
|
|
390
|
+
* cost string. Prefers `cost_os` (post-fork) over `cost_dem`
|
|
391
|
+
* (pre-fork). Throws if neither is present or both are unparseable.
|
|
392
|
+
*
|
|
393
|
+
* Exposed as a private static helper so internal payload builders and
|
|
394
|
+
* the public `quoteToCustomCharges` / `createCustomCharges` helpers
|
|
395
|
+
* share one implementation.
|
|
396
|
+
*/
|
|
397
|
+
private static _normalizeQuoteCostOs;
|
|
371
398
|
/**
|
|
372
399
|
* Create IPFSCustomCharges object from quote response
|
|
373
400
|
*
|