@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
|
@@ -8,6 +8,7 @@ export type BridgeOperation = {
|
|
|
8
8
|
destinationChain: SupportedEVMChain | SupportedNonEVMChain;
|
|
9
9
|
originAddress: string;
|
|
10
10
|
destinationAddress: string;
|
|
11
|
+
/** Stablecoin amount on the source foreign chain (NOT DEM/OS). */
|
|
11
12
|
amount: string;
|
|
12
13
|
token: SupportedStablecoin;
|
|
13
14
|
txHash: string;
|
|
@@ -17,12 +18,12 @@ export type EVMTankData = {
|
|
|
17
18
|
type: "evm";
|
|
18
19
|
abi: string[];
|
|
19
20
|
address: string;
|
|
20
|
-
amountExpected: number;
|
|
21
|
+
amountExpected: number | string;
|
|
21
22
|
};
|
|
22
23
|
export type SolanaTankData = {
|
|
23
24
|
type: "solana";
|
|
24
25
|
address: string;
|
|
25
|
-
amountExpected: number;
|
|
26
|
+
amountExpected: number | string;
|
|
26
27
|
};
|
|
27
28
|
export type CompiledContent = {
|
|
28
29
|
operation: BridgeOperation;
|
|
@@ -45,7 +46,7 @@ export type NativeBridgeTxPayload = {
|
|
|
45
46
|
export type BridgeOperationCompiledLegacy = {
|
|
46
47
|
content: {
|
|
47
48
|
operation: BridgeOperation;
|
|
48
|
-
amountExpected: number;
|
|
49
|
+
amountExpected: number | string;
|
|
49
50
|
validUntil: number;
|
|
50
51
|
} & ({
|
|
51
52
|
originChain: "EVM";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeBridgeTypes.js","sourceRoot":"","sources":["../../../src/bridge/nativeBridgeTypes.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F,mCAAmC;AACnC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAA;AACzD,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAAM,CAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"nativeBridgeTypes.js","sourceRoot":"","sources":["../../../src/bridge/nativeBridgeTypes.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F,mCAAmC;AACnC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAA;AACzD,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAAM,CAAU,CAAA;AA8FrD,2BAA2B;AAC3B,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAC9B,KAAK;IACL,SAAS;IACT,KAAK;IACL,UAAU;IACV,UAAU;IACV,WAAW;IACX,MAAM;CACA,CAAA;AAEV,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,QAAQ,CAAU,CAAA;AAExD,mEAAmE;AACnE,MAAM,CAAC,MAAM,aAAa,GAAG;IACzB,QAAQ,EAAE,4CAA4C,EAAE,eAAe;IACvE,OAAO,EAAE,4CAA4C,EAAE,cAAc;IACrE,GAAG,EAAE,4CAA4C,EAAE,mBAAmB;IACtE,QAAQ,EAAE,4CAA4C,EAAE,wBAAwB;IAChF,QAAQ,EAAE,4CAA4C,EAAE,wBAAwB;IAChF,SAAS,EAAE,4CAA4C,EAAE,YAAY;IACrE,IAAI,EAAE,4CAA4C,EAAE,oBAAoB;IACxE,MAAM,EAAE,8CAA8C,EAAE,qBAAqB;CAChF,CAAA;AAED,gCAAgC;AAChC,MAAM,CAAC,MAAM,OAAO,GAAG;IACnB,0DAA0D;IAC1D,0CAA0C;CAC7C,CAAA"}
|
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
* Client-side types for HTTP 402 payment protocol implementation
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* Payment requirement from 402 response
|
|
6
|
+
* Payment requirement from 402 response.
|
|
7
|
+
*
|
|
8
|
+
* P4 dual-shape: `amount` may be a JS `number` (pre-fork DEM) or a
|
|
9
|
+
* decimal-`string` (post-fork OS).
|
|
7
10
|
*/
|
|
8
11
|
export interface D402PaymentRequirement {
|
|
9
|
-
/** Payment amount
|
|
10
|
-
amount: number;
|
|
12
|
+
/** Payment amount: pre-fork `number` DEM or post-fork `string` OS. */
|
|
13
|
+
amount: number | string;
|
|
11
14
|
/** Merchant/recipient address */
|
|
12
15
|
recipient: string;
|
|
13
16
|
/** Resource identifier */
|
|
@@ -4,6 +4,31 @@
|
|
|
4
4
|
* Handles payment verification and content gating for Demos Network applications.
|
|
5
5
|
*/
|
|
6
6
|
import type { D402ServerConfig, D402PaymentRequirement, D402VerificationResult } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Normalise a D402 dual-shape amount carrier to OS `bigint`.
|
|
9
|
+
*
|
|
10
|
+
* The carrier widened in P4 to `number | string` so a single requirement
|
|
11
|
+
* object can be served by both pre-fork (DEM `number`) and post-fork
|
|
12
|
+
* (OS decimal `string`) nodes. Naïve `<` comparison on this union is
|
|
13
|
+
* unsafe: string-vs-string is lexicographic ("5000000000" < "5" === true)
|
|
14
|
+
* and number/string mixes coerce through `Number(...)` which loses
|
|
15
|
+
* precision above 2^53. Both failure modes can wrongly accept
|
|
16
|
+
* underpayment or reject valid payment.
|
|
17
|
+
*
|
|
18
|
+
* - `number` input: treated as DEM (legacy wire) and converted to OS
|
|
19
|
+
* via `demToOs`. Negative or non-finite numbers throw.
|
|
20
|
+
* - `string` input: treated as a canonical OS decimal-integer string
|
|
21
|
+
* and parsed via `parseOsString`. Non-canonical strings (whitespace,
|
|
22
|
+
* leading zeros, signed prefix) throw.
|
|
23
|
+
*
|
|
24
|
+
* The throw is intentional — D402 amount fields cross a trust boundary
|
|
25
|
+
* (the requirement set by the merchant, the verified amount returned
|
|
26
|
+
* by the node) and a malformed value is a configuration error, not a
|
|
27
|
+
* silent default.
|
|
28
|
+
*
|
|
29
|
+
* @internal exported for tests; not part of the public D402 API.
|
|
30
|
+
*/
|
|
31
|
+
export declare function _normalizeD402AmountToOsBigint(value: number | string | bigint): bigint;
|
|
7
32
|
export declare class D402Server {
|
|
8
33
|
private rpcUrl;
|
|
9
34
|
private cacheTTL;
|
|
@@ -3,6 +3,53 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Handles payment verification and content gating for Demos Network applications.
|
|
5
5
|
*/
|
|
6
|
+
import { demToOs, parseOsString } from '../../denomination/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Normalise a D402 dual-shape amount carrier to OS `bigint`.
|
|
9
|
+
*
|
|
10
|
+
* The carrier widened in P4 to `number | string` so a single requirement
|
|
11
|
+
* object can be served by both pre-fork (DEM `number`) and post-fork
|
|
12
|
+
* (OS decimal `string`) nodes. Naïve `<` comparison on this union is
|
|
13
|
+
* unsafe: string-vs-string is lexicographic ("5000000000" < "5" === true)
|
|
14
|
+
* and number/string mixes coerce through `Number(...)` which loses
|
|
15
|
+
* precision above 2^53. Both failure modes can wrongly accept
|
|
16
|
+
* underpayment or reject valid payment.
|
|
17
|
+
*
|
|
18
|
+
* - `number` input: treated as DEM (legacy wire) and converted to OS
|
|
19
|
+
* via `demToOs`. Negative or non-finite numbers throw.
|
|
20
|
+
* - `string` input: treated as a canonical OS decimal-integer string
|
|
21
|
+
* and parsed via `parseOsString`. Non-canonical strings (whitespace,
|
|
22
|
+
* leading zeros, signed prefix) throw.
|
|
23
|
+
*
|
|
24
|
+
* The throw is intentional — D402 amount fields cross a trust boundary
|
|
25
|
+
* (the requirement set by the merchant, the verified amount returned
|
|
26
|
+
* by the node) and a malformed value is a configuration error, not a
|
|
27
|
+
* silent default.
|
|
28
|
+
*
|
|
29
|
+
* @internal exported for tests; not part of the public D402 API.
|
|
30
|
+
*/
|
|
31
|
+
export function _normalizeD402AmountToOsBigint(value) {
|
|
32
|
+
if (typeof value === 'bigint') {
|
|
33
|
+
if (value < 0n) {
|
|
34
|
+
throw new Error(`[D402Server] amount must be non-negative, got ${value}`);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
if (typeof value === 'number') {
|
|
39
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
40
|
+
throw new Error(`[D402Server] amount must be a non-negative finite number, got ${value}`);
|
|
41
|
+
}
|
|
42
|
+
// demToOs accepts integer or fractional DEM; for D402 a fractional
|
|
43
|
+
// DEM number is valid (the legacy wire allowed sub-DEM numerics
|
|
44
|
+
// in some indexer paths) so we don't add an extra is-integer guard
|
|
45
|
+
// here.
|
|
46
|
+
return demToOs(value);
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === 'string') {
|
|
49
|
+
return parseOsString(value);
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`[D402Server] amount must be number | string | bigint, got ${typeof value}`);
|
|
52
|
+
}
|
|
6
53
|
export class D402Server {
|
|
7
54
|
constructor(config) {
|
|
8
55
|
this.rpcUrl = config.rpcUrl;
|
|
@@ -119,8 +166,22 @@ export class D402Server {
|
|
|
119
166
|
if (verification.verified_to !== requirement.recipient) {
|
|
120
167
|
return false;
|
|
121
168
|
}
|
|
122
|
-
// Check amount matches (or exceeds)
|
|
123
|
-
|
|
169
|
+
// Check amount matches (or exceeds). BigInt-normalise both sides
|
|
170
|
+
// so the dual-shape (number DEM | string OS) carrier works
|
|
171
|
+
// correctly: lexicographic string compare and Number() coercion
|
|
172
|
+
// both produce wrong answers on real-world OS magnitudes.
|
|
173
|
+
// A malformed amount here is a configuration / RPC-corruption
|
|
174
|
+
// bug — fail closed and return false rather than throwing the
|
|
175
|
+
// exception across the middleware.
|
|
176
|
+
try {
|
|
177
|
+
const verifiedOs = _normalizeD402AmountToOsBigint(verification.verified_amount);
|
|
178
|
+
const requiredOs = _normalizeD402AmountToOsBigint(requirement.amount);
|
|
179
|
+
if (verifiedOs < requiredOs) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
console.error('[D402Server] amount comparison failed:', err);
|
|
124
185
|
return false;
|
|
125
186
|
}
|
|
126
187
|
// Check resource ID in memo (format: "resourceId:xyz")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"D402Server.js","sourceRoot":"","sources":["../../../../src/d402/server/D402Server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"D402Server.js","sourceRoot":"","sources":["../../../../src/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ED;;OAEG;IACK,UAAU;QACd,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC;YACxD,IAAI,GAAG,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;gBAC3B,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAClC,CAAC;QACL,CAAC;IACL,CAAC;IAED;;OAEG;IACH,UAAU;QACN,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;IAC7B,CAAC;CACJ"}
|
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
* Express-compatible middleware for HTTP 402 payment gating
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* Middleware configuration options
|
|
6
|
+
* Middleware configuration options.
|
|
7
|
+
*
|
|
8
|
+
* P4 dual-shape: `amount` may be a JS `number` (pre-fork DEM) or a
|
|
9
|
+
* decimal-`string` (post-fork OS).
|
|
7
10
|
*/
|
|
8
11
|
export interface D402MiddlewareOptions {
|
|
9
|
-
/** Payment amount
|
|
10
|
-
amount: number;
|
|
12
|
+
/** Payment amount: pre-fork `number` DEM or post-fork `string` OS. */
|
|
13
|
+
amount: number | string;
|
|
11
14
|
/** Resource identifier (included in memo validation) */
|
|
12
15
|
resourceId: string;
|
|
13
16
|
/** Demos Network RPC URL */
|
|
@@ -29,7 +32,7 @@ export interface D402Request {
|
|
|
29
32
|
d402Payment?: {
|
|
30
33
|
from: string;
|
|
31
34
|
to: string;
|
|
32
|
-
amount: number;
|
|
35
|
+
amount: number | string;
|
|
33
36
|
txHash: string;
|
|
34
37
|
};
|
|
35
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../src/d402/server/middleware.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE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xB,KAAK,EAAE,6BAA6B;aACvC,CAAC,CAAA;QACN,CAAC;IACL,CAAC,CAAA;AACL,CAAC"}
|
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
* Server-side types for HTTP 402 payment protocol implementation
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* Payment requirements sent in 402 response
|
|
6
|
+
* Payment requirements sent in 402 response.
|
|
7
|
+
*
|
|
8
|
+
* P4 dual-shape: `amount` may be a JS `number` (pre-fork DEM) or a
|
|
9
|
+
* decimal-`string` (post-fork OS). SDK consumers should normalise via
|
|
10
|
+
* `BigInt(...)` before arithmetic.
|
|
7
11
|
*/
|
|
8
12
|
export interface D402PaymentRequirement {
|
|
9
|
-
/** Payment amount in
|
|
10
|
-
amount: number;
|
|
13
|
+
/** Payment amount in DEM (number) or OS (decimal string). */
|
|
14
|
+
amount: number | string;
|
|
11
15
|
/** Merchant/recipient address */
|
|
12
16
|
recipient: string;
|
|
13
17
|
/** Resource identifier (used in memo validation) */
|
|
@@ -16,13 +20,16 @@ export interface D402PaymentRequirement {
|
|
|
16
20
|
description?: string;
|
|
17
21
|
}
|
|
18
22
|
/**
|
|
19
|
-
* Payment verification result from RPC
|
|
23
|
+
* Payment verification result from RPC.
|
|
24
|
+
*
|
|
25
|
+
* P4 dual-shape: `verified_amount` may arrive as a JS `number` (pre-fork
|
|
26
|
+
* DEM) or a decimal-`string` (post-fork OS).
|
|
20
27
|
*/
|
|
21
28
|
export interface D402VerificationResult {
|
|
22
29
|
valid: boolean;
|
|
23
30
|
verified_from?: string;
|
|
24
31
|
verified_to?: string;
|
|
25
|
-
verified_amount?: number;
|
|
32
|
+
verified_amount?: number | string;
|
|
26
33
|
verified_memo?: string;
|
|
27
34
|
timestamp: number;
|
|
28
35
|
}
|
|
@@ -36,13 +43,14 @@ export interface D402ServerConfig {
|
|
|
36
43
|
cacheTTL?: number;
|
|
37
44
|
}
|
|
38
45
|
/**
|
|
39
|
-
* Cached payment data
|
|
46
|
+
* Cached payment data. `amount` follows the dual-shape rule (number DEM
|
|
47
|
+
* pre-fork, decimal-string OS post-fork).
|
|
40
48
|
*/
|
|
41
49
|
export interface CachedPayment {
|
|
42
50
|
txHash: string;
|
|
43
51
|
from: string;
|
|
44
52
|
to: string;
|
|
45
|
-
amount: number;
|
|
53
|
+
amount: number | string;
|
|
46
54
|
memo: string;
|
|
47
55
|
timestamp: number;
|
|
48
56
|
expiresAt: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, test, expect } from "
|
|
1
|
+
import { describe, test, expect } from "@jest/globals";
|
|
2
2
|
import { demToOs, osToDem, parseOsString, toOsString, formatDem, } from "./conversion.js";
|
|
3
3
|
// REVIEW: P0 foundation — verbatim test suite from IDEA.md §0.5 plus three
|
|
4
4
|
// edge-case tests called out in the P0 task brief.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversion.test.js","sourceRoot":"","sources":["../../../src/denomination/conversion.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"conversion.test.js","sourceRoot":"","sources":["../../../src/denomination/conversion.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtD,OAAO,EACH,OAAO,EACP,OAAO,EACP,aAAa,EACb,UAAU,EACV,SAAS,GACZ,MAAM,cAAc,CAAA;AAErB,2EAA2E;AAC3E,mDAAmD;AAEnD,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACrB,IAAI,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAc,CAAC,CAAA;QACvC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,aAAgB,CAAC,CAAA;QAC3C,MAA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,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
|
@@ -8,3 +8,6 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export { OS_DECIMALS, OS_PER_DEM, MIN_AMOUNT_OS, ZERO_OS, } from "./constants";
|
|
10
10
|
export { demToOs, osToDem, parseOsString, toOsString, formatDem, } from "./conversion";
|
|
11
|
+
export { serializeTransactionContent } from "./serializerGate";
|
|
12
|
+
export type { ForkStatus, NetworkInfo } from "./networkInfo";
|
|
13
|
+
export { SubDemPrecisionError } from "./networkInfo";
|
|
@@ -9,4 +9,10 @@
|
|
|
9
9
|
// REVIEW: P0 foundation — barrel export for the new denomination module.
|
|
10
10
|
export { OS_DECIMALS, OS_PER_DEM, MIN_AMOUNT_OS, ZERO_OS, } from "./constants.js";
|
|
11
11
|
export { demToOs, osToDem, parseOsString, toOsString, formatDem, } from "./conversion.js";
|
|
12
|
+
// REVIEW: P4 commit 2 — dual-format serializer (internal infrastructure).
|
|
13
|
+
// Exported through `denomination` so consumers can compute SDK-shaped
|
|
14
|
+
// hashes for off-line workflows; the primary use is internal to
|
|
15
|
+
// `Demos.sign`.
|
|
16
|
+
export { serializeTransactionContent } from "./serializerGate.js";
|
|
17
|
+
export { SubDemPrecisionError } from "./networkInfo.js";
|
|
12
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/denomination/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,yEAAyE;AAEzE,OAAO,EACH,WAAW,EACX,UAAU,EACV,aAAa,EACb,OAAO,GACV,MAAM,aAAa,CAAA;AAEpB,OAAO,EACH,OAAO,EACP,OAAO,EACP,aAAa,EACb,UAAU,EACV,SAAS,GACZ,MAAM,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/denomination/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,yEAAyE;AAEzE,OAAO,EACH,WAAW,EACX,UAAU,EACV,aAAa,EACb,OAAO,GACV,MAAM,aAAa,CAAA;AAEpB,OAAO,EACH,OAAO,EACP,OAAO,EACP,aAAa,EACb,UAAU,EACV,SAAS,GACZ,MAAM,cAAc,CAAA;AAErB,0EAA0E;AAC1E,sEAAsE;AACtE,gEAAgE;AAChE,gBAAgB;AAChB,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAA;AAK9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fork-detection types and the sub-DEM precision error.
|
|
3
|
+
*
|
|
4
|
+
* Shape mirrors the node's `libs/network/handlers/forkHandlers.ts`
|
|
5
|
+
* response — this is the wire contract for the `getNetworkInfo`
|
|
6
|
+
* `nodeCall`. Wrapping the per-fork status under `forks.<name>` makes
|
|
7
|
+
* adding a future fork a strictly additive change.
|
|
8
|
+
*
|
|
9
|
+
* @module denomination/networkInfo
|
|
10
|
+
*/
|
|
11
|
+
/** Per-fork status entry. */
|
|
12
|
+
export interface ForkStatus {
|
|
13
|
+
/**
|
|
14
|
+
* Configured activation height for the fork. `null` means the fork
|
|
15
|
+
* is configured but unscheduled (the SDK should treat this as
|
|
16
|
+
* "fork will not activate during this RPC's lifetime").
|
|
17
|
+
*/
|
|
18
|
+
activationHeight: number | null;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the fork's rules are currently active on the node.
|
|
21
|
+
* Computed by the canonical `isForkActive` gate node-side; the SDK
|
|
22
|
+
* uses this directly without recomputing.
|
|
23
|
+
*/
|
|
24
|
+
activated: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* In-memory cache of the latest block height the node has
|
|
27
|
+
* processed. Lets clients do their own near-fork detection without
|
|
28
|
+
* an extra `getLastBlockNumber` call.
|
|
29
|
+
*/
|
|
30
|
+
currentHeight: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Response shape for the `getNetworkInfo` `nodeCall`.
|
|
34
|
+
*
|
|
35
|
+
* The SDK only consults `forks.osDenomination.activated` for serializer
|
|
36
|
+
* routing; the rest of the payload is exposed for callers that want to
|
|
37
|
+
* surface near-fork warnings to their users.
|
|
38
|
+
*/
|
|
39
|
+
export interface NetworkInfo {
|
|
40
|
+
forks: {
|
|
41
|
+
osDenomination: ForkStatus;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Thrown by `Demos.transfer` (and friends) when a caller passes an OS
|
|
46
|
+
* amount with sub-DEM precision against a node that has not yet
|
|
47
|
+
* activated the `osDenomination` fork. The pre-fork wire shape is a JS
|
|
48
|
+
* `number` in DEM, which cannot represent sub-DEM precision; sending
|
|
49
|
+
* the transaction would silently truncate the user's funds. This guard
|
|
50
|
+
* fails fast at the public-API boundary before any signing happens.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* try {
|
|
55
|
+
* await demos.transfer(to, 1_234_567n) // sub-DEM precision
|
|
56
|
+
* } catch (err) {
|
|
57
|
+
* if (err instanceof SubDemPrecisionError) {
|
|
58
|
+
* // tell the user to round, or to upgrade the node
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare class SubDemPrecisionError extends Error {
|
|
64
|
+
/** Full OS amount the caller attempted to send. */
|
|
65
|
+
readonly amountOs: bigint;
|
|
66
|
+
/** Truncated remainder: `amountOs % OS_PER_DEM`. */
|
|
67
|
+
readonly subDemRemainderOs: bigint;
|
|
68
|
+
constructor(amountOs: bigint, subDemRemainderOs: bigint);
|
|
69
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fork-detection types and the sub-DEM precision error.
|
|
3
|
+
*
|
|
4
|
+
* Shape mirrors the node's `libs/network/handlers/forkHandlers.ts`
|
|
5
|
+
* response — this is the wire contract for the `getNetworkInfo`
|
|
6
|
+
* `nodeCall`. Wrapping the per-fork status under `forks.<name>` makes
|
|
7
|
+
* adding a future fork a strictly additive change.
|
|
8
|
+
*
|
|
9
|
+
* @module denomination/networkInfo
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Thrown by `Demos.transfer` (and friends) when a caller passes an OS
|
|
13
|
+
* amount with sub-DEM precision against a node that has not yet
|
|
14
|
+
* activated the `osDenomination` fork. The pre-fork wire shape is a JS
|
|
15
|
+
* `number` in DEM, which cannot represent sub-DEM precision; sending
|
|
16
|
+
* the transaction would silently truncate the user's funds. This guard
|
|
17
|
+
* fails fast at the public-API boundary before any signing happens.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* try {
|
|
22
|
+
* await demos.transfer(to, 1_234_567n) // sub-DEM precision
|
|
23
|
+
* } catch (err) {
|
|
24
|
+
* if (err instanceof SubDemPrecisionError) {
|
|
25
|
+
* // tell the user to round, or to upgrade the node
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class SubDemPrecisionError extends Error {
|
|
31
|
+
constructor(amountOs, subDemRemainderOs) {
|
|
32
|
+
super(`Cannot send amount ${amountOs} OS to a pre-fork node: sub-DEM precision (${subDemRemainderOs} OS) would be silently truncated. The target node must upgrade to support OS-denomination before this transaction can be sent.`);
|
|
33
|
+
this.name = "SubDemPrecisionError";
|
|
34
|
+
this.amountOs = amountOs;
|
|
35
|
+
this.subDemRemainderOs = subDemRemainderOs;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=networkInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networkInfo.js","sourceRoot":"","sources":["../../../src/denomination/networkInfo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAyCH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAM3C,YAAY,QAAgB,EAAE,iBAAyB;QACnD,KAAK,CACD,sBAAsB,QAAQ,8CAA8C,iBAAiB,gIAAgI,CAChO,CAAA;QACD,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;QAClC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAC9C,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, test, expect } from "@jest/globals";
|
|
2
|
+
import { SubDemPrecisionError } from "./networkInfo.js";
|
|
3
|
+
import { OS_PER_DEM } from "./constants.js";
|
|
4
|
+
// REVIEW: P4 commit 3 — public-API guard tests. The actual
|
|
5
|
+
// `Demos.getNetworkInfo` / `_isPostForkCached` round-trip is exercised
|
|
6
|
+
// in src/tests/forkDetection.spec.ts because it needs the full Demos
|
|
7
|
+
// class wired with a stubbed nodeCall.
|
|
8
|
+
describe("SubDemPrecisionError", () => {
|
|
9
|
+
test("carries the offending OS amount and the truncated remainder", () => {
|
|
10
|
+
const amountOs = 1234567890n;
|
|
11
|
+
const remainder = amountOs % OS_PER_DEM; // 234_567_890n
|
|
12
|
+
const err = new SubDemPrecisionError(amountOs, remainder);
|
|
13
|
+
expect(err).toBeInstanceOf(Error);
|
|
14
|
+
expect(err).toBeInstanceOf(SubDemPrecisionError);
|
|
15
|
+
expect(err.name).toBe("SubDemPrecisionError");
|
|
16
|
+
expect(err.amountOs).toBe(amountOs);
|
|
17
|
+
expect(err.subDemRemainderOs).toBe(remainder);
|
|
18
|
+
expect(err.message).toContain("1234567890 OS");
|
|
19
|
+
expect(err.message).toContain("234567890 OS");
|
|
20
|
+
expect(err.message).toContain("pre-fork node");
|
|
21
|
+
});
|
|
22
|
+
test("instanceof works after JSON-like construction", () => {
|
|
23
|
+
const err = new SubDemPrecisionError(1n, 1n);
|
|
24
|
+
expect(err instanceof SubDemPrecisionError).toBe(true);
|
|
25
|
+
expect(err instanceof Error).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=networkInfo.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networkInfo.test.js","sourceRoot":"","sources":["../../../src/denomination/networkInfo.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,2DAA2D;AAC3D,uEAAuE;AACvE,qEAAqE;AACrE,uCAAuC;AAEvC,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IAClC,IAAI,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACrE,MAAM,QAAQ,GAAG,WAAc,CAAA;QAC/B,MAAM,SAAS,GAAG,QAAQ,GAAG,UAAU,CAAA,CAAC,eAAe;QACvD,MAAM,GAAG,GAAG,IAAI,oBAAoB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;QACzD,MAAM,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;QACjC,MAAM,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAA;QAChD,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;QAC7C,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACnC,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAC7C,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,CAAA;QAC9C,MAAM,CAAC,GAAG,CA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