@kynesyslabs/demosdk 4.0.11 → 4.0.13

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 (82) hide show
  1. package/build/abstraction/Identities.js +10 -2
  2. package/build/abstraction/Identities.js.map +1 -1
  3. package/build/l2ps/channel/finalize.d.ts +63 -0
  4. package/build/l2ps/channel/finalize.js +85 -0
  5. package/build/l2ps/channel/finalize.js.map +1 -0
  6. package/build/l2ps/channel/index.d.ts +3 -0
  7. package/build/l2ps/channel/index.js +3 -0
  8. package/build/l2ps/channel/index.js.map +1 -1
  9. package/build/l2ps/channel/negotiate.d.ts +106 -0
  10. package/build/l2ps/channel/negotiate.js +206 -0
  11. package/build/l2ps/channel/negotiate.js.map +1 -0
  12. package/build/l2ps/channel/transport.d.ts +117 -0
  13. package/build/l2ps/channel/transport.js +178 -0
  14. package/build/l2ps/channel/transport.js.map +1 -0
  15. package/build/websdk/BroadcastFailedError.js.map +1 -1
  16. package/build/websdk/DemosTransactions.d.ts +2 -2
  17. package/build/websdk/DemosTransactions.js +3 -3
  18. package/build/websdk/TransportError.js.map +1 -1
  19. package/build/websdk/demosclass.d.ts +81 -1
  20. package/build/websdk/demosclass.js +84 -1
  21. package/build/websdk/demosclass.js.map +1 -1
  22. package/build/websdk/index.d.ts +1 -0
  23. package/build/websdk/index.js +3 -0
  24. package/build/websdk/index.js.map +1 -1
  25. package/build/websdk/programmatic/ProgrammaticTx.d.ts +118 -0
  26. package/build/websdk/programmatic/ProgrammaticTx.js +56 -0
  27. package/build/websdk/programmatic/ProgrammaticTx.js.map +1 -0
  28. package/build/websdk/programmatic/attest.d.ts +396 -0
  29. package/build/websdk/programmatic/attest.js +398 -0
  30. package/build/websdk/programmatic/attest.js.map +1 -0
  31. package/build/websdk/programmatic/bridge.d.ts +36 -0
  32. package/build/websdk/programmatic/bridge.js +37 -0
  33. package/build/websdk/programmatic/bridge.js.map +1 -0
  34. package/build/websdk/programmatic/context.d.ts +26 -0
  35. package/build/websdk/programmatic/context.js +9 -0
  36. package/build/websdk/programmatic/context.js.map +1 -0
  37. package/build/websdk/programmatic/contracts.d.ts +79 -0
  38. package/build/websdk/programmatic/contracts.js +81 -0
  39. package/build/websdk/programmatic/contracts.js.map +1 -0
  40. package/build/websdk/programmatic/d402.d.ts +33 -0
  41. package/build/websdk/programmatic/d402.js +35 -0
  42. package/build/websdk/programmatic/d402.js.map +1 -0
  43. package/build/websdk/programmatic/demoswork.d.ts +37 -0
  44. package/build/websdk/programmatic/demoswork.js +38 -0
  45. package/build/websdk/programmatic/demoswork.js.map +1 -0
  46. package/build/websdk/programmatic/errors.d.ts +20 -0
  47. package/build/websdk/programmatic/errors.js +24 -0
  48. package/build/websdk/programmatic/errors.js.map +1 -0
  49. package/build/websdk/programmatic/escrow.d.ts +75 -0
  50. package/build/websdk/programmatic/escrow.js +74 -0
  51. package/build/websdk/programmatic/escrow.js.map +1 -0
  52. package/build/websdk/programmatic/governance.d.ts +59 -0
  53. package/build/websdk/programmatic/governance.js +44 -0
  54. package/build/websdk/programmatic/governance.js.map +1 -0
  55. package/build/websdk/programmatic/index.d.ts +30 -0
  56. package/build/websdk/programmatic/index.js +31 -0
  57. package/build/websdk/programmatic/index.js.map +1 -0
  58. package/build/websdk/programmatic/ipfs.d.ts +74 -0
  59. package/build/websdk/programmatic/ipfs.js +103 -0
  60. package/build/websdk/programmatic/ipfs.js.map +1 -0
  61. package/build/websdk/programmatic/pay.d.ts +36 -0
  62. package/build/websdk/programmatic/pay.js +37 -0
  63. package/build/websdk/programmatic/pay.js.map +1 -0
  64. package/build/websdk/programmatic/runner.d.ts +30 -0
  65. package/build/websdk/programmatic/runner.js +186 -0
  66. package/build/websdk/programmatic/runner.js.map +1 -0
  67. package/build/websdk/programmatic/storage.d.ts +49 -0
  68. package/build/websdk/programmatic/storage.js +49 -0
  69. package/build/websdk/programmatic/storage.js.map +1 -0
  70. package/build/websdk/programmatic/tokens.d.ts +155 -0
  71. package/build/websdk/programmatic/tokens.js +157 -0
  72. package/build/websdk/programmatic/tokens.js.map +1 -0
  73. package/build/websdk/programmatic/types.d.ts +95 -0
  74. package/build/websdk/programmatic/types.js +8 -0
  75. package/build/websdk/programmatic/types.js.map +1 -0
  76. package/build/websdk/programmatic/validator.d.ts +63 -0
  77. package/build/websdk/programmatic/validator.js +64 -0
  78. package/build/websdk/programmatic/validator.js.map +1 -0
  79. package/build/websdk/programmatic/xm.d.ts +36 -0
  80. package/build/websdk/programmatic/xm.js +37 -0
  81. package/build/websdk/programmatic/xm.js.map +1 -0
  82. package/package.json +1 -1
