@kynesyslabs/demosdk 2.12.1 → 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.
Files changed (108) hide show
  1. package/build/abstraction/EvmCoinFinder.js +14 -2
  2. package/build/abstraction/EvmCoinFinder.js.map +1 -1
  3. package/build/abstraction/Identities.js +3 -1
  4. package/build/abstraction/Identities.js.map +1 -1
  5. package/build/bridge/nativeBridgeTypes.d.ts +4 -3
  6. package/build/bridge/nativeBridgeTypes.js.map +1 -1
  7. package/build/d402/client/types.d.ts +6 -3
  8. package/build/d402/server/D402Server.d.ts +25 -0
  9. package/build/d402/server/D402Server.js +63 -2
  10. package/build/d402/server/D402Server.js.map +1 -1
  11. package/build/d402/server/middleware.d.ts +7 -4
  12. package/build/d402/server/middleware.js.map +1 -1
  13. package/build/d402/server/types.d.ts +15 -7
  14. package/build/denomination/conversion.test.js +1 -1
  15. package/build/denomination/conversion.test.js.map +1 -1
  16. package/build/denomination/index.d.ts +3 -0
  17. package/build/denomination/index.js +6 -0
  18. package/build/denomination/index.js.map +1 -1
  19. package/build/denomination/networkInfo.d.ts +69 -0
  20. package/build/denomination/networkInfo.js +38 -0
  21. package/build/denomination/networkInfo.js.map +1 -0
  22. package/build/denomination/networkInfo.test.d.ts +1 -0
  23. package/build/denomination/networkInfo.test.js +28 -0
  24. package/build/denomination/networkInfo.test.js.map +1 -0
  25. package/build/denomination/roundTripHash.test.d.ts +1 -0
  26. package/build/denomination/roundTripHash.test.js +227 -0
  27. package/build/denomination/roundTripHash.test.js.map +1 -0
  28. package/build/denomination/serializerGate.d.ts +46 -0
  29. package/build/denomination/serializerGate.js +283 -0
  30. package/build/denomination/serializerGate.js.map +1 -0
  31. package/build/denomination/serializerGate.test.d.ts +1 -0
  32. package/build/denomination/serializerGate.test.js +245 -0
  33. package/build/denomination/serializerGate.test.js.map +1 -0
  34. package/build/encryption/zK/interactive/index.js +5 -1
  35. package/build/encryption/zK/interactive/index.js.map +1 -1
  36. package/build/escrow/EscrowTransaction.d.ts +36 -5
  37. package/build/escrow/EscrowTransaction.js +91 -10
  38. package/build/escrow/EscrowTransaction.js.map +1 -1
  39. package/build/instant_messaging/L2PSMessagingPeer.js +4 -1
  40. package/build/instant_messaging/L2PSMessagingPeer.js.map +1 -1
  41. package/build/ipfs/IPFSOperations.d.ts +37 -10
  42. package/build/ipfs/IPFSOperations.js +38 -8
  43. package/build/ipfs/IPFSOperations.js.map +1 -1
  44. package/build/storage/StorageProgram.d.ts +16 -8
  45. package/build/storage/StorageProgram.js +16 -8
  46. package/build/storage/StorageProgram.js.map +1 -1
  47. package/build/tlsnotary/TLSNotaryService.d.ts +19 -8
  48. package/build/tlsnotary/TLSNotaryService.js +22 -7
  49. package/build/tlsnotary/TLSNotaryService.js.map +1 -1
  50. package/build/tlsnotary/helpers.d.ts +11 -5
  51. package/build/tlsnotary/helpers.js +17 -5
  52. package/build/tlsnotary/helpers.js.map +1 -1
  53. package/build/types/blockchain/CustomCharges.d.ts +28 -16
  54. package/build/types/blockchain/CustomCharges.js +15 -5
  55. package/build/types/blockchain/CustomCharges.js.map +1 -1
  56. package/build/types/blockchain/GCREdit.d.ts +80 -3
  57. package/build/types/blockchain/NetworkParameters.d.ts +54 -0
  58. package/build/types/blockchain/NetworkParameters.js +9 -0
  59. package/build/types/blockchain/NetworkParameters.js.map +1 -0
  60. package/build/types/blockchain/Transaction.d.ts +21 -3
  61. package/build/types/blockchain/Transaction.js.map +1 -1
  62. package/build/types/blockchain/TransactionSubtypes/D402PaymentTransaction.d.ts +8 -3
  63. package/build/types/blockchain/TransactionSubtypes/NetworkUpgradeTransaction.d.ts +20 -0
  64. package/build/types/blockchain/TransactionSubtypes/NetworkUpgradeTransaction.js +2 -0
  65. package/build/types/blockchain/TransactionSubtypes/NetworkUpgradeTransaction.js.map +1 -0
  66. package/build/types/blockchain/TransactionSubtypes/NetworkUpgradeVoteTransaction.d.ts +13 -0
  67. package/build/types/blockchain/TransactionSubtypes/NetworkUpgradeVoteTransaction.js +2 -0
  68. package/build/types/blockchain/TransactionSubtypes/NetworkUpgradeVoteTransaction.js.map +1 -0
  69. package/build/types/blockchain/TransactionSubtypes/StorageProgramTransaction.d.ts +6 -5
  70. package/build/types/blockchain/TransactionSubtypes/StorageProgramTransaction.js +15 -3
  71. package/build/types/blockchain/TransactionSubtypes/StorageProgramTransaction.js.map +1 -1
  72. package/build/types/blockchain/TransactionSubtypes/ValidatorExitTransaction.d.ts +10 -0
  73. package/build/types/blockchain/TransactionSubtypes/ValidatorExitTransaction.js +2 -0
  74. package/build/types/blockchain/TransactionSubtypes/ValidatorExitTransaction.js.map +1 -0
  75. package/build/types/blockchain/TransactionSubtypes/ValidatorStakeTransaction.d.ts +15 -0
  76. package/build/types/blockchain/TransactionSubtypes/ValidatorStakeTransaction.js +2 -0
  77. package/build/types/blockchain/TransactionSubtypes/ValidatorStakeTransaction.js.map +1 -0
  78. package/build/types/blockchain/TransactionSubtypes/ValidatorUnstakeTransaction.d.ts +10 -0
  79. package/build/types/blockchain/TransactionSubtypes/ValidatorUnstakeTransaction.js +2 -0
  80. package/build/types/blockchain/TransactionSubtypes/ValidatorUnstakeTransaction.js.map +1 -0
  81. package/build/types/blockchain/TransactionSubtypes/index.d.ts +11 -1
  82. package/build/types/blockchain/TransactionSubtypes/index.js +7 -0
  83. package/build/types/blockchain/TransactionSubtypes/index.js.map +1 -1
  84. package/build/types/blockchain/TxFee.d.ts +16 -3
  85. package/build/types/blockchain/address.d.ts +23 -0
  86. package/build/types/blockchain/rawTransaction.d.ts +13 -4
  87. package/build/types/blockchain/statusNative.d.ts +9 -1
  88. package/build/types/bridge/bridgeTradePayload.d.ts +1 -1
  89. package/build/types/gls/StateChange.d.ts +29 -3
  90. package/build/types/index.d.ts +4 -2
  91. package/build/types/index.js.map +1 -1
  92. package/build/types/native/INativePayload.d.ts +6 -1
  93. package/build/types/validator/ValidatorTypes.d.ts +13 -0
  94. package/build/types/validator/ValidatorTypes.js +3 -0
  95. package/build/types/validator/ValidatorTypes.js.map +1 -0
  96. package/build/wallet/Wallet.d.ts +27 -1
  97. package/build/wallet/Wallet.js +30 -17
  98. package/build/wallet/Wallet.js.map +1 -1
  99. package/build/websdk/DemosTransactions.d.ts +78 -4
  100. package/build/websdk/DemosTransactions.js +253 -9
  101. package/build/websdk/DemosTransactions.js.map +1 -1
  102. package/build/websdk/GCRGeneration.d.ts +11 -2
  103. package/build/websdk/GCRGeneration.js +143 -14
  104. package/build/websdk/GCRGeneration.js.map +1 -1
  105. package/build/websdk/demosclass.d.ts +238 -26
  106. package/build/websdk/demosclass.js +434 -54
  107. package/build/websdk/demosclass.js.map +1 -1
  108. package/package.json +1 -1
