@kynesyslabs/demosdk 4.0.12 → 4.0.14
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/abstraction/Identities.d.ts +65 -21
- package/build/abstraction/Identities.js +51 -50
- package/build/abstraction/Identities.js.map +1 -1
- package/build/bridge/nativeBridge.d.ts +3 -1
- package/build/bridge/nativeBridge.js +4 -3
- package/build/bridge/nativeBridge.js.map +1 -1
- package/build/contracts/ContractDeployer.js +5 -2
- package/build/contracts/ContractDeployer.js.map +1 -1
- package/build/contracts/ContractInteractor.js +4 -1
- package/build/contracts/ContractInteractor.js.map +1 -1
- package/build/d402/client/D402Client.d.ts +3 -1
- package/build/d402/client/D402Client.js +4 -3
- package/build/d402/client/D402Client.js.map +1 -1
- package/build/escrow/EscrowTransaction.d.ts +7 -2
- package/build/escrow/EscrowTransaction.js +9 -8
- package/build/escrow/EscrowTransaction.js.map +1 -1
- package/build/l2ps/anchor/anchor.d.ts +1 -0
- package/build/l2ps/anchor/anchor.js +4 -3
- package/build/l2ps/anchor/anchor.js.map +1 -1
- package/build/l2ps/binding/binding.d.ts +3 -1
- package/build/l2ps/binding/binding.js +3 -2
- package/build/l2ps/binding/binding.js.map +1 -1
- package/build/tlsnotary/TLSNotaryService.d.ts +2 -0
- package/build/tlsnotary/TLSNotaryService.js +11 -10
- package/build/tlsnotary/TLSNotaryService.js.map +1 -1
- package/build/types/blockchain/GCREdit.d.ts +0 -30
- package/build/types/blockchain/Transaction.d.ts +7 -0
- package/build/types/blockchain/Transaction.js.map +1 -1
- package/build/types/blockchain/rawTransaction.d.ts +2 -7
- package/build/types/web2/index.d.ts +1 -0
- package/build/utils/index.d.ts +2 -0
- package/build/utils/index.js +12 -0
- package/build/utils/index.js.map +1 -1
- package/build/websdk/DemosTokens.d.ts +42 -14
- package/build/websdk/DemosTokens.js +35 -30
- package/build/websdk/DemosTokens.js.map +1 -1
- package/build/websdk/DemosTransactions.d.ts +29 -11
- package/build/websdk/DemosTransactions.js +30 -29
- package/build/websdk/DemosTransactions.js.map +1 -1
- package/build/websdk/Web2Calls.js +3 -2
- package/build/websdk/Web2Calls.js.map +1 -1
- package/build/websdk/demosclass.d.ts +177 -33
- package/build/websdk/demosclass.js +102 -13
- package/build/websdk/demosclass.js.map +1 -1
- package/build/websdk/index.d.ts +1 -0
- package/build/websdk/index.js +3 -0
- package/build/websdk/index.js.map +1 -1
- package/build/websdk/programmatic/ProgrammaticTx.d.ts +118 -0
- package/build/websdk/programmatic/ProgrammaticTx.js +56 -0
- package/build/websdk/programmatic/ProgrammaticTx.js.map +1 -0
- package/build/websdk/programmatic/attest.d.ts +396 -0
- package/build/websdk/programmatic/attest.js +418 -0
- package/build/websdk/programmatic/attest.js.map +1 -0
- package/build/websdk/programmatic/bridge.d.ts +36 -0
- package/build/websdk/programmatic/bridge.js +37 -0
- package/build/websdk/programmatic/bridge.js.map +1 -0
- package/build/websdk/programmatic/context.d.ts +26 -0
- package/build/websdk/programmatic/context.js +9 -0
- package/build/websdk/programmatic/context.js.map +1 -0
- package/build/websdk/programmatic/contracts.d.ts +79 -0
- package/build/websdk/programmatic/contracts.js +81 -0
- package/build/websdk/programmatic/contracts.js.map +1 -0
- package/build/websdk/programmatic/d402.d.ts +33 -0
- package/build/websdk/programmatic/d402.js +35 -0
- package/build/websdk/programmatic/d402.js.map +1 -0
- package/build/websdk/programmatic/demoswork.d.ts +37 -0
- package/build/websdk/programmatic/demoswork.js +38 -0
- package/build/websdk/programmatic/demoswork.js.map +1 -0
- package/build/websdk/programmatic/errors.d.ts +20 -0
- package/build/websdk/programmatic/errors.js +24 -0
- package/build/websdk/programmatic/errors.js.map +1 -0
- package/build/websdk/programmatic/escrow.d.ts +75 -0
- package/build/websdk/programmatic/escrow.js +74 -0
- package/build/websdk/programmatic/escrow.js.map +1 -0
- package/build/websdk/programmatic/governance.d.ts +59 -0
- package/build/websdk/programmatic/governance.js +48 -0
- package/build/websdk/programmatic/governance.js.map +1 -0
- package/build/websdk/programmatic/index.d.ts +30 -0
- package/build/websdk/programmatic/index.js +31 -0
- package/build/websdk/programmatic/index.js.map +1 -0
- package/build/websdk/programmatic/ipfs.d.ts +74 -0
- package/build/websdk/programmatic/ipfs.js +106 -0
- package/build/websdk/programmatic/ipfs.js.map +1 -0
- package/build/websdk/programmatic/pay.d.ts +36 -0
- package/build/websdk/programmatic/pay.js +37 -0
- package/build/websdk/programmatic/pay.js.map +1 -0
- package/build/websdk/programmatic/runner.d.ts +30 -0
- package/build/websdk/programmatic/runner.js +188 -0
- package/build/websdk/programmatic/runner.js.map +1 -0
- package/build/websdk/programmatic/storage.d.ts +49 -0
- package/build/websdk/programmatic/storage.js +51 -0
- package/build/websdk/programmatic/storage.js.map +1 -0
- package/build/websdk/programmatic/tokens.d.ts +155 -0
- package/build/websdk/programmatic/tokens.js +171 -0
- package/build/websdk/programmatic/tokens.js.map +1 -0
- package/build/websdk/programmatic/types.d.ts +96 -0
- package/build/websdk/programmatic/types.js +8 -0
- package/build/websdk/programmatic/types.js.map +1 -0
- package/build/websdk/programmatic/validator.d.ts +63 -0
- package/build/websdk/programmatic/validator.js +68 -0
- package/build/websdk/programmatic/validator.js.map +1 -0
- package/build/websdk/programmatic/xm.d.ts +36 -0
- package/build/websdk/programmatic/xm.js +37 -0
- package/build/websdk/programmatic/xm.js.map +1 -0
- 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,106 @@
|
|
|
1
|
+
import { uint8ArrayToHex } from "../../encryption/unifiedCrypto.js";
|
|
2
|
+
import { IPFSOperations, } from "../../ipfs/index.js";
|
|
3
|
+
import { DemosTransactions } from "../DemosTransactions.js";
|
|
4
|
+
import { resolveNonce } from "../../utils/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* IPFS operations as one-call programmatic transactions.
|
|
7
|
+
*
|
|
8
|
+
* Unlike `pay`/`store`/`storagePrograms`, there is no single Demos builder
|
|
9
|
+
* that returns a signed `ipfs` transaction: the payloads come from
|
|
10
|
+
* {@link IPFSOperations}' static creators (`createAddPayload`,
|
|
11
|
+
* `createPinPayload`, `createUnpinPayload`) and the caller must assemble the
|
|
12
|
+
* transaction around them. This namespace does that assembly.
|
|
13
|
+
*
|
|
14
|
+
* Each method builds the payload, wraps it in an UNSIGNED `ipfs` transaction
|
|
15
|
+
* (nonce set exactly like `demos.storagePrograms.sign`), and hands a thunk
|
|
16
|
+
* producing it to `ctx.run(...)`. The shared runner signs it and confirms it
|
|
17
|
+
* against the fee ceiling before auto-broadcasting — keeping fee-cap policy,
|
|
18
|
+
* confirmation strategy and result shape uniform with the rest of
|
|
19
|
+
* `demos.run.*`.
|
|
20
|
+
*
|
|
21
|
+
* Cost control ("custom charges") is opt-in and stays simple: forward a
|
|
22
|
+
* `customCharges` block through `addOptions`/`pinOptions` (obtained from
|
|
23
|
+
* `IPFSOperations.quoteToCustomCharges(await demos.ipfs.quote(...))`). The
|
|
24
|
+
* payload creators embed it in the payload; this namespace additionally
|
|
25
|
+
* mirrors it onto `tx.content.custom_charges` so the node sees the ceiling
|
|
26
|
+
* the sender signed. No quote round-trip is performed here.
|
|
27
|
+
*/
|
|
28
|
+
export function createIpfsNamespace(ctx) {
|
|
29
|
+
/**
|
|
30
|
+
* Assemble an UNSIGNED `ipfs` transaction around a ready IPFS payload.
|
|
31
|
+
*
|
|
32
|
+
* Replicates the nonce pattern from `demos.storagePrograms.sign`: read the
|
|
33
|
+
* sender's ed25519 public key, fetch its on-chain nonce and set
|
|
34
|
+
* `content.nonce = nonce + 1`. The transaction is returned unsigned; the
|
|
35
|
+
* shared runner signs it.
|
|
36
|
+
*
|
|
37
|
+
* @param payload - An IPFS payload from an `IPFSOperations.create*` method.
|
|
38
|
+
* @returns The unsigned `ipfs` transaction, ready for `ctx.run`.
|
|
39
|
+
*/
|
|
40
|
+
const buildIpfsTx = async (payload, customNonce) => {
|
|
41
|
+
const nonce = await resolveNonce(customNonce, async () => {
|
|
42
|
+
const { publicKey } = await ctx.demos.crypto.getIdentity("ed25519");
|
|
43
|
+
return ctx.demos.getAddressNonce(uint8ArrayToHex(publicKey));
|
|
44
|
+
});
|
|
45
|
+
const tx = DemosTransactions.empty();
|
|
46
|
+
tx.content.type = "ipfs";
|
|
47
|
+
tx.content.nonce = nonce;
|
|
48
|
+
tx.content.data = ["ipfs", payload];
|
|
49
|
+
// Mirror the signed cost ceiling onto the transaction content when the
|
|
50
|
+
// payload carries one, so the node enforces the same `max_cost_os` the
|
|
51
|
+
// sender agreed to. `IPFSUnpinPayload` never has this field.
|
|
52
|
+
if ("custom_charges" in payload && payload.custom_charges) {
|
|
53
|
+
tx.content.custom_charges = payload.custom_charges;
|
|
54
|
+
}
|
|
55
|
+
return tx;
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
/**
|
|
59
|
+
* Upload content to IPFS (and auto-pin it), end to end.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* // auto-broadcast within the 5 DEM fee cap:
|
|
64
|
+
* await demos.run.ipfs.add("hello world", { filename: "hello.txt" })
|
|
65
|
+
*
|
|
66
|
+
* // with a signed cost ceiling from a quote:
|
|
67
|
+
* const quote = await demos.ipfs.quote(bytes.length, "IPFS_ADD")
|
|
68
|
+
* await demos.run.ipfs.add(bytes, {
|
|
69
|
+
* customCharges: IPFSOperations.quoteToCustomCharges(quote),
|
|
70
|
+
* })
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @param content - Content to upload (Buffer, Uint8Array or string).
|
|
74
|
+
* @param addOptions - Filename, metadata and optional custom charges.
|
|
75
|
+
* @param opts - Fee ceiling / confirmation strategy / wait behaviour.
|
|
76
|
+
*/
|
|
77
|
+
add: (content, addOptions, opts) => ctx.run(() => buildIpfsTx(IPFSOperations.createAddPayload(content, addOptions), opts?.nonce), opts),
|
|
78
|
+
/**
|
|
79
|
+
* Pin an existing CID to the sender's account, end to end.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* await demos.run.ipfs.pin("QmExampleCID...")
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @param cid - The Content Identifier to pin (CIDv0 or CIDv1).
|
|
87
|
+
* @param pinOptions - Duration, metadata, `fileSize` and optional
|
|
88
|
+
* custom charges.
|
|
89
|
+
* @param opts - Fee ceiling / confirmation strategy / wait behaviour.
|
|
90
|
+
*/
|
|
91
|
+
pin: (cid, pinOptions, opts) => ctx.run(() => buildIpfsTx(IPFSOperations.createPinPayload(cid, pinOptions), opts?.nonce), opts),
|
|
92
|
+
/**
|
|
93
|
+
* Remove a pin from the sender's account, end to end.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* await demos.run.ipfs.unpin("QmExampleCID...")
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @param cid - The Content Identifier to unpin (CIDv0 or CIDv1).
|
|
101
|
+
* @param opts - Fee ceiling / confirmation strategy / wait behaviour.
|
|
102
|
+
*/
|
|
103
|
+
unpin: (cid, opts) => ctx.run(() => buildIpfsTx(IPFSOperations.createUnpinPayload(cid), opts?.nonce), opts),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//# 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;AAGxD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC;;;;;;;;;;;;;;;;;;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,EAClC,IAA4B,EACC,EAAE,CAC/B,GAAG,CAAC,GAAG,CACH,GAAG,EAAE,CACD,WAAW,CACP,cAAc,CAAC,gBAAgB,CAAC,GAAG,EAAE,UAAU,CAAC,EAChD,IAAI,EAAE,KAAK,CACd,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,EAAE,IAAI,EAAE,KAAK,CAAC,EACtE,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, { nonce: opts?.nonce }), 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, { nonce: opts?.nonce }), 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,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC;QAE1E;;;;;;WAMG;QACH,QAAQ,EAAE,CACN,EAAU,EACV,MAAuB,EACvB,IAA4B,EACC,EAAE,CAC/B,GAAG,CAAC,GAAG,CACH,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAC5D,IAAI,CACP;KACR,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,188 @@
|
|
|
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, customNonce) {
|
|
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
|
|
98
|
+
? tx
|
|
99
|
+
: await demos.sign(tx, customNonce !== undefined ? { nonce: customNonce } : undefined);
|
|
100
|
+
return await demos.confirm(signed);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The shared programmatic-transaction runner — the single place where
|
|
104
|
+
* `confirm → (fee cap / callback) → broadcast` lives.
|
|
105
|
+
*
|
|
106
|
+
* Every typed one-call method (`demos.run.pay`, `demos.run.attest.*`,
|
|
107
|
+
* `demos.run.tokens.*`, …) builds/signs its transaction and hands it here,
|
|
108
|
+
* so confirmation policy and result shape are uniform across the SDK.
|
|
109
|
+
*
|
|
110
|
+
* @param demos - The connected Demos instance.
|
|
111
|
+
* @param source - A signed/unsigned tx, an already-confirmed validityData,
|
|
112
|
+
* or a thunk producing either.
|
|
113
|
+
* @param opts - Fee ceiling, confirmation strategy and wait behaviour.
|
|
114
|
+
* @returns A uniform {@link ProgrammaticTxResult}.
|
|
115
|
+
*/
|
|
116
|
+
export async function runProgrammaticTx(demos, source, opts = {}) {
|
|
117
|
+
const validityData = await resolveToConfirmed(demos, source, opts.nonce);
|
|
118
|
+
const transaction = validityData.response.data.transaction;
|
|
119
|
+
// A successful confirm always echoes the transaction; guard so the
|
|
120
|
+
// non-optional `transaction`/`hash` on the result types stay truthful
|
|
121
|
+
// (rather than silently handing callers `undefined.hash`).
|
|
122
|
+
if (!transaction) {
|
|
123
|
+
throw new Error("[programmatic-tx] confirm response did not include a transaction");
|
|
124
|
+
}
|
|
125
|
+
const hash = transaction.hash;
|
|
126
|
+
const referenceBlock = validityData.response.data.reference_block;
|
|
127
|
+
const feeOs = totalFeeOs(validityData);
|
|
128
|
+
const feeDem = osToDem(feeOs);
|
|
129
|
+
const capOs = resolveCapOs(opts.maxFee);
|
|
130
|
+
const withinFeeCap = capOs === null || feeOs <= capOs;
|
|
131
|
+
const info = {
|
|
132
|
+
transaction,
|
|
133
|
+
validityData,
|
|
134
|
+
feeOs,
|
|
135
|
+
feeDem,
|
|
136
|
+
withinFeeCap,
|
|
137
|
+
referenceBlock,
|
|
138
|
+
};
|
|
139
|
+
const mode = opts.confirm ?? "auto";
|
|
140
|
+
// "manual": stop after confirm, hand back the validity data unbroadcast.
|
|
141
|
+
if (mode === "manual") {
|
|
142
|
+
return {
|
|
143
|
+
broadcasted: false,
|
|
144
|
+
skippedReason: "manual",
|
|
145
|
+
transaction,
|
|
146
|
+
hash,
|
|
147
|
+
validityData,
|
|
148
|
+
feeOs,
|
|
149
|
+
feeDem,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
// Decide whether to broadcast.
|
|
153
|
+
let allowed;
|
|
154
|
+
if (typeof mode === "function") {
|
|
155
|
+
allowed = await mode(info);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
// "auto": enforce the fee ceiling loudly.
|
|
159
|
+
if (!withinFeeCap) {
|
|
160
|
+
throw new FeeCapExceededError(feeOs, capOs, info);
|
|
161
|
+
}
|
|
162
|
+
allowed = true;
|
|
163
|
+
}
|
|
164
|
+
if (!allowed) {
|
|
165
|
+
return {
|
|
166
|
+
broadcasted: false,
|
|
167
|
+
skippedReason: "rejected",
|
|
168
|
+
transaction,
|
|
169
|
+
hash,
|
|
170
|
+
validityData,
|
|
171
|
+
feeOs,
|
|
172
|
+
feeDem,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const broadcast = opts.wait
|
|
176
|
+
? await demos.broadcastAndWait(validityData, opts.waitOptions)
|
|
177
|
+
: await demos.broadcast(validityData);
|
|
178
|
+
return {
|
|
179
|
+
broadcasted: true,
|
|
180
|
+
transaction,
|
|
181
|
+
hash,
|
|
182
|
+
validityData,
|
|
183
|
+
broadcast,
|
|
184
|
+
feeOs,
|
|
185
|
+
feeDem,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
//# 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,KAAK,CAAC,CAAA;QACpD,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;QACtB,IAAI,CAAC,KAAK,EAAE;YAAE,OAAO,EAAE,CAAA;QACvB,wEAAwE;QACxE,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACnD,CAAC;IAAC,MAAM,CAAC;QACL,mEAAmE;QACnE,mEAAmE;QACnE,MAAM,IAAI,KAAK,CACX,2CAA2C,IAAI,CAAC,SAAS,CACrD,KAAK,CACR,iCAAiC,CACrC,CAAA;IACL,CAAC;AACL,CAAC;AAED;;;;;;;;;;G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,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,51 @@
|
|
|
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, { nonce: opts?.nonce }), 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, {
|
|
47
|
+
nonce: opts?.nonce,
|
|
48
|
+
}), opts),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# 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,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC;QAEvE;;;;;;;;;;;;;;WAcG;QACH,OAAO,EAAE,CACL,OAA8B,EAC9B,IAA4B,EACC,EAAE,CAC/B,GAAG,CAAC,GAAG,CACH,GAAG,EAAE,CACD,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE;YACpC,KAAK,EAAE,IAAI,EAAE,KAAK;SACrB,CAAC,EACN,IAAI,CACP;KACR,CAAA;AACL,CAAC"}
|