@@ -0,0 +1,74 @@
1
+ import { type AddOptionsWithCharges, type PinOptionsWithCharges } from "../../ipfs";
2
+ import type { ProgrammaticContext } from "./context";
3
+ import type { ProgrammaticTxOptions, ProgrammaticTxResult } from "./types";
4
+ /**
5
+ * IPFS operations as one-call programmatic transactions.
6
+ *
7
+ * Unlike `pay`/`store`/`storagePrograms`, there is no single Demos builder
8
+ * that returns a signed `ipfs` transaction: the payloads come from
9
+ * {@link IPFSOperations}' static creators (`createAddPayload`,
10
+ * `createPinPayload`, `createUnpinPayload`) and the caller must assemble the
11
+ * transaction around them. This namespace does that assembly.
12
+ *
13
+ * Each method builds the payload, wraps it in an UNSIGNED `ipfs` transaction
14
+ * (nonce set exactly like `demos.storagePrograms.sign`), and hands a thunk
15
+ * producing it to `ctx.run(...)`. The shared runner signs it and confirms it
16
+ * against the fee ceiling before auto-broadcasting — keeping fee-cap policy,
17
+ * confirmation strategy and result shape uniform with the rest of
18
+ * `demos.run.*`.
19
+ *
20
+ * Cost control ("custom charges") is opt-in and stays simple: forward a
21
+ * `customCharges` block through `addOptions`/`pinOptions` (obtained from
22
+ * `IPFSOperations.quoteToCustomCharges(await demos.ipfs.quote(...))`). The
23
+ * payload creators embed it in the payload; this namespace additionally
24
+ * mirrors it onto `tx.content.custom_charges` so the node sees the ceiling
25
+ * the sender signed. No quote round-trip is performed here.
26
+ */
27
+ export declare function createIpfsNamespace(ctx: ProgrammaticContext): {
28
+ /**
29
+ * Upload content to IPFS (and auto-pin it), end to end.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * // auto-broadcast within the 5 DEM fee cap:
34
+ * await demos.run.ipfs.add("hello world", { filename: "hello.txt" })
35
+ *
36
+ * // with a signed cost ceiling from a quote:
37
+ * const quote = await demos.ipfs.quote(bytes.length, "IPFS_ADD")
38
+ * await demos.run.ipfs.add(bytes, {
39
+ * customCharges: IPFSOperations.quoteToCustomCharges(quote),
40
+ * })
41
+ * ```
42
+ *
43
+ * @param content - Content to upload (Buffer, Uint8Array or string).
44
+ * @param addOptions - Filename, metadata and optional custom charges.
45
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
46
+ */
47
+ add: (content: Buffer | Uint8Array | string, addOptions?: AddOptionsWithCharges, opts?: ProgrammaticTxOptions) => Promise<ProgrammaticTxResult>;
48
+ /**
49
+ * Pin an existing CID to the sender's account, end to end.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * await demos.run.ipfs.pin("QmExampleCID...")
54
+ * ```
55
+ *
56
+ * @param cid - The Content Identifier to pin (CIDv0 or CIDv1).
57
+ * @param pinOptions - Duration, metadata, `fileSize` and optional
58
+ * custom charges.
59
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
60
+ */
61
+ pin: (cid: string, pinOptions?: PinOptionsWithCharges, opts?: ProgrammaticTxOptions) => Promise<ProgrammaticTxResult>;
62
+ /**
63
+ * Remove a pin from the sender's account, end to end.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * await demos.run.ipfs.unpin("QmExampleCID...")
68
+ * ```
69
+ *
70
+ * @param cid - The Content Identifier to unpin (CIDv0 or CIDv1).
71
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
72
+ */
73
+ unpin: (cid: string, opts?: ProgrammaticTxOptions) => Promise<ProgrammaticTxResult>;
74
+ };
@@ -0,0 +1,103 @@
1
+ import { uint8ArrayToHex } from "../../encryption/unifiedCrypto.js";
2
+ import { IPFSOperations, } from "../../ipfs/index.js";
3
+ import { DemosTransactions } from "../DemosTransactions.js";
4
+ /**
5
+ * IPFS operations as one-call programmatic transactions.
6
+ *
7
+ * Unlike `pay`/`store`/`storagePrograms`, there is no single Demos builder
8
+ * that returns a signed `ipfs` transaction: the payloads come from
9
+ * {@link IPFSOperations}' static creators (`createAddPayload`,
10
+ * `createPinPayload`, `createUnpinPayload`) and the caller must assemble the
11
+ * transaction around them. This namespace does that assembly.
12
+ *
13
+ * Each method builds the payload, wraps it in an UNSIGNED `ipfs` transaction
14
+ * (nonce set exactly like `demos.storagePrograms.sign`), and hands a thunk
15
+ * producing it to `ctx.run(...)`. The shared runner signs it and confirms it
16
+ * against the fee ceiling before auto-broadcasting — keeping fee-cap policy,
17
+ * confirmation strategy and result shape uniform with the rest of
18
+ * `demos.run.*`.
19
+ *
20
+ * Cost control ("custom charges") is opt-in and stays simple: forward a
21
+ * `customCharges` block through `addOptions`/`pinOptions` (obtained from
22
+ * `IPFSOperations.quoteToCustomCharges(await demos.ipfs.quote(...))`). The
23
+ * payload creators embed it in the payload; this namespace additionally
24
+ * mirrors it onto `tx.content.custom_charges` so the node sees the ceiling
25
+ * the sender signed. No quote round-trip is performed here.
26
+ */
27
+ export function createIpfsNamespace(ctx) {
28
+ /**
29
+ * Assemble an UNSIGNED `ipfs` transaction around a ready IPFS payload.
30
+ *
31
+ * Replicates the nonce pattern from `demos.storagePrograms.sign`: read the
32
+ * sender's ed25519 public key, fetch its on-chain nonce and set
33
+ * `content.nonce = nonce + 1`. The transaction is returned unsigned; the
34
+ * shared runner signs it.
35
+ *
36
+ * @param payload - An IPFS payload from an `IPFSOperations.create*` method.
37
+ * @returns The unsigned `ipfs` transaction, ready for `ctx.run`.
38
+ */
39
+ const buildIpfsTx = async (payload) => {
40
+ const { publicKey } = await ctx.demos.crypto.getIdentity("ed25519");
41
+ const nonce = await ctx.demos.getAddressNonce(uint8ArrayToHex(publicKey));
42
+ const tx = DemosTransactions.empty();
43
+ tx.content.type = "ipfs";
44
+ tx.content.nonce = nonce + 1;
45
+ tx.content.data = ["ipfs", payload];
46
+ // Mirror the signed cost ceiling onto the transaction content when the
47
+ // payload carries one, so the node enforces the same `max_cost_os` the
48
+ // sender agreed to. `IPFSUnpinPayload` never has this field.
49
+ if ("custom_charges" in payload && payload.custom_charges) {
50
+ tx.content.custom_charges = payload.custom_charges;
51
+ }
52
+ return tx;
53
+ };
54
+ return {
55
+ /**
56
+ * Upload content to IPFS (and auto-pin it), end to end.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * // auto-broadcast within the 5 DEM fee cap:
61
+ * await demos.run.ipfs.add("hello world", { filename: "hello.txt" })
62
+ *
63
+ * // with a signed cost ceiling from a quote:
64
+ * const quote = await demos.ipfs.quote(bytes.length, "IPFS_ADD")
65
+ * await demos.run.ipfs.add(bytes, {
66
+ * customCharges: IPFSOperations.quoteToCustomCharges(quote),
67
+ * })
68
+ * ```
69
+ *
70
+ * @param content - Content to upload (Buffer, Uint8Array or string).
71
+ * @param addOptions - Filename, metadata and optional custom charges.
72
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
73
+ */
74
+ add: (content, addOptions, opts) => ctx.run(() => buildIpfsTx(IPFSOperations.createAddPayload(content, addOptions)), opts),
75
+ /**
76
+ * Pin an existing CID to the sender's account, end to end.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * await demos.run.ipfs.pin("QmExampleCID...")
81
+ * ```
82
+ *
83
+ * @param cid - The Content Identifier to pin (CIDv0 or CIDv1).
84
+ * @param pinOptions - Duration, metadata, `fileSize` and optional
85
+ * custom charges.
86
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
87
+ */
88
+ pin: (cid, pinOptions, opts) => ctx.run(() => buildIpfsTx(IPFSOperations.createPinPayload(cid, pinOptions)), opts),
89
+ /**
90
+ * Remove a pin from the sender's account, end to end.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * await demos.run.ipfs.unpin("QmExampleCID...")
95
+ * ```
96
+ *
97
+ * @param cid - The Content Identifier to unpin (CIDv0 or CIDv1).
98
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
99
+ */
100
+ unpin: (cid, opts) => ctx.run(() => buildIpfsTx(IPFSOperations.createUnpinPayload(cid)), opts),
101
+ };
102
+ }
103
+ //# sourceMappingURL=ipfs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ipfs.js","sourceRoot":"","sources":["../../../../src/websdk/programmatic/ipfs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EACH,cAAc,GAIjB,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAIxD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAwB;IACxD;;;;;;;;;;OAUG;IACH,MAAM,WAAW,GAAG,KAAK,EAAE,OAAoB,EAAwB,EAAE;QACrE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAA;QACnE,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,eAAe,CACzC,eAAe,CAAC,SAAuB,CAAC,CAC3C,CAAA;QAED,MAAM,EAAE,GAAG,iBAAiB,CAAC,KAAK,EAAE,CAAA;QACpC,EAAE,CAAC,OAAO,CAAC,IAAI,GAAG,MAAM,CAAA;QACxB,EAAE,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,GAAG,CAAC,CAAA;QAC5B,EAAE,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAEnC,uEAAuE;QACvE,uEAAuE;QACvE,6DAA6D;QAC7D,IAAI,gBAAgB,IAAI,OAAO,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;YACxD,EAAE,CAAC,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;QACtD,CAAC;QAED,OAAO,EAAE,CAAA;IACb,CAAC,CAAA;IAED,OAAO;QACH;;;;;;;;;;;;;;;;;;WAkBG;QACH,GAAG,EAAE,CACD,OAAqC,EACrC,UAAkC,EAClC,IAA4B,EACC,EAAE,CAC/B,GAAG,CAAC,GAAG,CACH,GAAG,EAAE,CACD,WAAW,CACP,cAAc,CAAC,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC,CACvD,EACL,IAAI,CACP;QAEL;;;;;;;;;;;;WAYG;QACH,GAAG,EAAE,CACD,GAAW,EACX,UAAkC,EAClC,IAA4B,EACC,EAAE,CAC/B,GAAG,CAAC,GAAG,CACH,GAAG,EAAE,CACD,WAAW,CACP,cAAc,CAAC,gBAAgB,CAAC,GAAG,EAAE,UAAU,CAAC,CACnD,EACL,IAAI,CACP;QAEL;;;;;;;;;;WAUG;QACH,KAAK,EAAE,CACH,GAAW,EACX,IAA4B,EACC,EAAE,CAC/B,GAAG,CAAC,GAAG,CACH,GAAG,EAAE,CAAC,WAAW,CAAC,cAAc,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,EACzD,IAAI,CACP;KACR,CAAA;AACL,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { ProgrammaticContext } from "./context";
2
+ import type { ProgrammaticTxOptions, ProgrammaticTxResult } from "./types";
3
+ /**
4
+ * Native-value transfers as one-call programmatic transactions.
5
+ *
6
+ * Collapses the classic `pay → confirm → broadcast` flow into a single call
7
+ * that auto-broadcasts within the configured fee ceiling.
8
+ */
9
+ export declare function createPayNamespace(ctx: ProgrammaticContext): {
10
+ /**
11
+ * Send native DEMOS tokens to an address, end to end.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { denomination } from "@kynesyslabs/demosdk"
16
+ * // auto-broadcast within the 5 DEM fee cap:
17
+ * await demos.run.pay("0x...", denomination.demToOs(100))
18
+ * // build + confirm only, broadcast later yourself:
19
+ * const r = await demos.run.pay("0x...", 100n, { confirm: "manual" })
20
+ * await demos.broadcast(r.validityData)
21
+ * ```
22
+ *
23
+ * @param to - Receiver address (0x-prefixed hex).
24
+ * @param amount - DEM `number` (legacy) or OS `bigint` (preferred).
25
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
26
+ */
27
+ pay: (to: string, amount: number | bigint, opts?: ProgrammaticTxOptions) => Promise<ProgrammaticTxResult>;
28
+ /**
29
+ * Alias of {@link pay}. Same dual-input amount semantics.
30
+ *
31
+ * @param to - Receiver address (0x-prefixed hex).
32
+ * @param amount - DEM `number` (legacy) or OS `bigint` (preferred).
33
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
34
+ */
35
+ transfer: (to: string, amount: number | bigint, opts?: ProgrammaticTxOptions) => Promise<ProgrammaticTxResult>;
36
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Native-value transfers as one-call programmatic transactions.
3
+ *
4
+ * Collapses the classic `pay → confirm → broadcast` flow into a single call
5
+ * that auto-broadcasts within the configured fee ceiling.
6
+ */
7
+ export function createPayNamespace(ctx) {
8
+ return {
9
+ /**
10
+ * Send native DEMOS tokens to an address, end to end.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { denomination } from "@kynesyslabs/demosdk"
15
+ * // auto-broadcast within the 5 DEM fee cap:
16
+ * await demos.run.pay("0x...", denomination.demToOs(100))
17
+ * // build + confirm only, broadcast later yourself:
18
+ * const r = await demos.run.pay("0x...", 100n, { confirm: "manual" })
19
+ * await demos.broadcast(r.validityData)
20
+ * ```
21
+ *
22
+ * @param to - Receiver address (0x-prefixed hex).
23
+ * @param amount - DEM `number` (legacy) or OS `bigint` (preferred).
24
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
25
+ */
26
+ pay: (to, amount, opts) => ctx.run(() => ctx.demos.pay(to, amount), opts),
27
+ /**
28
+ * Alias of {@link pay}. Same dual-input amount semantics.
29
+ *
30
+ * @param to - Receiver address (0x-prefixed hex).
31
+ * @param amount - DEM `number` (legacy) or OS `bigint` (preferred).
32
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
33
+ */
34
+ transfer: (to, amount, opts) => ctx.run(() => ctx.demos.transfer(to, amount), opts),
35
+ };
36
+ }
37
+ //# sourceMappingURL=pay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pay.js","sourceRoot":"","sources":["../../../../src/websdk/programmatic/pay.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAwB;IACvD,OAAO;QACH;;;;;;;;;;;;;;;;WAgBG;QACH,GAAG,EAAE,CACD,EAAU,EACV,MAAuB,EACvB,IAA4B,EACC,EAAE,CAC/B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC;QAElD;;;;;;WAMG;QACH,QAAQ,EAAE,CACN,EAAU,EACV,MAAuB,EACvB,IAA4B,EACC,EAAE,CAC/B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC;KAC1D,CAAA;AACL,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { RPCResponseWithValidityData } from "../../types/communication/rpc";
2
+ import type { Demos } from "../demosclass";
3
+ import { type ProgrammaticTxOptions, type ProgrammaticTxResult, type TxSource } from "./types";
4
+ /**
5
+ * Sum `network_fee + rpc_fee + additional_fee` into a single OS `bigint`.
6
+ *
7
+ * The fee is read from the node's confirm response. Two shapes are handled:
8
+ * - `gas_operation.fees` — the node's authoritative gas operation, when the
9
+ * node populates it (post-fork gas-separation model), preferred; else
10
+ * - `transaction.content.transaction_fee` — the fee carried on the confirmed
11
+ * transaction itself, which live nodes return with `gas_operation: null`.
12
+ *
13
+ * Returns `0n` when neither is present (fee not exposed at confirm time).
14
+ */
15
+ export declare function totalFeeOs(validityData: RPCResponseWithValidityData): bigint;
16
+ /**
17
+ * The shared programmatic-transaction runner — the single place where
18
+ * `confirm → (fee cap / callback) → broadcast` lives.
19
+ *
20
+ * Every typed one-call method (`demos.run.pay`, `demos.run.attest.*`,
21
+ * `demos.run.tokens.*`, …) builds/signs its transaction and hands it here,
22
+ * so confirmation policy and result shape are uniform across the SDK.
23
+ *
24
+ * @param demos - The connected Demos instance.
25
+ * @param source - A signed/unsigned tx, an already-confirmed validityData,
26
+ * or a thunk producing either.
27
+ * @param opts - Fee ceiling, confirmation strategy and wait behaviour.
28
+ * @returns A uniform {@link ProgrammaticTxResult}.
29
+ */
30
+ export declare function runProgrammaticTx(demos: Demos, source: TxSource, opts?: ProgrammaticTxOptions): Promise<ProgrammaticTxResult>;
@@ -0,0 +1,186 @@
1
+ import { demToOs, osToDem } from "../../denomination/index.js";
2
+ import { FeeCapExceededError } from "./errors.js";
3
+ import { DEFAULT_MAX_FEE_DEM, } from "./types.js";
4
+ /**
5
+ * Normalise a single {@link TxFee} field to OS (`bigint`).
6
+ *
7
+ * Wire-format compatibility (see `TxFee` docs):
8
+ * - pre-fork node: `number` in DEM,
9
+ * - post-fork node: decimal `string` in OS.
10
+ *
11
+ * A defensive `"."`-in-string branch treats decimal strings as DEM so a
12
+ * mixed/legacy shape can never be misread as a huge OS integer.
13
+ */
14
+ function feeFieldToOs(value) {
15
+ if (value == null)
16
+ return 0n;
17
+ try {
18
+ if (typeof value === "number")
19
+ return demToOs(value);
20
+ const s = value.trim();
21
+ if (s === "")
22
+ return 0n;
23
+ // Decimal string ⇒ DEM (human) shape; integer string ⇒ OS (wire) shape.
24
+ return s.includes(".") ? demToOs(s) : BigInt(s);
25
+ }
26
+ catch {
27
+ // The value comes from the node's confirm response — surface which
28
+ // field/shape failed instead of a bare BigInt/demToOs SyntaxError.
29
+ throw new Error(`[programmatic-tx] unparseable fee field ${JSON.stringify(value)} in the node's confirm response`);
30
+ }
31
+ }
32
+ /**
33
+ * Sum `network_fee + rpc_fee + additional_fee` into a single OS `bigint`.
34
+ *
35
+ * The fee is read from the node's confirm response. Two shapes are handled:
36
+ * - `gas_operation.fees` — the node's authoritative gas operation, when the
37
+ * node populates it (post-fork gas-separation model), preferred; else
38
+ * - `transaction.content.transaction_fee` — the fee carried on the confirmed
39
+ * transaction itself, which live nodes return with `gas_operation: null`.
40
+ *
41
+ * Returns `0n` when neither is present (fee not exposed at confirm time).
42
+ */
43
+ export function totalFeeOs(validityData) {
44
+ const data = validityData?.response?.data;
45
+ const fees = (data?.gas_operation?.fees ??
46
+ data?.transaction?.content?.transaction_fee);
47
+ if (!fees)
48
+ return 0n;
49
+ return (feeFieldToOs(fees.network_fee) +
50
+ feeFieldToOs(fees.rpc_fee) +
51
+ feeFieldToOs(fees.additional_fee));
52
+ }
53
+ /**
54
+ * Resolve the configured fee ceiling to OS. Returns `null` when the cap is
55
+ * disabled — only `null` or `Infinity` disable it. `undefined` falls back to
56
+ * the default ceiling. Any other value (including `NaN` or a non-numeric
57
+ * string) is routed through `demToOs`, which throws loudly: silently
58
+ * disabling the cap on a `NaN` from `Number(userInput)` would remove the very
59
+ * safety this feature promises.
60
+ */
61
+ function resolveCapOs(maxFee) {
62
+ if (maxFee === null)
63
+ return null;
64
+ if (maxFee === undefined)
65
+ return demToOs(DEFAULT_MAX_FEE_DEM);
66
+ if (maxFee === Infinity)
67
+ return null;
68
+ return demToOs(maxFee);
69
+ }
70
+ /** Distinguish an already-confirmed validity-data object from a Transaction. */
71
+ function isValidityData(v) {
72
+ return (v != null &&
73
+ typeof v === "object" &&
74
+ "response" in v &&
75
+ v.response?.data != null);
76
+ }
77
+ /**
78
+ * Turn any {@link TxSource} into an `RPCResponseWithValidityData`:
79
+ * - a thunk is invoked,
80
+ * - an already-confirmed value is returned as-is (pattern B, e.g. the
81
+ * `Identities.*` builders),
82
+ * - a `Transaction` is signed if needed, then confirmed (pattern A).
83
+ */
84
+ async function resolveToConfirmed(demos, source) {
85
+ const resolved = typeof source === "function" ? await source() : source;
86
+ if (isValidityData(resolved)) {
87
+ return resolved;
88
+ }
89
+ const tx = resolved;
90
+ // A tx counts as signed only when its signature actually carries data.
91
+ // Some builders (e.g. DemosTokens) return an UNSIGNED tx with a truthy
92
+ // placeholder `signature: { type: "ed25519", data: "" }`, so a bare
93
+ // `tx.signature` truthiness check would wrongly skip signing and confirm
94
+ // an empty-signature tx. Gate on the signature payload instead.
95
+ const sig = tx.signature;
96
+ const isSigned = !!(sig && sig.data);
97
+ const signed = isSigned ? tx : await demos.sign(tx);
98
+ return await demos.confirm(signed);
99
+ }
100
+ /**
101
+ * The shared programmatic-transaction runner — the single place where
102
+ * `confirm → (fee cap / callback) → broadcast` lives.
103
+ *
104
+ * Every typed one-call method (`demos.run.pay`, `demos.run.attest.*`,
105
+ * `demos.run.tokens.*`, …) builds/signs its transaction and hands it here,
106
+ * so confirmation policy and result shape are uniform across the SDK.
107
+ *
108
+ * @param demos - The connected Demos instance.
109
+ * @param source - A signed/unsigned tx, an already-confirmed validityData,
110
+ * or a thunk producing either.
111
+ * @param opts - Fee ceiling, confirmation strategy and wait behaviour.
112
+ * @returns A uniform {@link ProgrammaticTxResult}.
113
+ */
114
+ export async function runProgrammaticTx(demos, source, opts = {}) {
115
+ const validityData = await resolveToConfirmed(demos, source);
116
+ const transaction = validityData.response.data.transaction;
117
+ // A successful confirm always echoes the transaction; guard so the
118
+ // non-optional `transaction`/`hash` on the result types stay truthful
119
+ // (rather than silently handing callers `undefined.hash`).
120
+ if (!transaction) {
121
+ throw new Error("[programmatic-tx] confirm response did not include a transaction");
122
+ }
123
+ const hash = transaction.hash;
124
+ const referenceBlock = validityData.response.data.reference_block;
125
+ const feeOs = totalFeeOs(validityData);
126
+ const feeDem = osToDem(feeOs);
127
+ const capOs = resolveCapOs(opts.maxFee);
128
+ const withinFeeCap = capOs === null || feeOs <= capOs;
129
+ const info = {
130
+ transaction,
131
+ validityData,
132
+ feeOs,
133
+ feeDem,
134
+ withinFeeCap,
135
+ referenceBlock,
136
+ };
137
+ const mode = opts.confirm ?? "auto";
138
+ // "manual": stop after confirm, hand back the validity data unbroadcast.
139
+ if (mode === "manual") {
140
+ return {
141
+ broadcasted: false,
142
+ skippedReason: "manual",
143
+ transaction,
144
+ hash,
145
+ validityData,
146
+ feeOs,
147
+ feeDem,
148
+ };
149
+ }
150
+ // Decide whether to broadcast.
151
+ let allowed;
152
+ if (typeof mode === "function") {
153
+ allowed = await mode(info);
154
+ }
155
+ else {
156
+ // "auto": enforce the fee ceiling loudly.
157
+ if (!withinFeeCap) {
158
+ throw new FeeCapExceededError(feeOs, capOs, info);
159
+ }
160
+ allowed = true;
161
+ }
162
+ if (!allowed) {
163
+ return {
164
+ broadcasted: false,
165
+ skippedReason: "rejected",
166
+ transaction,
167
+ hash,
168
+ validityData,
169
+ feeOs,
170
+ feeDem,
171
+ };
172
+ }
173
+ const broadcast = opts.wait
174
+ ? await demos.broadcastAndWait(validityData, opts.waitOptions)
175
+ : await demos.broadcast(validityData);
176
+ return {
177
+ broadcasted: true,
178
+ transaction,
179
+ hash,
180
+ validityData,
181
+ broadcast,
182
+ feeOs,
183
+ feeDem,
184
+ };
185
+ }
186
+ //# sourceMappingURL=runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../../src/websdk/programmatic/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAKjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,EACH,mBAAmB,GAKtB,MAAM,SAAS,CAAA;AAEhB;;;;;;;;;GASG;AACH,SAAS,YAAY,CAAC,KAAyC;IAC3D,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,EAAE,CAAA;IAC5B,IAAI,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,OAAO,CAAC,KAA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X,IAAI;YACJ,YAAY;YACZ,KAAK;YACL,MAAM;SACT,CAAA;IACL,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI;QACvB,CAAC,CAAC,MAAM,KAAK,CAAC,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC,WAAW,CAAC;QAC9D,CAAC,CAAC,MAAM,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;IAEzC,OAAO;QACH,WAAW,EAAE,IAAI;QACjB,WAAW;QACX,IAAI;QACJ,YAAY;QACZ,SAAS;QACT,KAAK;QACL,MAAM;KACT,CAAA;AACL,CAAC"}
@@ -0,0 +1,49 @@
1
+ import type { StorageProgramPayload } from "../../storage";
2
+ import type { ProgrammaticContext } from "./context";
3
+ import type { ProgrammaticTxOptions, ProgrammaticTxResult } from "./types";
4
+ /**
5
+ * On-chain storage as one-call programmatic transactions.
6
+ *
7
+ * Wraps {@link Demos.store} and {@link Demos.storagePrograms} so persisting
8
+ * binary data or signing a storage program collapses the classic
9
+ * `build/sign → confirm → broadcast` flow into a single call. Each builder
10
+ * here returns a SIGNED transaction; the method hands a thunk producing it
11
+ * to `ctx.run(...)`, which confirms against the fee ceiling and
12
+ * auto-broadcasts — keeping fee-cap policy, confirmation strategy and result
13
+ * shape uniform with the rest of `demos.run.*`.
14
+ */
15
+ export declare function createStorageNamespace(ctx: ProgrammaticContext): {
16
+ /**
17
+ * Store binary data on the blockchain, end to end.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const bytes = new TextEncoder().encode("hello world")
22
+ * // auto-broadcast within the 5 DEM fee cap:
23
+ * await demos.run.storage.store(bytes)
24
+ * // build + confirm only, broadcast later yourself:
25
+ * const r = await demos.run.storage.store(bytes, { confirm: "manual" })
26
+ * await demos.broadcast(r.validityData)
27
+ * ```
28
+ *
29
+ * @param bytes - The binary data to store in the sender's account.
30
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
31
+ */
32
+ store: (bytes: Uint8Array, opts?: ProgrammaticTxOptions) => Promise<ProgrammaticTxResult>;
33
+ /**
34
+ * Sign and submit a storage program, end to end.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const r = await demos.run.storage.program({
39
+ * storageAddress: "0x...",
40
+ * // …program payload fields
41
+ * })
42
+ * ```
43
+ *
44
+ * @param payload - The storage program payload to sign (must carry a
45
+ * `storageAddress`).
46
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
47
+ */
48
+ program: (payload: StorageProgramPayload, opts?: ProgrammaticTxOptions) => Promise<ProgrammaticTxResult>;
49
+ };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * On-chain storage as one-call programmatic transactions.
3
+ *
4
+ * Wraps {@link Demos.store} and {@link Demos.storagePrograms} so persisting
5
+ * binary data or signing a storage program collapses the classic
6
+ * `build/sign → confirm → broadcast` flow into a single call. Each builder
7
+ * here returns a SIGNED transaction; the method hands a thunk producing it
8
+ * to `ctx.run(...)`, which confirms against the fee ceiling and
9
+ * auto-broadcasts — keeping fee-cap policy, confirmation strategy and result
10
+ * shape uniform with the rest of `demos.run.*`.
11
+ */
12
+ export function createStorageNamespace(ctx) {
13
+ return {
14
+ /**
15
+ * Store binary data on the blockchain, end to end.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const bytes = new TextEncoder().encode("hello world")
20
+ * // auto-broadcast within the 5 DEM fee cap:
21
+ * await demos.run.storage.store(bytes)
22
+ * // build + confirm only, broadcast later yourself:
23
+ * const r = await demos.run.storage.store(bytes, { confirm: "manual" })
24
+ * await demos.broadcast(r.validityData)
25
+ * ```
26
+ *
27
+ * @param bytes - The binary data to store in the sender's account.
28
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
29
+ */
30
+ store: (bytes, opts) => ctx.run(() => ctx.demos.store(bytes), opts),
31
+ /**
32
+ * Sign and submit a storage program, end to end.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const r = await demos.run.storage.program({
37
+ * storageAddress: "0x...",
38
+ * // …program payload fields
39
+ * })
40
+ * ```
41
+ *
42
+ * @param payload - The storage program payload to sign (must carry a
43
+ * `storageAddress`).
44
+ * @param opts - Fee ceiling / confirmation strategy / wait behaviour.
45
+ */
46
+ program: (payload, opts) => ctx.run(() => ctx.demos.storagePrograms.sign(payload), opts),
47
+ };
48
+ }
49
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../../src/websdk/programmatic/storage.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB,CAAC,GAAwB;IAC3D,OAAO;QACH;;;;;;;;;;;;;;;WAeG;QACH,KAAK,EAAE,CACH,KAAiB,EACjB,IAA4B,EACC,EAAE,CAC/B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC;QAE/C;;;;;;;;;;;;;;WAcG;QACH,OAAO,EAAE,CACL,OAA8B,EAC9B,IAA4B,EACC,EAAE,CAC/B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC;KACnE,CAAA;AACL,CAAC"}