@@ -1,3 +1,25 @@
1
+ /**
2
+ * Snapshot of an address's on-chain state.
3
+ *
4
+ * P4: `balance` is `bigint`. The magnitude depends on the connected
5
+ * node's fork status:
6
+ *
7
+ * - **Post-fork**: the node returns balance in **OS** (smallest unit,
8
+ * 1 DEM = 10^9 OS). The SDK passes this through unchanged.
9
+ * - **Pre-fork**: the node returns balance in **DEM**. The SDK passes
10
+ * this through unchanged — it does **not** auto-convert client-side.
11
+ *
12
+ * Consumers that need to do arithmetic in OS regardless of node version
13
+ * should branch on `demos.getNetworkInfo()` (or the internal
14
+ * `_isPostForkCached`) and call `denomination.demToOs(balance)` only
15
+ * on the pre-fork branch. For display, use `denomination.osToDem(balance)`
16
+ * post-fork or treat the value as DEM directly pre-fork.
17
+ *
18
+ * (Earlier drafts of this doc claimed the SDK multiplied pre-fork
19
+ * balances client-side via `osToDem`; that was inaccurate on both
20
+ * counts — `osToDem` divides, and the SDK does not multiply at all.
21
+ * Fixed in PR-86 review.)
22
+ */
1
23
  export interface AddressInfo {
2
24
  pubkey: string;
3
25
  assignedTxs: string[];
@@ -6,5 +28,6 @@ export interface AddressInfo {
6
28
  web2: Map<string, string[]>;
7
29
  };
8
30
  nonce: number;
31
+ /** Address balance, `bigint` in OS (smallest unit). */
9
32
  balance: bigint;
10
33
  }
