@integraledger/terms 0.2.0 → 0.3.1
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/README.md +88 -52
- package/dist/agreement.d.ts +14 -4
- package/dist/agreement.js +139 -49
- package/dist/channels.d.ts +47 -14
- package/dist/channels.js +147 -74
- package/dist/gate.d.ts +37 -16
- package/dist/gate.js +69 -45
- package/dist/pairings/batch.d.ts +2 -5
- package/dist/pairings/batch.js +1 -11
- package/dist/pairings/card.js +0 -2
- package/dist/pairings/common.d.ts +17 -4
- package/dist/pairings/common.js +35 -4
- package/dist/pairings/lnbtc-request.d.ts +1 -1
- package/dist/pairings/lnbtc-request.js +14 -5
- package/dist/pairings/mpp-charge-hedera.d.ts +13 -11
- package/dist/pairings/mpp-charge-hedera.js +16 -14
- package/dist/pairings/mpp-charge-tempo-memo.d.ts +1 -9
- package/dist/pairings/mpp-charge-tempo-memo.js +3 -7
- package/dist/pairings/mpp-charge-tempo-push.d.ts +6 -1
- package/dist/pairings/mpp-charge-tempo-push.js +4 -13
- package/dist/pairings/mpp-charge-xrpl.js +3 -3
- package/dist/pairings/mpp-rails.d.ts +1 -1
- package/dist/pairings/mpp-session-hedera.js +3 -4
- package/dist/pairings/mpp-session-xrpl.js +3 -4
- package/dist/pairings/mpp.d.ts +14 -17
- package/dist/pairings/mpp.js +35 -114
- package/dist/pairings/protocol-groups.d.ts +1 -1
- package/dist/pairings/x402-account-rails.d.ts +1 -1
- package/dist/pairings/x402-batch-settlement-solana.d.ts +2 -0
- package/dist/pairings/x402-batch-settlement-solana.js +2 -1
- package/dist/pairings/x402-exact-hedera.d.ts +4 -1
- package/dist/pairings/x402-exact-hedera.js +5 -2
- package/dist/pairings/x402-exact-near.js +23 -2
- package/dist/pairings/x402-exact-solana.d.ts +4 -4
- package/dist/pairings/x402-exact-solana.js +3 -2
- package/dist/pairings/x402-exact-sui.js +3 -1
- package/dist/pairings/x402-exact-tvm.js +10 -2
- package/dist/pairings/x402-exact-xrpl.js +2 -4
- package/dist/pairings/x402-rail.d.ts +3 -2
- package/dist/pairings/x402-rail.js +1 -1
- package/dist/transact.d.ts +3 -2
- package/dist/transact.js +9 -6
- package/dist/types.d.ts +6 -16
- package/package.json +10 -12
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bigintOf, inputsOf, isObject, isRefusal, refuse } from "./common.js";
|
|
1
|
+
import { bigintOf, held, inputsOf, isObject, isRefusal, refuse, withoutFetched } from "./common.js";
|
|
2
2
|
import { HEDERA_EVM_ADDRESS, mppRailPiece, sessionRevive } from "./mpp-rails.js";
|
|
3
3
|
const PAIRING = "mpp/session/hedera";
|
|
4
4
|
async function complete(unsigned, signature, _chosen) {
|
|
@@ -20,7 +20,7 @@ async function complete(unsigned, signature, _chosen) {
|
|
|
20
20
|
const blockNumber = bigintOf(landed["blockNumber"]);
|
|
21
21
|
if (blockNumber === undefined)
|
|
22
22
|
return refuse("mpp/credential-malformed");
|
|
23
|
-
return
|
|
23
|
+
return held(credential, { transaction: landed["transaction"], blockNumber, logs: landed["logs"] });
|
|
24
24
|
}
|
|
25
25
|
export const mppSessionHedera = Object.freeze({
|
|
26
26
|
...mppRailPiece({
|
|
@@ -35,7 +35,6 @@ export const mppSessionHedera = Object.freeze({
|
|
|
35
35
|
}),
|
|
36
36
|
moves: () => true,
|
|
37
37
|
sent(signed) {
|
|
38
|
-
|
|
39
|
-
return credential;
|
|
38
|
+
return withoutFetched(signed);
|
|
40
39
|
},
|
|
41
40
|
});
|
|
@@ -20,13 +20,12 @@ function inputs(_request, given) {
|
|
|
20
20
|
return refuse("mpp/input-missing");
|
|
21
21
|
return { ...read, xrpl: { ...x, publicKey } };
|
|
22
22
|
}
|
|
23
|
-
/** `{signedBlob, claimSignature}` as the build's hex digits
|
|
23
|
+
/** `{signedBlob, claimSignature}` as given: the build's `complete` reads each as hex digits without `0x`. */
|
|
24
24
|
function answer(signature) {
|
|
25
25
|
if (!isObject(signature))
|
|
26
26
|
return refuse("mpp/credential-malformed");
|
|
27
|
-
const signedBlob =
|
|
28
|
-
|
|
29
|
-
if (signedBlob === undefined || claimSignature === undefined)
|
|
27
|
+
const { signedBlob, claimSignature } = signature;
|
|
28
|
+
if (typeof signedBlob !== "string" || typeof claimSignature !== "string")
|
|
30
29
|
return refuse("mpp/credential-malformed");
|
|
31
30
|
return { signedBlob, claimSignature };
|
|
32
31
|
}
|
package/dist/pairings/mpp.d.ts
CHANGED
|
@@ -2,20 +2,27 @@
|
|
|
2
2
|
* The buyer pieces shared by MPP's pairings: the first challenge, in document order, that offers the pairing on the
|
|
3
3
|
* signer's chain; the build's request exactly as built; and the credential the signer's answer completes.
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
6
|
-
import { type MppChallenge
|
|
5
|
+
import type { Json, Refusal } from "@integraledger/lcp/core";
|
|
6
|
+
import { type MppChallenge } from "@integraledger/lcp/mpp";
|
|
7
7
|
import type { BuyerPiece, Choose, Chosen, Presented, Signature, SigningRequest } from "../types.js";
|
|
8
8
|
import { inputsOf } from "./common.js";
|
|
9
9
|
type Spec = Parameters<typeof inputsOf>[2];
|
|
10
|
-
/** The request a challenge carries,
|
|
10
|
+
/** The request a challenge carries, read by `decodeObject`, or undefined. */
|
|
11
11
|
export declare function requestOf(c: MppChallenge): Record<string, unknown> | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The JSON object a base64url value holds, read as the protocol package reads an MPP challenge's `request` and
|
|
14
|
+
* `opaque`: base64url without padding, its final character's unused bits zero, at most 8 KiB decoded; UTF-8 whose
|
|
15
|
+
* leading byte order mark is kept as a character; one JSON object, nested at most 16 levels deep, that has an RFC 8785
|
|
16
|
+
* form. Undefined for anything else.
|
|
17
|
+
*/
|
|
18
|
+
export declare function decodeObject(s: unknown): Record<string, Json> | undefined;
|
|
12
19
|
/** Whether a placed challenge offers the pairing, by the protocol package's `pairingsOfPlaced`. */
|
|
13
20
|
export declare function offers(c: MppChallenge, pairing: string): boolean;
|
|
14
21
|
/**
|
|
15
22
|
* The first challenge offering `pairing` on the account's EVM network, as MPP's `network` reads it, with the choice
|
|
16
23
|
* MPP's build takes: the challenge, `from`, `now`, and the buyer's own inputs named in `spec`.
|
|
17
24
|
*/
|
|
18
|
-
export declare function mppChoose(pairing: string, spec: Spec
|
|
25
|
+
export declare function mppChoose(pairing: string, spec: Spec): Choose;
|
|
19
26
|
/** The choice as MPP's build takes it, with `deposit` as a bigint where the choice carries one. */
|
|
20
27
|
export declare function mppChoice(chosen: Chosen): unknown;
|
|
21
28
|
/** The build's request, exactly as built. */
|
|
@@ -23,21 +30,11 @@ export declare function mppRequest(unsigned: unknown): SigningRequest | Refusal;
|
|
|
23
30
|
/** The credential for a one-value answer: a signature, a signed transaction or a transaction hash, as `0x` hex. */
|
|
24
31
|
export declare function mppComplete(unsigned: unknown, signature: Signature): Promise<Presented | Refusal>;
|
|
25
32
|
/** A buyer piece for an MPP charge pairing whose answer is one value. */
|
|
26
|
-
export declare function mppChargePiece(pairing: string, spec: Spec
|
|
27
|
-
/** Accepts a Tempo challenge whose splits are well formed and leave the primary recipient more than zero. */
|
|
28
|
-
export declare function acceptSplits(c: MppChallenge): Refusal | null;
|
|
29
|
-
type TempoBinding = {
|
|
30
|
-
build(choice: never, h: AtrHash): Promise<MppUnsigned | Refusal>;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* A Tempo charge's build. Without splits it is the binding's own `tempo-call`. With splits it is `tempo-calls`: the
|
|
34
|
-
* binding's primary call, carrying its attribution memo, for `amount` less the splits, then one call per split in
|
|
35
|
-
* array order, `transferWithMemo` where the split names a memo and `transfer` otherwise, all on `currency`.
|
|
36
|
-
*/
|
|
37
|
-
export declare function tempoBuild(binding: TempoBinding): NonNullable<BuyerPiece["build"]>;
|
|
33
|
+
export declare function mppChargePiece(pairing: string, spec: Spec): BuyerPiece;
|
|
38
34
|
/**
|
|
39
35
|
* The credential for a pushed Tempo transfer: the answer is `{hash, landed?: {transaction, blockNumber, logs}}`, the
|
|
40
|
-
* hash the signer broadcast and, where the signer gives it, its landed receipt, which carries the memo `bound` reads
|
|
36
|
+
* hash the signer broadcast and, where the signer gives it, its landed receipt, which carries the memo `bound` reads,
|
|
37
|
+
* held under the payment's own `FETCHED` member (`@integraledger/lcp`'s symbol, which no wire form carries).
|
|
41
38
|
*/
|
|
42
39
|
export declare function pushComplete(unsigned: unknown, signature: Signature): Promise<Presented | Refusal>;
|
|
43
40
|
export {};
|
package/dist/pairings/mpp.js
CHANGED
|
@@ -1,23 +1,42 @@
|
|
|
1
|
-
import { parseJson } from "@integraledger/lcp";
|
|
1
|
+
import { base64UrlBytes, canonicalJson, parseJson } from "@integraledger/lcp/core";
|
|
2
2
|
import { network, pairingsOfPlaced } from "@integraledger/lcp/mpp";
|
|
3
|
-
import {
|
|
4
|
-
import { accountOf, bigintOf, broadcasts, choiceOf, inputsOf, isObject, isRefusal, refuse } from "./common.js";
|
|
3
|
+
import { accountOf, bigintOf, broadcasts, choiceOf, held, inputsOf, isObject, isRefusal, refuse } from "./common.js";
|
|
5
4
|
const EVM_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
6
|
-
|
|
5
|
+
const MAX_DECODED = 8192;
|
|
6
|
+
const MAX_JSON_DEPTH = 16;
|
|
7
|
+
/** The request a challenge carries, read by `decodeObject`, or undefined. */
|
|
7
8
|
export function requestOf(c) {
|
|
8
|
-
|
|
9
|
+
return isObject(c) ? decodeObject(c["request"]) : undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The JSON object a base64url value holds, read as the protocol package reads an MPP challenge's `request` and
|
|
13
|
+
* `opaque`: base64url without padding, its final character's unused bits zero, at most 8 KiB decoded; UTF-8 whose
|
|
14
|
+
* leading byte order mark is kept as a character; one JSON object, nested at most 16 levels deep, that has an RFC 8785
|
|
15
|
+
* form. Undefined for anything else.
|
|
16
|
+
*/
|
|
17
|
+
export function decodeObject(s) {
|
|
18
|
+
const bytes = base64UrlBytes(s, MAX_DECODED);
|
|
19
|
+
if (typeof bytes === "string")
|
|
9
20
|
return undefined;
|
|
10
21
|
try {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return isObject(v) ? v : undefined;
|
|
22
|
+
const v = parseJson(new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes));
|
|
23
|
+
if (!isObject(v) || depthOf(v, 0) > MAX_JSON_DEPTH)
|
|
24
|
+
return undefined;
|
|
25
|
+
return typeof canonicalJson(v) === "string" ? v : undefined;
|
|
16
26
|
}
|
|
17
27
|
catch {
|
|
18
28
|
return undefined;
|
|
19
29
|
}
|
|
20
30
|
}
|
|
31
|
+
/** The nesting depth of objects and arrays in `v`, counting from `d`, stopping once past `MAX_JSON_DEPTH`. */
|
|
32
|
+
function depthOf(v, d) {
|
|
33
|
+
if (d > MAX_JSON_DEPTH || typeof v !== "object" || v === null)
|
|
34
|
+
return d;
|
|
35
|
+
let max = d + 1;
|
|
36
|
+
for (const x of Object.values(v))
|
|
37
|
+
max = Math.max(max, depthOf(x, d + 1));
|
|
38
|
+
return max;
|
|
39
|
+
}
|
|
21
40
|
/** Whether a placed challenge offers the pairing, by the protocol package's `pairingsOfPlaced`. */
|
|
22
41
|
export function offers(c, pairing) {
|
|
23
42
|
return pairingsOfPlaced(c).some((p) => p === pairing);
|
|
@@ -26,7 +45,7 @@ export function offers(c, pairing) {
|
|
|
26
45
|
* The first challenge offering `pairing` on the account's EVM network, as MPP's `network` reads it, with the choice
|
|
27
46
|
* MPP's build takes: the challenge, `from`, `now`, and the buyer's own inputs named in `spec`.
|
|
28
47
|
*/
|
|
29
|
-
export function mppChoose(pairing, spec
|
|
48
|
+
export function mppChoose(pairing, spec) {
|
|
30
49
|
return (read, account, inputs, now, ref) => {
|
|
31
50
|
const a = accountOf(account);
|
|
32
51
|
if (a === undefined || a.namespace !== "eip155" || !EVM_ADDRESS.test(a.address))
|
|
@@ -36,9 +55,6 @@ export function mppChoose(pairing, spec, accept) {
|
|
|
36
55
|
const challenge = challenges.find((c) => offers(c, pairing) && network(c) === a.network);
|
|
37
56
|
if (challenge === undefined)
|
|
38
57
|
return refuse("mpp/no-payable-option");
|
|
39
|
-
const refused = accept?.(challenge) ?? null;
|
|
40
|
-
if (refused !== null)
|
|
41
|
-
return refused;
|
|
42
58
|
const given = inputsOf(inputs, pairing, spec);
|
|
43
59
|
if (isRefusal(given))
|
|
44
60
|
return given;
|
|
@@ -66,111 +82,19 @@ export async function mppComplete(unsigned, signature) {
|
|
|
66
82
|
return unsigned.complete(signature);
|
|
67
83
|
}
|
|
68
84
|
/** A buyer piece for an MPP charge pairing whose answer is one value. */
|
|
69
|
-
export function mppChargePiece(pairing, spec
|
|
85
|
+
export function mppChargePiece(pairing, spec) {
|
|
70
86
|
return Object.freeze({
|
|
71
|
-
choose: mppChoose(pairing, spec
|
|
87
|
+
choose: mppChoose(pairing, spec),
|
|
72
88
|
choice: mppChoice,
|
|
73
89
|
request: mppRequest,
|
|
74
90
|
complete: mppComplete,
|
|
75
91
|
moves: broadcasts,
|
|
76
92
|
});
|
|
77
93
|
}
|
|
78
|
-
const MAX_SPLITS = 10;
|
|
79
|
-
const DECIMAL = /^[0-9]{1,78}$/;
|
|
80
|
-
const WORD = /^0x[0-9a-fA-F]{64}$/;
|
|
81
|
-
const TRANSFER_SELECTOR = "a9059cbb";
|
|
82
|
-
/**
|
|
83
|
-
* A Tempo challenge's `methodDetails.splits`: none, or 1–10 entries, each with a recipient address, an amount above
|
|
84
|
-
* zero and an optional 32-byte memo.
|
|
85
|
-
*/
|
|
86
|
-
function tempoSplits(c) {
|
|
87
|
-
const details = requestOf(c)?.["methodDetails"];
|
|
88
|
-
const splits = isObject(details) ? details["splits"] : undefined;
|
|
89
|
-
if (splits === undefined)
|
|
90
|
-
return [];
|
|
91
|
-
if (!Array.isArray(splits) || splits.length < 1 || splits.length > MAX_SPLITS)
|
|
92
|
-
return refuse("mpp/splits-malformed");
|
|
93
|
-
const out = [];
|
|
94
|
-
for (const s of splits) {
|
|
95
|
-
if (!isObject(s))
|
|
96
|
-
return refuse("mpp/splits-malformed");
|
|
97
|
-
const { recipient, amount, memo } = s;
|
|
98
|
-
if (typeof recipient !== "string" || !EVM_ADDRESS.test(recipient))
|
|
99
|
-
return refuse("mpp/splits-malformed");
|
|
100
|
-
if (typeof amount !== "string" || !DECIMAL.test(amount) || BigInt(amount) === 0n)
|
|
101
|
-
return refuse("mpp/splits-malformed");
|
|
102
|
-
if (memo !== undefined && (typeof memo !== "string" || !WORD.test(memo)))
|
|
103
|
-
return refuse("mpp/splits-malformed");
|
|
104
|
-
out.push({ recipient: recipient, amount: BigInt(amount), ...(memo !== undefined ? { memo: memo } : {}) });
|
|
105
|
-
}
|
|
106
|
-
return out;
|
|
107
|
-
}
|
|
108
|
-
/** What the primary recipient receives: `amount` less the splits, which must leave more than zero. */
|
|
109
|
-
function primaryAmount(c, splits) {
|
|
110
|
-
const amount = requestOf(c)?.["amount"];
|
|
111
|
-
if (typeof amount !== "string" || !DECIMAL.test(amount))
|
|
112
|
-
return refuse("mpp/request-malformed");
|
|
113
|
-
const primary = BigInt(amount) - splits.reduce((sum, s) => sum + s.amount, 0n);
|
|
114
|
-
return primary > 0n ? primary : refuse("mpp/input-malformed");
|
|
115
|
-
}
|
|
116
|
-
/** Accepts a Tempo challenge whose splits are well formed and leave the primary recipient more than zero. */
|
|
117
|
-
export function acceptSplits(c) {
|
|
118
|
-
const splits = tempoSplits(c);
|
|
119
|
-
if (isRefusal(splits))
|
|
120
|
-
return splits;
|
|
121
|
-
const primary = primaryAmount(c, splits);
|
|
122
|
-
return isRefusal(primary) ? primary : null;
|
|
123
|
-
}
|
|
124
|
-
/** `transfer(address,uint256)` calldata. */
|
|
125
|
-
function transferCalldata(to, amount) {
|
|
126
|
-
return `0x${TRANSFER_SELECTOR}${"0".repeat(24)}${to.slice(2).toLowerCase()}${amount.toString(16).padStart(64, "0")}`;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* A Tempo charge's build. Without splits it is the binding's own `tempo-call`. With splits it is `tempo-calls`: the
|
|
130
|
-
* binding's primary call, carrying its attribution memo, for `amount` less the splits, then one call per split in
|
|
131
|
-
* array order, `transferWithMemo` where the split names a memo and `transfer` otherwise, all on `currency`.
|
|
132
|
-
*/
|
|
133
|
-
export function tempoBuild(binding) {
|
|
134
|
-
return async (choice, h) => {
|
|
135
|
-
const unsigned = await binding.build(choice, h);
|
|
136
|
-
if (isRefusal(unsigned))
|
|
137
|
-
return unsigned;
|
|
138
|
-
const challenge = choice.challenge;
|
|
139
|
-
const splits = tempoSplits(challenge);
|
|
140
|
-
if (isRefusal(splits) || splits.length === 0)
|
|
141
|
-
return isRefusal(splits) ? splits : unsigned;
|
|
142
|
-
const primary = primaryAmount(challenge, splits);
|
|
143
|
-
if (isRefusal(primary))
|
|
144
|
-
return primary;
|
|
145
|
-
const request = unsigned.request;
|
|
146
|
-
if (request.kind !== "tempo-call")
|
|
147
|
-
return refuse("mpp/request-malformed");
|
|
148
|
-
const recipient = requestOf(challenge)?.["recipient"];
|
|
149
|
-
const memo = `0x${request.call.data.slice(-64)}`;
|
|
150
|
-
const primaryCall = memoCalldata(recipient, primary, memo);
|
|
151
|
-
if (isRefusal(primaryCall))
|
|
152
|
-
return primaryCall;
|
|
153
|
-
const currency = request.call.to;
|
|
154
|
-
const calls = [{ to: currency, data: primaryCall }];
|
|
155
|
-
for (const s of splits) {
|
|
156
|
-
const data = s.memo !== undefined ? memoCalldata(s.recipient, s.amount, s.memo) : transferCalldata(s.recipient, s.amount);
|
|
157
|
-
if (isRefusal(data))
|
|
158
|
-
return data;
|
|
159
|
-
calls.push({ to: currency, data });
|
|
160
|
-
}
|
|
161
|
-
const tempoCalls = {
|
|
162
|
-
kind: "tempo-calls",
|
|
163
|
-
chainId: request.chainId,
|
|
164
|
-
calls,
|
|
165
|
-
validBefore: request.validBefore,
|
|
166
|
-
broadcast: request.broadcast,
|
|
167
|
-
};
|
|
168
|
-
return { request: tempoCalls, complete: (s) => unsigned.complete(s) };
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
94
|
/**
|
|
172
95
|
* The credential for a pushed Tempo transfer: the answer is `{hash, landed?: {transaction, blockNumber, logs}}`, the
|
|
173
|
-
* hash the signer broadcast and, where the signer gives it, its landed receipt, which carries the memo `bound` reads
|
|
96
|
+
* hash the signer broadcast and, where the signer gives it, its landed receipt, which carries the memo `bound` reads,
|
|
97
|
+
* held under the payment's own `FETCHED` member (`@integraledger/lcp`'s symbol, which no wire form carries).
|
|
174
98
|
*/
|
|
175
99
|
export async function pushComplete(unsigned, signature) {
|
|
176
100
|
if (!isObject(signature) || typeof signature["hash"] !== "string")
|
|
@@ -187,8 +111,5 @@ export async function pushComplete(unsigned, signature) {
|
|
|
187
111
|
const blockNumber = bigintOf(landed["blockNumber"]);
|
|
188
112
|
if (blockNumber === undefined)
|
|
189
113
|
return refuse("mpp/credential-malformed");
|
|
190
|
-
return {
|
|
191
|
-
...credential,
|
|
192
|
-
landed: { transaction: landed["transaction"], blockNumber, logs: landed["logs"] },
|
|
193
|
-
};
|
|
114
|
+
return held(credential, { transaction: landed["transaction"], blockNumber, logs: landed["logs"] });
|
|
194
115
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* What the protocol-group pieces (card, AP2, UCP, ACP, ACK) share: the buyer's CAIP-10 account, which names the buyer,
|
|
3
3
|
* the object choice revived from `Chosen`, and the piece of a pairing whose build has nothing for the buyer to sign.
|
|
4
4
|
*/
|
|
5
|
-
import type { Json, Refusal } from "@integraledger/lcp";
|
|
5
|
+
import type { Json, Refusal } from "@integraledger/lcp/core";
|
|
6
6
|
import type { BuyerPiece, Chosen, Inputs, Read } from "../types.js";
|
|
7
7
|
/** A refusal `<ns>/no-payable-option` unless the account is CAIP-10. */
|
|
8
8
|
export declare function unnamedBuyer(account: string, ns: string): Refusal | undefined;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* percent-decoded as CAIP-10 writes it, and the piece for pairings where the payer's wallet builds and signs the
|
|
4
4
|
* rail's own payment around what the build hands it.
|
|
5
5
|
*/
|
|
6
|
-
import type { Refusal } from "@integraledger/lcp";
|
|
6
|
+
import type { Refusal } from "@integraledger/lcp/core";
|
|
7
7
|
import type { PaymentRequired, PaymentRequirements } from "@integraledger/lcp/x402";
|
|
8
8
|
import type { BuyerPiece, Chosen, Presented, Read } from "../types.js";
|
|
9
9
|
/**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { batchComplete, batchRequest, depositOf, optionalInputs, randomU64, reviveDecimals } from "./batch.js";
|
|
2
2
|
import { firstOption, inputsOf, isObject, isRefusal, refuse, uintOf, x402Chosen } from "./common.js";
|
|
3
3
|
const PAIRING = "x402/batch-settlement/solana";
|
|
4
|
-
|
|
4
|
+
/** A Solana key or blockhash in base58: 32 to 44 characters of the Bitcoin alphabet. */
|
|
5
|
+
export const KEY = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
5
6
|
const U64 = /^[0-9]{1,20}$/;
|
|
6
7
|
const U64_LIMIT = 1n << 64n;
|
|
7
8
|
const isU64 = (v) => typeof v === "string" && U64.test(v) && BigInt(v) < U64_LIMIT;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* A Hedera entity id, `shard.realm.num`, as `@integraledger/lcp`'s Hedera pairings read it: each part 0, or up to 19
|
|
3
|
+
* digits with no leading zero.
|
|
4
|
+
*/
|
|
2
5
|
export declare const HEDERA_ENTITY: RegExp;
|
|
3
6
|
export declare const x402ExactHedera: import("../types.js").BuyerPiece;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { bigintOf, bytesOf, inputsOf, isObject, isRefusal, refuse } from "./common.js";
|
|
2
2
|
import { railPiece } from "./x402-rail.js";
|
|
3
3
|
const PAIRING = "x402/exact/hedera";
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A Hedera entity id, `shard.realm.num`, as `@integraledger/lcp`'s Hedera pairings read it: each part 0, or up to 19
|
|
6
|
+
* digits with no leading zero.
|
|
7
|
+
*/
|
|
8
|
+
export const HEDERA_ENTITY = /^(0|[1-9][0-9]{0,18})\.(0|[1-9][0-9]{0,18})\.(0|[1-9][0-9]{0,18})$/;
|
|
6
9
|
const KEY_TYPES = ["ed25519", "ecdsa-secp256k1"];
|
|
7
10
|
function inputs(_accepted, given) {
|
|
8
11
|
const read = inputsOf(given, PAIRING, { node: "string", validStart: "object", maxFee: "decimal", decimals: "optional-uint" });
|
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
import { bigintOf, bytesOf, choiceOf, inputsOf, isObject, isRefusal, refuse, x402Chosen } from "./common.js";
|
|
2
2
|
import { identified, railOption } from "./x402-account-rails.js";
|
|
3
3
|
const PAIRING = "x402/exact/near";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* True for a NEAR account id: what near-account-id 3.0.0, the version nearcore locks, reads as an `AccountId`
|
|
6
|
+
* (src/validation.rs: `validate`, `MIN_LEN` and `MAX_LEN`), as the delegate action's sender is read. An id is 2 to 64
|
|
7
|
+
* characters, each a lowercase ASCII letter, a digit, `-`, `_` or `.`; a separator (`-`, `_` or `.`) is never first,
|
|
8
|
+
* never last, and never follows another. The length bounds count bytes, and every character an id may hold is one
|
|
9
|
+
* byte, so counting UTF-16 code units gives the same answer.
|
|
10
|
+
*/
|
|
11
|
+
function isNearAccountId(id) {
|
|
12
|
+
if (id.length < 2 || id.length > 64)
|
|
13
|
+
return false;
|
|
14
|
+
let afterSeparator = true;
|
|
15
|
+
for (let i = 0; i < id.length; i++) {
|
|
16
|
+
const c = id.charCodeAt(i);
|
|
17
|
+
const separator = c === 0x2d || c === 0x5f || c === 0x2e;
|
|
18
|
+
if (!separator && !((c >= 0x61 && c <= 0x7a) || (c >= 0x30 && c <= 0x39)))
|
|
19
|
+
return false;
|
|
20
|
+
if (separator && afterSeparator)
|
|
21
|
+
return false;
|
|
22
|
+
afterSeparator = separator;
|
|
23
|
+
}
|
|
24
|
+
return !afterSeparator;
|
|
25
|
+
}
|
|
5
26
|
export const x402ExactNear = Object.freeze({
|
|
6
27
|
choose(read, account, inputs, _now, ref) {
|
|
7
|
-
const o = railOption(read, account, ["near"], PAIRING,
|
|
28
|
+
const o = railOption(read, account, ["near"], PAIRING, isNearAccountId);
|
|
8
29
|
if (isRefusal(o))
|
|
9
30
|
return o;
|
|
10
31
|
const given = inputsOf(inputs, PAIRING, { publicKey: "string", accessKeyNonce: "decimal", finalHeight: "decimal" });
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The buyer piece for `x402/exact/solana`: the v0 message whose one memo is the option's `extra.memo`, signed by the
|
|
3
|
-
* payer as `solana-message`. The recent blockhash is the option's `extra.recentBlockhash` when it
|
|
4
|
-
* buyer's; the mint's decimals and token program are the buyer's reads.
|
|
3
|
+
* payer as `solana-message`. The recent blockhash is the option's `extra.recentBlockhash` when it is a base58 key of 32
|
|
4
|
+
* bytes, else the buyer's; the mint's decimals and token program are the buyer's reads.
|
|
5
5
|
*/
|
|
6
|
-
import type { Refusal } from "@integraledger/lcp";
|
|
7
|
-
/** A Solana address
|
|
6
|
+
import type { Refusal } from "@integraledger/lcp/core";
|
|
7
|
+
/** A Solana address or blockhash in base58: 32 to 44 characters of the Bitcoin alphabet. */
|
|
8
8
|
export declare const SOLANA_ADDRESS: RegExp;
|
|
9
9
|
/** `computeUnitPrice` as the build's bigint, where the choice carries one. */
|
|
10
10
|
export declare function withUnitPrice(c: Record<string, unknown>): Record<string, unknown> | Refusal;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { isKey } from "@integraledger/lcp/svm";
|
|
1
2
|
import { bigintOf, inputsOf, isRefusal, refuse } from "./common.js";
|
|
2
3
|
import { railPiece, signature64 } from "./x402-rail.js";
|
|
3
4
|
const PAIRING = "x402/exact/solana";
|
|
4
|
-
/** A Solana address
|
|
5
|
+
/** A Solana address or blockhash in base58: 32 to 44 characters of the Bitcoin alphabet. */
|
|
5
6
|
export const SOLANA_ADDRESS = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
6
7
|
/** `computeUnitPrice` as the build's bigint, where the choice carries one. */
|
|
7
8
|
export function withUnitPrice(c) {
|
|
@@ -12,7 +13,7 @@ export function withUnitPrice(c) {
|
|
|
12
13
|
}
|
|
13
14
|
function inputs(accepted, given) {
|
|
14
15
|
const offered = accepted.extra?.["recentBlockhash"];
|
|
15
|
-
const fromOffer =
|
|
16
|
+
const fromOffer = isKey(offered);
|
|
16
17
|
const read = inputsOf(given, PAIRING, {
|
|
17
18
|
decimals: "uint",
|
|
18
19
|
tokenProgram: "string",
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The buyer piece for `x402/exact/sui`: the wallet builds the scheme's payment, adds the request's `pureInput` as the
|
|
3
|
-
* one unused `Pure` input, bounds the expiration by epoch, signs, and answers
|
|
3
|
+
* one unused `Pure` input, bounds the expiration by epoch as the request asks, signs, and answers
|
|
4
|
+
* `{signature, transaction}`. The epoch bound is this piece's choice, not a condition of the record: a signed
|
|
5
|
+
* transaction without one that carries the hash completes, and is recorded.
|
|
4
6
|
*/
|
|
5
7
|
import { walletBuiltPiece } from "./x402-account-rails.js";
|
|
6
8
|
const SUI_ADDRESS = /^0x[0-9a-fA-F]{64}$/;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { bigintOf, bytesOf, choiceOf, inputsOf, isRefusal, refuse, x402Chosen } from "./common.js";
|
|
2
2
|
import { identified, railOption } from "./x402-account-rails.js";
|
|
3
3
|
const PAIRING = "x402/exact/tvm";
|
|
4
|
-
const RAW_ADDRESS =
|
|
4
|
+
const RAW_ADDRESS = /^(-?[0-9]{1,10}):[0-9a-fA-F]{64}$/;
|
|
5
|
+
/**
|
|
6
|
+
* A raw `workchain:hex` address whose workchain fits TL-B's `addr_std` `workchain_id:int8`, [-128, 127], as lcp's
|
|
7
|
+
* TON filter reads one.
|
|
8
|
+
*/
|
|
9
|
+
function isRawAddress(a) {
|
|
10
|
+
const m = RAW_ADDRESS.exec(a);
|
|
11
|
+
return m !== null && Number(m[1]) >= -128 && Number(m[1]) <= 127;
|
|
12
|
+
}
|
|
5
13
|
export const x402ExactTvm = Object.freeze({
|
|
6
14
|
choose(read, account, inputs, now, ref) {
|
|
7
|
-
const o = railOption(read, account, ["tvm"], PAIRING,
|
|
15
|
+
const o = railOption(read, account, ["tvm"], PAIRING, isRawAddress);
|
|
8
16
|
if (isRefusal(o))
|
|
9
17
|
return o;
|
|
10
18
|
const given = inputsOf(inputs, PAIRING, {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { inputsOf, refuse } from "./common.js";
|
|
2
2
|
import { railPiece } from "./x402-rail.js";
|
|
3
3
|
const PAIRING = "x402/exact/xrpl";
|
|
4
|
-
const BLOB = /^0x((?:[0-9a-fA-F]{2})+)$/;
|
|
5
4
|
function inputs(accepted, given) {
|
|
6
5
|
const ticket = accepted.extra?.["assetTransferMethod"] === "ticketSequence";
|
|
7
6
|
return inputsOf(given, PAIRING, {
|
|
@@ -10,10 +9,9 @@ function inputs(accepted, given) {
|
|
|
10
9
|
lastLedgerSequence: "uint",
|
|
11
10
|
});
|
|
12
11
|
}
|
|
13
|
-
/** The signed blob's hex digits
|
|
12
|
+
/** The signed blob as given: the build's `complete` reads it as hex digits without `0x`. */
|
|
14
13
|
function blob(signature) {
|
|
15
|
-
|
|
16
|
-
return m === null ? refuse("x402/signature-malformed") : m[1];
|
|
14
|
+
return typeof signature === "string" ? signature : refuse("x402/signature-malformed");
|
|
17
15
|
}
|
|
18
16
|
export const x402ExactXrpl = railPiece({
|
|
19
17
|
pairing: PAIRING,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The buyer pieces shared by the x402 pairings on the Solana, Stellar, XRPL, Hedera and Algorand rails: the first option
|
|
3
3
|
* on the account's network, the buyer's own inputs beside it as JSON, the build's request exactly as built, and the
|
|
4
|
-
* payment the
|
|
4
|
+
* payment the build's `complete` gives for the signer's answer, awaited where it answers a Promise, with the payment
|
|
5
|
+
* identifier appended where the challenge advertises it.
|
|
5
6
|
*/
|
|
6
|
-
import type { Json, Refusal } from "@integraledger/lcp";
|
|
7
|
+
import type { Json, Refusal } from "@integraledger/lcp/core";
|
|
7
8
|
import type { PaymentRequirements } from "@integraledger/lcp/x402";
|
|
8
9
|
import type { BuyerPiece, Inputs, Signature } from "../types.js";
|
|
9
10
|
/** One x402 rail pairing's buyer piece, described by what differs between rails. */
|
|
@@ -47,7 +47,7 @@ export function railPiece(rail) {
|
|
|
47
47
|
if (isRefusal(answer))
|
|
48
48
|
return answer;
|
|
49
49
|
const c = choiceOf(chosen);
|
|
50
|
-
const completed = unsigned.complete(answer);
|
|
50
|
+
const completed = await unsigned.complete(answer);
|
|
51
51
|
if (isRefusal(completed))
|
|
52
52
|
return completed;
|
|
53
53
|
let signed;
|
package/dist/transact.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* then `finish`. The agreement payment is signed only once the buyer's agent has approved it: the first call returns it
|
|
4
4
|
* in `approve`, and a second call with that payment as `approved` pays it and then the resource.
|
|
5
5
|
*/
|
|
6
|
-
import type { AtrHash } from "@integraledger/lcp";
|
|
6
|
+
import type { AtrHash } from "@integraledger/lcp/core";
|
|
7
7
|
import type { AgreementReceipt, Binding, Declined, Fetch, Presented, Signer, ToApprove, TransactOptions } from "./types.js";
|
|
8
8
|
/**
|
|
9
9
|
* `confirm`, then, for a pairing whose payment is not itself a public proof, the agreement, then the signer, then
|
|
@@ -13,7 +13,8 @@ import type { AgreementReceipt, Binding, Declined, Fetch, Presented, Signer, ToA
|
|
|
13
13
|
* the build is itself the payment the signer is not called; where the pairing has nothing for the buyer to sign,
|
|
14
14
|
* `signed` is null after the comparison. `agreement` is the agreement's receipt, where the pairing needs one. `landed`
|
|
15
15
|
* is `finish`'s, where it gives one. `signal` ends the agreement exchange. Options holding anything but `inputs`,
|
|
16
|
-
* `agreementSigner`, `approved` and `signal
|
|
16
|
+
* `agreementSigner`, `approved` and `signal`, or a signer or agreement signer whose `account` is not a string, are
|
|
17
|
+
* declined `no-payable-option` with `<namespace>/input-malformed` before any fetch or signer call.
|
|
17
18
|
*/
|
|
18
19
|
export declare function transact(doc: unknown, binding: Binding, signer: Signer, fetch: Fetch, options?: TransactOptions): Promise<{
|
|
19
20
|
signed: Presented | null;
|
package/dist/transact.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { exchange } from "./agreement.js";
|
|
2
|
-
import { confirm, declined, isObject, namespaceOf, pieceOf, signSteps, unsupported } from "./gate.js";
|
|
2
|
+
import { confirm, declined, hasAccount, isObject, namespaceOf, pieceOf, signSteps, unsupported } from "./gate.js";
|
|
3
3
|
/**
|
|
4
4
|
* `confirm`, then, for a pairing whose payment is not itself a public proof, the agreement, then the signer, then
|
|
5
5
|
* `finish`. Without `approved`, an agreement not yet recorded is returned as `approve`, the agreement payment for the
|
|
@@ -8,13 +8,14 @@ import { confirm, declined, isObject, namespaceOf, pieceOf, signSteps, unsupport
|
|
|
8
8
|
* the build is itself the payment the signer is not called; where the pairing has nothing for the buyer to sign,
|
|
9
9
|
* `signed` is null after the comparison. `agreement` is the agreement's receipt, where the pairing needs one. `landed`
|
|
10
10
|
* is `finish`'s, where it gives one. `signal` ends the agreement exchange. Options holding anything but `inputs`,
|
|
11
|
-
* `agreementSigner`, `approved` and `signal
|
|
11
|
+
* `agreementSigner`, `approved` and `signal`, or a signer or agreement signer whose `account` is not a string, are
|
|
12
|
+
* declined `no-payable-option` with `<namespace>/input-malformed` before any fetch or signer call.
|
|
12
13
|
*/
|
|
13
14
|
export async function transact(doc, binding, signer, fetch, options) {
|
|
14
15
|
if (pieceOf(binding) === undefined)
|
|
15
16
|
return unsupported(binding);
|
|
16
17
|
const ns = namespaceOf(binding);
|
|
17
|
-
if (!optionsOk(options))
|
|
18
|
+
if (!optionsOk(options) || !hasAccount(signer))
|
|
18
19
|
return declined("no-payable-option", `${ns}/input-malformed`);
|
|
19
20
|
const { inputs = {}, agreementSigner, approved, signal } = options ?? {};
|
|
20
21
|
const confirmed = await confirm(doc, binding, signer.account, fetch, inputs);
|
|
@@ -37,8 +38,8 @@ export async function transact(doc, binding, signer, fetch, options) {
|
|
|
37
38
|
const OPTION_KEYS = ["inputs", "agreementSigner", "approved", "signal"];
|
|
38
39
|
/**
|
|
39
40
|
* Whether `transact`'s options are absent, or an object holding only `inputs` (an object, or undefined),
|
|
40
|
-
* `agreementSigner` (an object with a `sign` function
|
|
41
|
-
* (an `AbortSignal`, or undefined).
|
|
41
|
+
* `agreementSigner` (an object with a `sign` function and a string `account`, or undefined), `approved` (an object, or
|
|
42
|
+
* undefined) and `signal` (an `AbortSignal`, or undefined).
|
|
42
43
|
*/
|
|
43
44
|
function optionsOk(options) {
|
|
44
45
|
if (options === undefined)
|
|
@@ -52,5 +53,7 @@ function optionsOk(options) {
|
|
|
52
53
|
return false;
|
|
53
54
|
if (signal !== undefined && !(signal instanceof AbortSignal))
|
|
54
55
|
return false;
|
|
55
|
-
|
|
56
|
+
if (agreementSigner === undefined)
|
|
57
|
+
return true;
|
|
58
|
+
return isObject(agreementSigner) && typeof agreementSigner["sign"] === "function" && hasAccount(agreementSigner);
|
|
56
59
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -68,22 +68,12 @@ export type SigningRequest = Extract<X402Unsigned, unknown>["request"] | Extract
|
|
|
68
68
|
requests: readonly (BatchRequest | WithinSigningRequest)[];
|
|
69
69
|
} | Extract<BatchRequest, {
|
|
70
70
|
kind: "ed25519-raw";
|
|
71
|
-
}
|
|
72
|
-
/** Several calls in one Tempo `0x76` transaction, in order, signed by the payer; broadcast by it where `broadcast`. */
|
|
73
|
-
export interface TempoCalls {
|
|
74
|
-
kind: "tempo-calls";
|
|
75
|
-
chainId: number;
|
|
76
|
-
calls: readonly {
|
|
77
|
-
to: `0x${string}`;
|
|
78
|
-
data: `0x${string}`;
|
|
79
|
-
}[];
|
|
80
|
-
validBefore: number;
|
|
81
|
-
broadcast: boolean;
|
|
82
|
-
}
|
|
71
|
+
}>;
|
|
83
72
|
/**
|
|
84
|
-
* The signer's answer, as JSON.
|
|
85
|
-
*
|
|
86
|
-
*
|
|
73
|
+
* The signer's answer, as JSON. Each kind's form is its buyer piece's: a signature for the kinds whose payment takes one
|
|
74
|
+
* signature, an object for the kinds whose payment takes several values, and a list, in order, for `batch`. Byte strings
|
|
75
|
+
* are `0x` hex, except where the signers guide names another form for the kind: base58, base64, or hex digits without
|
|
76
|
+
* `0x`.
|
|
87
77
|
*/
|
|
88
78
|
export type Signature = Json;
|
|
89
79
|
export interface Signer {
|
|
@@ -156,7 +146,7 @@ export interface Read {
|
|
|
156
146
|
/**
|
|
157
147
|
* The agreement payment, for the buyer's agent to approve before anything is signed: the agreement URL; `option`, the
|
|
158
148
|
* option of the agreement URL's payment request that the gate pays, whose `amount`, `asset`, `payTo` and `network` are
|
|
159
|
-
*
|
|
149
|
+
* the terms the agent approves; and `required`, that payment request as the agreement URL served it.
|
|
160
150
|
*/
|
|
161
151
|
export interface AgreementPayment {
|
|
162
152
|
readonly url: string;
|