@@ -1,4 +1,13 @@
1
1
  import { TransactionContent } from "./Transaction";
2
+ /**
3
+ * Raw transaction row as it surfaces from the node's storage layer.
4
+ *
5
+ * Wire-format compatibility note (P4): `amount`, `networkFee`, `rpcFee`, and
6
+ * `additionalFee` may arrive as either JS `number` (pre-fork node, DEM) or
7
+ * decimal `string` (post-fork node, OS). Consumers must coerce via
8
+ * `denomination.parseOsString` / `BigInt(...)` before doing arithmetic;
9
+ * never call raw `Number(...)` once OS-magnitude values are possible.
10
+ */
2
11
  export interface RawTransaction {
3
12
  id: number;
4
13
  blockNumber: number;
@@ -9,12 +18,12 @@ export interface RawTransaction {
9
18
  type: TransactionContent["type"];
10
19
  from: any;
11
20
  to: any;
12
- amount: number;
21
+ amount: number | string;
13
22
  nonce: number;
14
23
  timestamp: number;
15
- networkFee: number;
16
- rpcFee: number;
17
- additionalFee: number;
24
+ networkFee: number | string;
25
+ rpcFee: number | string;
26
+ additionalFee: number | string;
18
27
  ed25519_signature: string;
19
28
  from_ed25519_address: string;
20
29
  }
@@ -1,6 +1,14 @@
1
+ /**
2
+ * Native chain status snapshot for an address.
3
+ *
4
+ * Wire-format compatibility (P4): `balance` may arrive as a JS `number`
5
+ * (pre-fork node, DEM) or a decimal `string` (post-fork node, OS).
6
+ * Consumers should normalise via `BigInt(...)` to OS internally before
7
+ * arithmetic. Direct `Number(balance)` truncates above 2^53.
8
+ */
1
9
  export interface StatusNative {
2
10
  address: string;
3
- balance: number;
11
+ balance: number | string;
4
12
  nonce: number;
5
13
  tx_list: string;
6
14
  }
@@ -1,7 +1,7 @@
1
1
  export interface BridgeTradePayload {
2
2
  fromToken: "NATIVE" | "USDC" | "USDT";
3
3
  toToken: "NATIVE" | "USDC" | "USDT";
4
- amount: number;
4
+ amount: number | string;
5
5
  fromChainId: number;
6
6
  toChainId: number;
7
7
  }
@@ -1,17 +1,43 @@
1
1
  import forge from "node-forge";
2
+ /**
3
+ * Indexer-style state change record. Wire-format compatibility (P4):
4
+ * `nativeAmount`, `TokenTransfer.amount`, and `NFTTransfer.amount` may
5
+ * arrive as JS `number` (pre-fork DEM) or decimal `string` (post-fork OS).
6
+ *
7
+ * Consumers should normalise via the denomination helpers, **not**
8
+ * `BigInt(...)`, because:
9
+ *
10
+ * - `BigInt(numberWithFractional)` throws `RangeError`.
11
+ * - `BigInt("non-numeric")` throws `SyntaxError`.
12
+ * - `BigInt(...)` does not validate decimal-string OS canonicality —
13
+ * indexer responses can arrive with whitespace, leading zeros, or
14
+ * signed-integer notation.
15
+ *
16
+ * Recommended:
17
+ *
18
+ * - `denomination.parseOsString(value)` for OS decimal-string inputs
19
+ * (post-fork wire). Strips noise and validates the integer shape.
20
+ * - `denomination.demToOs(value)` for DEM `number` inputs (pre-fork
21
+ * wire). Validates and converts to OS bigint.
22
+ *
23
+ * Branch on the source's known fork status (e.g. via
24
+ * `demos.getNetworkInfo()`), not on `typeof value` — the literal `"5"`
25
+ * could be either a pre-fork DEM string or a post-fork OS string,
26
+ * which differ by a factor of 10^9.
27
+ */
2
28
  interface TokenTransfer {
3
29
  address: string;
4
- amount: number;
30
+ amount: number | string;
5
31
  }
6
32
  interface NFTTransfer {
7
33
  address: string;
8
34
  tokenId: string;
9
- amount: number;
35
+ amount: number | string;
10
36
  }
11
37
  export interface StateChange {
12
38
  sender: forge.pki.ed25519.BinaryBuffer;
13
39
  receiver: forge.pki.ed25519.BinaryBuffer;
14
- nativeAmount: number;
40
+ nativeAmount: number | string;
15
41
  tx_hash: string;
16
42
  token: TokenTransfer;
17
43
  nft: NFTTransfer;
@@ -4,7 +4,7 @@ export { ISignature } from "./blockchain/ISignature";
4
4
  export { RawTransaction } from "./blockchain/rawTransaction";
5
5
  export { Transaction, TransactionContent, TransactionContentData, } from "./blockchain/Transaction";
6
6
  export { type CustomCharges, type IPFSCustomCharges, type IPFSCostBreakdown, type ValidityDataCustomCharges, hasIPFSCustomCharges, isValidCharge, } from "./blockchain/CustomCharges";
7
- export { L2PSTransaction, Web2Transaction, CrosschainTransaction, NativeTransaction, DemosworkTransaction, IdentityTransaction, InstantMessagingTransaction, NativeBridgeTransaction, SpecificTransaction, IPFSTransaction, type IPFSTransactionContent, type IPFSPayload, type IPFSAddPayload, type IPFSPinPayload, type IPFSUnpinPayload, type IPFSExtendPinPayload, type IPFSOperationType, isIPFSAddPayload, isIPFSPinPayload, isIPFSUnpinPayload, isIPFSExtendPinPayload, isIPFSPayload, } from "./blockchain/TransactionSubtypes";
7
+ export { L2PSTransaction, Web2Transaction, CrosschainTransaction, NativeTransaction, DemosworkTransaction, IdentityTransaction, InstantMessagingTransaction, NativeBridgeTransaction, SpecificTransaction, IPFSTransaction, type IPFSTransactionContent, type IPFSPayload, type IPFSAddPayload, type IPFSPinPayload, type IPFSUnpinPayload, type IPFSExtendPinPayload, type IPFSOperationType, isIPFSAddPayload, isIPFSPinPayload, isIPFSUnpinPayload, isIPFSExtendPinPayload, isIPFSPayload, ValidatorStakeTransaction, ValidatorStakePayload, ValidatorUnstakeTransaction, ValidatorUnstakePayload, ValidatorExitTransaction, ValidatorExitPayload, NetworkUpgradeTransaction, NetworkUpgradePayload, NetworkUpgradeVoteTransaction, NetworkUpgradeVotePayload, } from "./blockchain/TransactionSubtypes";
8
8
  export { INativePayload } from "./native/INativePayload";
9
9
  export { InstantMessagingPayload } from "./instantMessaging";
10
10
  export { TxFee } from "./blockchain/TxFee";
@@ -30,7 +30,9 @@ export { DataTypes, operators } from "./demoswork/datatypes";
30
30
  export { ConditionalOperationScript, DemosWorkOperationScripts, OperationScript, OperationType, } from "./demoswork/operations";
31
31
  export { ICondition, Conditional, StepOutputKey, WorkStepInput, XmStepResult, stepKeys, stepKeysEnum, } from "./demoswork/steps";
32
32
  export { BrowserRequest, ConsensusRequest, RPCRequest, RPCResponse, HelloPeerRequest, NodeCall, VoteRequest, RPCResponseWithValidityData, emptyResponse as RPCResponseSkeleton, } from "./communication/rpc";
33
- export { GCREdit, GCREditAssign, GCREditAssignIdentity, GCREditBalance, GCREditIdentity, GCREditNonce, GCREditSubnetsTx, GCREditStorageProgram, Web2GCRData, XmGCRData, XmGCRIdentityData, } from "./blockchain/GCREdit";
33
+ export { GCREdit, GCREditAssign, GCREditAssignIdentity, GCREditBalance, GCREditIdentity, GCREditNonce, GCREditSubnetsTx, GCREditStorageProgram, GCREditValidatorStake, GCREditNetworkUpgrade, GCREditNetworkUpgradeVote, Web2GCRData, XmGCRData, XmGCRIdentityData, } from "./blockchain/GCREdit";
34
+ export { type ValidatorInfo, type ValidatorStatus, } from "./validator/ValidatorTypes";
35
+ export { type NetworkParameters, type NetworkParameterKey, type NetworkUpgradeProposal, type ProposalStatus, type ProposalVoteInfo, } from "./blockchain/NetworkParameters";
34
36
  export { BridgeTradePayload } from "./bridge/bridgeTradePayload";
35
37
  export { ChainProviders, SupportedChains, SupportedTokens, } from "./bridge/constants";
36
38
  export { type SigningAlgorithm, type EncryptionAlgorithm } from "./cryptography";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAmBA,gEAAgE;AAChE,OAAO,EAKH,oBAAoB,EACpB,aAAa,GAChB,MAAM,4BAA4B,CAAA;AAEnC,wCAAwC;AACxC,OAAO,EAoBH,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB;AAClB,6CAA6C;AAC7C,sBAAsB,EACtB,aAAa,GAChB,MAAM,kCAAkC,CAAA;AASzC,OAAO,EAAE,aAAa,EAAgB,MAAM,2BAA2B,CAAA;AA6CvE,OAAO;AACP,OAAO,EAaH,eAAe,GAClB,MAAM,QAAQ,CAAA;AAef,OAAO,EAAE,SAAS,EAAa,MAAM,uBAAuB,CAAA;AAO5D,OAAO,EAKH,YAAY,EAEZ,YAAY,GACf,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EASH,aAAa,IAAI,mBAAmB,GACvC,MAAM,qBAAqB,CAAA;AAgB5B,OAAO,EACH,cAAc,EACd,eAAe,EACf,eAAe,GAClB,MAAM,oBAAoB,CAAA;AAY3B,+BAA+B;AAC/B,OAAO,EACH,iBAAiB,EACjB,qBAAqB,GACxB,MAAM,wCAAwC,CAAA;AAmB/C,sEAAsE;AACtE,OAAO;AAgCH,oBAAoB;AACpB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,uBAAuB,EACvB,0BAA0B,EAC1B,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,2BAA2B,EAC3B,cAAc,EACd,aAAa,GAChB,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAmBA,gEAAgE;AAChE,OAAO,EAKH,oBAAoB,EACpB,aAAa,GAChB,MAAM,4BAA4B,CAAA;AAEnC,wCAAwC;AACxC,OAAO,EAoBH,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB;AAClB,6CAA6C;AAC7C,sBAAsB,EACtB,aAAa,GAahB,MAAM,kCAAkC,CAAA;AASzC,OAAO,EAAE,aAAa,EAAgB,MAAM,2BAA2B,CAAA;AA6CvE,OAAO;AACP,OAAO,EAaH,eAAe,GAClB,MAAM,QAAQ,CAAA;AAef,OAAO,EAAE,SAAS,EAAa,MAAM,uBAAuB,CAAA;AAO5D,OAAO,EAKH,YAAY,EAEZ,YAAY,GACf,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EASH,aAAa,IAAI,mBAAmB,GACvC,MAAM,qBAAqB,CAAA;AA8B5B,OAAO,EACH,cAAc,EACd,eAAe,EACf,eAAe,GAClB,MAAM,oBAAoB,CAAA;AAY3B,+BAA+B;AAC/B,OAAO,EACH,iBAAiB,EACjB,qBAAqB,GACxB,MAAM,wCAAwC,CAAA;AAmB/C,sEAAsE;AACtE,OAAO;AAgCH,oBAAoB;AACpB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,uBAAuB,EACvB,0BAA0B,EAC1B,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,2BAA2B,EAC3B,cAAc,EACd,aAAa,GAChB,MAAM,SAAS,CAAA"}
@@ -1,6 +1,11 @@
1
1
  interface INativeSend {
2
2
  nativeOperation: "send";
3
- args: [string, number];
3
+ /**
4
+ * `[to, amount]`. P4 dual-shape: `amount` may be a JS `number` (pre-fork
5
+ * DEM) or decimal `string` (post-fork OS). Internal arithmetic uses
6
+ * `bigint` OS via `denomination` utilities.
7
+ */
8
+ args: [string, number | string];
4
9
  }
5
10
  interface INativeTlsnRequest {
6
11
  nativeOperation: "tlsn_request";
@@ -0,0 +1,13 @@
1
+ /** Status codes written into the Validators table. */
2
+ export type ValidatorStatus = "0" | "2" | "3";
3
+ /** What `getValidatorInfo` / `getValidators` return per row. */
4
+ export interface ValidatorInfo {
5
+ address: string;
6
+ status: ValidatorStatus | string;
7
+ connectionUrl: string | null;
8
+ stakedAmount: string;
9
+ firstSeen: number | null;
10
+ validAt: number | null;
11
+ unstakeRequestedAt: number | null;
12
+ unstakeAvailableAt: number | null;
13
+ }
@@ -0,0 +1,3 @@
1
+ // Validator state as exposed by the node's RPC surface.
2
+ export {};
3
+ //# sourceMappingURL=ValidatorTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidatorTypes.js","sourceRoot":"","sources":["../../../../src/types/validator/ValidatorTypes.ts"],"names":[],"mappings":"AAAA,wDAAwD"}
@@ -21,7 +21,33 @@ export default class Wallet {
21
21
  load(filename: string): Promise<void>;
22
22
  save(filename: string): Promise<void>;
23
23
  getBalance(): Promise<void>;
24
- transfer(to: Address, amount: number, demos: websdk.Demos): Promise<RPCResponseWithValidityData>;
24
+ /**
25
+ * Transfer native DEM tokens to a recipient address.
26
+ *
27
+ * P4 dual-input:
28
+ * - `bigint` (preferred, post-v3): OS amount. 1 DEM = 10^9 OS.
29
+ * - `number` (deprecated, v2 callers): DEM amount, auto-converted.
30
+ *
31
+ * Internal carrier is OS bigint; the serializerGate (run from
32
+ * `demos.sign`) chooses pre-fork vs post-fork wire encoding from
33
+ * the cached `getNetworkInfo` fork status. Sub-DEM precision
34
+ * against a pre-fork node throws `SubDemPrecisionError` from
35
+ * `demos.pay` before any tx construction happens — we delegate to
36
+ * `demos.pay` which carries the guard.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { denomination, websdk, wallet } from "@kynesyslabs/demosdk"
41
+ * const w = wallet.default.getInstance("alice")
42
+ * await w.transfer("0x...", denomination.demToOs(100), demos)
43
+ * await w.transfer("0x...", 100_000_000_000n, demos) // raw OS
44
+ * ```
45
+ *
46
+ * @param to - Recipient address (0x-prefixed hex).
47
+ * @param amount - DEM `number` (legacy) or OS `bigint`.
48
+ * @param demos - Demos client used to sign and submit.
49
+ */
50
+ transfer(to: Address, amount: number | bigint, demos: websdk.Demos): Promise<RPCResponseWithValidityData>;
25
51
  broadcast(validityData: RPCResponseWithValidityData, demos: websdk.Demos): Promise<any>;
26
52
  generatePasskey(): Promise<string>;
27
53
  }
@@ -1,6 +1,5 @@
1
1
  // TODO & REVIEW See if the fs methods are useful in this context or nah (also the public ip)
2
2
  import * as websdk from "../websdk/index.js";
3
- import { DemosTransactions } from "../websdk/index.js";
4
3
  import { PasskeyGenerator } from "./passkeys/passkeys.js";
5
4
  import { Cryptography } from "../encryption/Cryptography.js";
6
5
  class Wallet {
@@ -49,23 +48,37 @@ class Wallet {
49
48
  }
50
49
  /* SECTION Basic writes */
51
50
  // NOTE All the writes return a validity object that needs to be confirmed and broadcasted
51
+ /**
52
+ * Transfer native DEM tokens to a recipient address.
53
+ *
54
+ * P4 dual-input:
55
+ * - `bigint` (preferred, post-v3): OS amount. 1 DEM = 10^9 OS.
56
+ * - `number` (deprecated, v2 callers): DEM amount, auto-converted.
57
+ *
58
+ * Internal carrier is OS bigint; the serializerGate (run from
59
+ * `demos.sign`) chooses pre-fork vs post-fork wire encoding from
60
+ * the cached `getNetworkInfo` fork status. Sub-DEM precision
61
+ * against a pre-fork node throws `SubDemPrecisionError` from
62
+ * `demos.pay` before any tx construction happens — we delegate to
63
+ * `demos.pay` which carries the guard.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import { denomination, websdk, wallet } from "@kynesyslabs/demosdk"
68
+ * const w = wallet.default.getInstance("alice")
69
+ * await w.transfer("0x...", denomination.demToOs(100), demos)
70
+ * await w.transfer("0x...", 100_000_000_000n, demos) // raw OS
71
+ * ```
72
+ *
73
+ * @param to - Recipient address (0x-prefixed hex).
74
+ * @param amount - DEM `number` (legacy) or OS `bigint`.
75
+ * @param demos - Demos client used to sign and submit.
76
+ */
52
77
  async transfer(to, amount, demos) {
53
- let tx = DemosTransactions.empty();
54
- // Putting the right data in the transaction
55
- // tx.content.from = keypair.publicKey.toString("hex")
56
- tx.content.from = demos.keypair.publicKey.toString("hex");
57
- // tx.content.to = to
58
- tx.content.type = "native";
59
- tx.content.data = [
60
- "native",
61
- {
62
- nativeOperation: "send",
63
- args: [to, amount],
64
- },
65
- ];
66
- // tx.content.amount = amount
67
- tx = await demos.sign(tx);
68
- // Sending the transaction and getting the validity data
78
+ // Delegate to demos.pay so we get the sub-DEM guard, the
79
+ // serializerGate, and the canonical native-send tx shape (with
80
+ // nonce, timestamp, gcr_edits, fee derivation) for free.
81
+ const tx = await demos.pay(to, amount);
69
82
  return await demos.confirm(tx);
70
83
  }
71
84
  // TODO Implement other methods too
@@ -1 +1 @@
1
- {"version":3,"file":"Wallet.js","sourceRoot":"","sources":["../../../src/wallet/Wallet.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAI7F,OAAO,KAAK,MAAM,MAAM,UAAU,CAAA;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAA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;OAyBG;IACH,KAAK,CAAC,QAAQ,CACV,EAAW,EACX,MAAuB,EACvB,KAAmB;QAEnB,yDAAyD;QACzD,+DAA+D;QAC/D,yDAAyD;QACzD,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;QACtC,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAClC,CAAC;IAED,mCAAmC;IAEnC,2FAA2F;IAC3F,KAAK,CAAC,SAAS,CACX,YAAyC,EACzC,KAAmB;QAEnB,OAAO,MAAM,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;IAC9C,CAAC;IAED,0BAA0B;IAC1B,KAAK,CAAC,eAAe;QACjB,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAA;QAC/C,OAAO,MAAM,gBAAgB,CAAC,QAAQ,EAAE,CAAA;IAC5C,CAAC;;AA1HD,yGAAyG;AAC1F,gBAAS,GAA8B,EAAE,CAAA;eAFvC,MAAM"}
@@ -1,5 +1,6 @@
1
1
  import { Demos } from "./demosclass";
2
2
  import type { SigningAlgorithm, Transaction } from "../types";
3
+ import type { NetworkParameters } from "../types/blockchain/NetworkParameters";
3
4
  import { IKeyPair } from "./types/KeyPair";
4
5
  import { RPCResponse, RPCResponseWithValidityData } from "../types/communication/rpc";
5
6
  export declare const DemosTransactions: {
@@ -8,23 +9,49 @@ export declare const DemosTransactions: {
8
9
  /**
9
10
  * Create a signed DEMOS transaction to send native tokens to a given address.
10
11
  *
12
+ * P4 dual-input:
13
+ * - `bigint`: OS amount (preferred — 1 DEM = 10^9 OS).
14
+ * - `number`: DEM amount (legacy, deprecated). Auto-converted to OS.
15
+ *
16
+ * Internal carrier in `tx.content.amount` is bigint OS; the
17
+ * serializerGate (run from `demos.sign`) emits the right wire shape
18
+ * per the connected node's fork status.
19
+ *
11
20
  * @param to - The reciever
12
- * @param amount - The amount in DEM
21
+ * @param amount - DEM `number` (legacy) or OS `bigint`.
13
22
  * @param demos - The demos instance (for getting the address nonce)
14
23
  *
15
24
  * @returns The signed transaction.
16
25
  */
17
- pay(to: string, amount: number, demos: Demos): Promise<Transaction>;
26
+ pay(to: string, amount: number | bigint, demos: Demos): Promise<Transaction>;
27
+ /**
28
+ * Convert a legacy DEM `number` input to an OS `bigint` for internal
29
+ * carrying. Only whole-DEM `number` inputs are accepted on this
30
+ * legacy path — fractional DEM is rejected with a clear error
31
+ * directing callers to the bigint OS path (`denomination.demToOs`).
32
+ *
33
+ * Rationale: silently flooring (the previous behaviour) discarded up
34
+ * to ~10^9 OS per call without warning. The migration period
35
+ * tolerates legacy `number` callers, but only at exact DEM
36
+ * granularity — anything sub-DEM must come in as `bigint` so the
37
+ * caller has explicitly opted into OS arithmetic.
38
+ *
39
+ * @internal
40
+ */
41
+ _demNumberToOsBigint(amountDem: number): bigint;
18
42
  /**
19
43
  * Create a signed DEMOS transaction to send native tokens to a given address.
20
44
  *
45
+ * Alias of {@link pay}. Same dual-input semantics — `bigint` OS
46
+ * preferred, `number` DEM accepted as the deprecated path.
47
+ *
21
48
  * @param to - The reciever
22
- * @param amount - The amount in DEM
49
+ * @param amount - DEM `number` (legacy) or OS `bigint`.
23
50
  * @param demos - The demos instance (for getting the address nonce)
24
51
  *
25
52
  * @returns The signed transaction.
26
53
  */
27
- transfer(to: string, amount: number, demos: Demos): Promise<Transaction>;
54
+ transfer(to: string, amount: number | bigint, demos: Demos): Promise<Transaction>;
28
55
  /**
29
56
  * Signs a transaction after hashing its content.
30
57
  *
@@ -144,4 +171,51 @@ export declare const DemosTransactions: {
144
171
  * ```
145
172
  */
146
173
  createL2PSHashUpdate(l2psUid: string, consolidatedHash: string, transactionCount: number, demos: Demos): Promise<Transaction>;
174
+ /**
175
+ * Create a signed `validatorStake` transaction. Used both for initial
176
+ * validator registration and to top up an existing stake.
177
+ *
178
+ * @param amount - Stake amount in base-unit DEMOS, encoded as a bigint string.
179
+ * @param connectionUrl - Validator's public endpoint (required on first stake;
180
+ * subsequent top-ups may overwrite it).
181
+ * @param demos - The demos instance (for nonce + signing).
182
+ */
183
+ stake(amount: string, connectionUrl: string, demos: Demos): Promise<Transaction>;
184
+ /**
185
+ * Create a signed `validatorUnstake` transaction. Arms the unstake lock
186
+ * period; after `UNSTAKE_LOCK_BLOCKS` have elapsed the validator may call
187
+ * `validatorExit`.
188
+ */
189
+ unstake(demos: Demos): Promise<Transaction>;
190
+ /**
191
+ * Create a signed `validatorExit` transaction. Only accepted by the
192
+ * network once `unstake_available_at <= currentBlock`.
193
+ */
194
+ validatorExit(demos: Demos): Promise<Transaction>;
195
+ /**
196
+ * Create a signed `networkUpgrade` proposal transaction.
197
+ *
198
+ * Only active validators may propose. The node rejects proposals whose
199
+ * `proposedParameters` violate safety bounds (≤50% change, absolute
200
+ * floor/ceiling) or overlap keys with other pending/activating proposals.
201
+ *
202
+ * @param params.proposalId - UUID. Also used as lexicographic activation-order tiebreaker.
203
+ * @param params.proposedParameters - Subset of NetworkParameters to change.
204
+ * @param params.rationale - Human-readable reason, ≤1024 bytes.
205
+ * @param params.effectiveAtBlock - Activation block. Must be ≥ tallyBlock + grace period.
206
+ */
207
+ proposeNetworkUpgrade(params: {
208
+ proposalId: string;
209
+ proposedParameters: Partial<NetworkParameters>;
210
+ rationale: string;
211
+ effectiveAtBlock: number;
212
+ }, demos: Demos): Promise<Transaction>;
213
+ /**
214
+ * Create a signed `networkUpgradeVote` transaction.
215
+ *
216
+ * The voter must be in the validator snapshot taken at the proposal's
217
+ * confirmation block, and may cast exactly one vote per proposal (final,
218
+ * non-revocable).
219
+ */
220
+ voteOnUpgrade(proposalId: string, approve: boolean, demos: Demos): Promise<Transaction>;
147
221
  };