@integraledger/terms 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +539 -0
- package/dist/agreement.d.ts +23 -0
- package/dist/agreement.js +264 -0
- package/dist/channels.d.ts +49 -0
- package/dist/channels.js +395 -0
- package/dist/gate.d.ts +69 -0
- package/dist/gate.js +347 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/pairings/ack-payment-request.d.ts +1 -0
- package/dist/pairings/ack-payment-request.js +12 -0
- package/dist/pairings/acp-checkout-delegated.d.ts +2 -0
- package/dist/pairings/acp-checkout-delegated.js +28 -0
- package/dist/pairings/acp-checkout-undelegated.d.ts +1 -0
- package/dist/pairings/acp-checkout-undelegated.js +11 -0
- package/dist/pairings/ap2-checkout-mandate.d.ts +2 -0
- package/dist/pairings/ap2-checkout-mandate.js +23 -0
- package/dist/pairings/batch.d.ts +29 -0
- package/dist/pairings/batch.js +83 -0
- package/dist/pairings/card-mastercard-vi-autonomous.d.ts +1 -0
- package/dist/pairings/card-mastercard-vi-autonomous.js +3 -0
- package/dist/pairings/card-mastercard-vi-immediate.d.ts +1 -0
- package/dist/pairings/card-mastercard-vi-immediate.js +3 -0
- package/dist/pairings/card-seller-reference.d.ts +1 -0
- package/dist/pairings/card-seller-reference.js +3 -0
- package/dist/pairings/card-visa-tap.d.ts +1 -0
- package/dist/pairings/card-visa-tap.js +3 -0
- package/dist/pairings/card.d.ts +7 -0
- package/dist/pairings/card.js +68 -0
- package/dist/pairings/common.d.ts +54 -0
- package/dist/pairings/common.js +134 -0
- package/dist/pairings/evm-x402.d.ts +3 -0
- package/dist/pairings/evm-x402.js +49 -0
- package/dist/pairings/index.d.ts +3 -0
- package/dist/pairings/index.js +134 -0
- package/dist/pairings/lightning.d.ts +17 -0
- package/dist/pairings/lightning.js +112 -0
- package/dist/pairings/lnbtc-request.d.ts +24 -0
- package/dist/pairings/lnbtc-request.js +175 -0
- package/dist/pairings/mpp-charge-card.d.ts +1 -0
- package/dist/pairings/mpp-charge-card.js +3 -0
- package/dist/pairings/mpp-charge-evm-authorization.d.ts +1 -0
- package/dist/pairings/mpp-charge-evm-authorization.js +3 -0
- package/dist/pairings/mpp-charge-evm-hash.d.ts +1 -0
- package/dist/pairings/mpp-charge-evm-hash.js +3 -0
- package/dist/pairings/mpp-charge-evm-permit2.d.ts +1 -0
- package/dist/pairings/mpp-charge-evm-permit2.js +3 -0
- package/dist/pairings/mpp-charge-evm-transaction.d.ts +1 -0
- package/dist/pairings/mpp-charge-evm-transaction.js +3 -0
- package/dist/pairings/mpp-charge-hedera.d.ts +23 -0
- package/dist/pairings/mpp-charge-hedera.js +137 -0
- package/dist/pairings/mpp-charge-nearintents.d.ts +2 -0
- package/dist/pairings/mpp-charge-nearintents.js +19 -0
- package/dist/pairings/mpp-charge-solana.d.ts +1 -0
- package/dist/pairings/mpp-charge-solana.js +25 -0
- package/dist/pairings/mpp-charge-stellar.d.ts +1 -0
- package/dist/pairings/mpp-charge-stellar.js +16 -0
- package/dist/pairings/mpp-charge-stripe.d.ts +1 -0
- package/dist/pairings/mpp-charge-stripe.js +3 -0
- package/dist/pairings/mpp-charge-tempo-memo.d.ts +9 -0
- package/dist/pairings/mpp-charge-tempo-memo.js +10 -0
- package/dist/pairings/mpp-charge-tempo-push.d.ts +12 -0
- package/dist/pairings/mpp-charge-tempo-push.js +21 -0
- package/dist/pairings/mpp-charge-usdc-evm.d.ts +1 -0
- package/dist/pairings/mpp-charge-usdc-evm.js +6 -0
- package/dist/pairings/mpp-charge-usdc-gateway.d.ts +2 -0
- package/dist/pairings/mpp-charge-usdc-gateway.js +33 -0
- package/dist/pairings/mpp-charge-usdc-solana.d.ts +1 -0
- package/dist/pairings/mpp-charge-usdc-solana.js +25 -0
- package/dist/pairings/mpp-charge-usdc-stacks.d.ts +1 -0
- package/dist/pairings/mpp-charge-usdc-stacks.js +17 -0
- package/dist/pairings/mpp-charge-xrpl.d.ts +1 -0
- package/dist/pairings/mpp-charge-xrpl.js +20 -0
- package/dist/pairings/mpp-confirm-only.d.ts +2 -0
- package/dist/pairings/mpp-confirm-only.js +21 -0
- package/dist/pairings/mpp-rails.d.ts +48 -0
- package/dist/pairings/mpp-rails.js +71 -0
- package/dist/pairings/mpp-session-evm.d.ts +1 -0
- package/dist/pairings/mpp-session-evm.js +3 -0
- package/dist/pairings/mpp-session-hedera.d.ts +2 -0
- package/dist/pairings/mpp-session-hedera.js +41 -0
- package/dist/pairings/mpp-session-solana.d.ts +1 -0
- package/dist/pairings/mpp-session-solana.js +60 -0
- package/dist/pairings/mpp-session-tempo.d.ts +1 -0
- package/dist/pairings/mpp-session-tempo.js +3 -0
- package/dist/pairings/mpp-session-xrpl.d.ts +1 -0
- package/dist/pairings/mpp-session-xrpl.js +42 -0
- package/dist/pairings/mpp-session.d.ts +5 -0
- package/dist/pairings/mpp-session.js +65 -0
- package/dist/pairings/mpp-subscription-stripe.d.ts +1 -0
- package/dist/pairings/mpp-subscription-stripe.js +6 -0
- package/dist/pairings/mpp-subscription-tempo.d.ts +2 -0
- package/dist/pairings/mpp-subscription-tempo.js +2 -0
- package/dist/pairings/mpp.d.ts +43 -0
- package/dist/pairings/mpp.js +194 -0
- package/dist/pairings/protocol-groups.d.ts +17 -0
- package/dist/pairings/protocol-groups.js +27 -0
- package/dist/pairings/ucp-booking-ap2-mandate.d.ts +1 -0
- package/dist/pairings/ucp-booking-ap2-mandate.js +3 -0
- package/dist/pairings/ucp-booking-unsigned.d.ts +1 -0
- package/dist/pairings/ucp-booking-unsigned.js +3 -0
- package/dist/pairings/ucp-checkout-ap2-mandate.d.ts +1 -0
- package/dist/pairings/ucp-checkout-ap2-mandate.js +3 -0
- package/dist/pairings/ucp-checkout-unsigned.d.ts +1 -0
- package/dist/pairings/ucp-checkout-unsigned.js +3 -0
- package/dist/pairings/ucp.d.ts +5 -0
- package/dist/pairings/ucp.js +35 -0
- package/dist/pairings/x402-account-rails.d.ts +25 -0
- package/dist/pairings/x402-account-rails.js +52 -0
- package/dist/pairings/x402-auth-capture-eip155-eip3009.d.ts +1 -0
- package/dist/pairings/x402-auth-capture-eip155-eip3009.js +3 -0
- package/dist/pairings/x402-auth-capture-eip155-permit2.d.ts +1 -0
- package/dist/pairings/x402-auth-capture-eip155-permit2.js +3 -0
- package/dist/pairings/x402-batch-settlement-cloudflare.d.ts +2 -0
- package/dist/pairings/x402-batch-settlement-cloudflare.js +21 -0
- package/dist/pairings/x402-batch-settlement-eip155.d.ts +2 -0
- package/dist/pairings/x402-batch-settlement-eip155.js +32 -0
- package/dist/pairings/x402-batch-settlement-solana.d.ts +2 -0
- package/dist/pairings/x402-batch-settlement-solana.js +55 -0
- package/dist/pairings/x402-exact-algorand.d.ts +1 -0
- package/dist/pairings/x402-exact-algorand.js +37 -0
- package/dist/pairings/x402-exact-aptos.d.ts +1 -0
- package/dist/pairings/x402-exact-aptos.js +9 -0
- package/dist/pairings/x402-exact-cardano.d.ts +1 -0
- package/dist/pairings/x402-exact-cardano.js +7 -0
- package/dist/pairings/x402-exact-casper.d.ts +2 -0
- package/dist/pairings/x402-exact-casper.js +21 -0
- package/dist/pairings/x402-exact-ccd.d.ts +2 -0
- package/dist/pairings/x402-exact-ccd.js +20 -0
- package/dist/pairings/x402-exact-eip155-eip3009.d.ts +1 -0
- package/dist/pairings/x402-exact-eip155-eip3009.js +3 -0
- package/dist/pairings/x402-exact-eip155-erc7710-salt.d.ts +1 -0
- package/dist/pairings/x402-exact-eip155-erc7710-salt.js +3 -0
- package/dist/pairings/x402-exact-eip155-erc7710.d.ts +1 -0
- package/dist/pairings/x402-exact-eip155-erc7710.js +3 -0
- package/dist/pairings/x402-exact-eip155-permit2.d.ts +1 -0
- package/dist/pairings/x402-exact-eip155-permit2.js +3 -0
- package/dist/pairings/x402-exact-hedera-transfer-executor.d.ts +1 -0
- package/dist/pairings/x402-exact-hedera-transfer-executor.js +23 -0
- package/dist/pairings/x402-exact-hedera.d.ts +3 -0
- package/dist/pairings/x402-exact-hedera.js +46 -0
- package/dist/pairings/x402-exact-near.d.ts +2 -0
- package/dist/pairings/x402-exact-near.js +34 -0
- package/dist/pairings/x402-exact-polkadot-lcp-assets-remark.d.ts +2 -0
- package/dist/pairings/x402-exact-polkadot-lcp-assets-remark.js +20 -0
- package/dist/pairings/x402-exact-solana.d.ts +11 -0
- package/dist/pairings/x402-exact-solana.js +36 -0
- package/dist/pairings/x402-exact-starknet.d.ts +2 -0
- package/dist/pairings/x402-exact-starknet.js +20 -0
- package/dist/pairings/x402-exact-stellar.d.ts +1 -0
- package/dist/pairings/x402-exact-stellar.js +17 -0
- package/dist/pairings/x402-exact-sui.d.ts +1 -0
- package/dist/pairings/x402-exact-sui.js +10 -0
- package/dist/pairings/x402-exact-tron-lcp-trc20-memo.d.ts +2 -0
- package/dist/pairings/x402-exact-tron-lcp-trc20-memo.js +45 -0
- package/dist/pairings/x402-exact-tvm.d.ts +2 -0
- package/dist/pairings/x402-exact-tvm.js +35 -0
- package/dist/pairings/x402-exact-xrpl.d.ts +1 -0
- package/dist/pairings/x402-exact-xrpl.js +27 -0
- package/dist/pairings/x402-rail.d.ts +31 -0
- package/dist/pairings/x402-rail.js +65 -0
- package/dist/pairings/x402-upto-eip155-permit2.d.ts +1 -0
- package/dist/pairings/x402-upto-eip155-permit2.js +3 -0
- package/dist/pairings/x402-upto-solana.d.ts +1 -0
- package/dist/pairings/x402-upto-solana.js +42 -0
- package/dist/transact.d.ts +20 -0
- package/dist/transact.js +53 -0
- package/dist/types.d.ts +169 -0
- package/dist/types.js +2 -0
- package/package.json +64 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { choiceOf, firstOption, isObject, refuse, withPaymentIdentifier, x402Chosen } from "./common.js";
|
|
2
|
+
const ID = "x402/exact/ccd";
|
|
3
|
+
export const x402ExactCcd = Object.freeze({
|
|
4
|
+
choose(read, account, _inputs, now, ref) {
|
|
5
|
+
const o = firstOption(read, account, "ccd", ID);
|
|
6
|
+
if ("refused" in o)
|
|
7
|
+
return refuse("x402/no-payable-option");
|
|
8
|
+
return x402Chosen(ID, { required: o.required, accepted: o.accepted, now }, ref);
|
|
9
|
+
},
|
|
10
|
+
choice: (chosen) => choiceOf(chosen) ?? refuse("x402/choice-malformed"),
|
|
11
|
+
request: (unsigned) => unsigned.request,
|
|
12
|
+
async complete(unsigned, signature, chosen) {
|
|
13
|
+
if (!isObject(signature))
|
|
14
|
+
return refuse("x402/signature-malformed");
|
|
15
|
+
const signed = unsigned.complete(signature);
|
|
16
|
+
if ("refused" in signed)
|
|
17
|
+
return signed;
|
|
18
|
+
return withPaymentIdentifier(signed, choiceOf(chosen)?.["required"], chosen.ref);
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const x402ExactEip155Eip3009: import("../types.js").BuyerPiece;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const x402ExactEip155Erc7710Salt: import("../types.js").BuyerPiece;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const x402ExactEip155Erc7710: import("../types.js").BuyerPiece;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const x402ExactEip155Permit2: import("../types.js").BuyerPiece;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const x402ExactHederaTransferExecutor: import("../types.js").BuyerPiece;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isObject, refuse } from "./common.js";
|
|
2
|
+
import { HEDERA_ENTITY } from "./x402-exact-hedera.js";
|
|
3
|
+
import { railPiece } from "./x402-rail.js";
|
|
4
|
+
/** The wallet's answer, its three members as strings. */
|
|
5
|
+
function answer(signature) {
|
|
6
|
+
if (!isObject(signature))
|
|
7
|
+
return refuse("x402/signature-malformed");
|
|
8
|
+
const { payer, executor, authorization } = signature;
|
|
9
|
+
if (typeof payer !== "string" || typeof executor !== "string" || typeof authorization !== "string") {
|
|
10
|
+
return refuse("x402/signature-malformed");
|
|
11
|
+
}
|
|
12
|
+
return { payer, executor, authorization };
|
|
13
|
+
}
|
|
14
|
+
export const x402ExactHederaTransferExecutor = railPiece({
|
|
15
|
+
pairing: "x402/exact/hedera/transfer-executor",
|
|
16
|
+
namespace: "hedera",
|
|
17
|
+
address: HEDERA_ENTITY,
|
|
18
|
+
payer: null,
|
|
19
|
+
now: true,
|
|
20
|
+
inputs: () => ({}),
|
|
21
|
+
revive: (c) => c,
|
|
22
|
+
answer,
|
|
23
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { bigintOf, bytesOf, inputsOf, isObject, isRefusal, refuse } from "./common.js";
|
|
2
|
+
import { railPiece } from "./x402-rail.js";
|
|
3
|
+
const PAIRING = "x402/exact/hedera";
|
|
4
|
+
/** A Hedera entity id, `shard.realm.num`. */
|
|
5
|
+
export const HEDERA_ENTITY = /^[0-9]{1,20}\.[0-9]{1,20}\.[0-9]{1,20}$/;
|
|
6
|
+
const KEY_TYPES = ["ed25519", "ecdsa-secp256k1"];
|
|
7
|
+
function inputs(_accepted, given) {
|
|
8
|
+
const read = inputsOf(given, PAIRING, { node: "string", validStart: "object", maxFee: "decimal", decimals: "optional-uint" });
|
|
9
|
+
if (isRefusal(read))
|
|
10
|
+
return read;
|
|
11
|
+
const validStart = inputsOf(read["validStart"], PAIRING, { seconds: "decimal", nanos: "uint" });
|
|
12
|
+
if (isRefusal(validStart))
|
|
13
|
+
return validStart;
|
|
14
|
+
return { ...read, validStart };
|
|
15
|
+
}
|
|
16
|
+
function revive(c) {
|
|
17
|
+
const vs = c["validStart"];
|
|
18
|
+
const seconds = isObject(vs) ? bigintOf(vs["seconds"]) : undefined;
|
|
19
|
+
const maxFee = bigintOf(c["maxFee"]);
|
|
20
|
+
if (!isObject(vs) || seconds === undefined || maxFee === undefined)
|
|
21
|
+
return refuse("x402/choice-malformed");
|
|
22
|
+
return { ...c, validStart: { ...vs, seconds }, maxFee };
|
|
23
|
+
}
|
|
24
|
+
/** `{publicKey, signature, type}` with the key and signature as bytes. */
|
|
25
|
+
function answer(signature) {
|
|
26
|
+
if (!isObject(signature))
|
|
27
|
+
return refuse("x402/signature-malformed");
|
|
28
|
+
const publicKey = bytesOf(signature["publicKey"]);
|
|
29
|
+
const bytes = bytesOf(signature["signature"]);
|
|
30
|
+
const type = signature["type"];
|
|
31
|
+
if (publicKey === undefined || bytes === undefined || typeof type !== "string" || !KEY_TYPES.includes(type)) {
|
|
32
|
+
return refuse("x402/signature-malformed");
|
|
33
|
+
}
|
|
34
|
+
return { publicKey, signature: bytes, type };
|
|
35
|
+
}
|
|
36
|
+
export const x402ExactHedera = railPiece({
|
|
37
|
+
pairing: PAIRING,
|
|
38
|
+
namespace: "hedera",
|
|
39
|
+
address: HEDERA_ENTITY,
|
|
40
|
+
payer: "payer",
|
|
41
|
+
now: false,
|
|
42
|
+
inputs,
|
|
43
|
+
revive,
|
|
44
|
+
answer,
|
|
45
|
+
payload: (transaction) => ({ transaction }),
|
|
46
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { bigintOf, bytesOf, choiceOf, inputsOf, isObject, isRefusal, refuse, x402Chosen } from "./common.js";
|
|
2
|
+
import { identified, railOption } from "./x402-account-rails.js";
|
|
3
|
+
const PAIRING = "x402/exact/near";
|
|
4
|
+
const NEAR_ACCOUNT = /^[a-z0-9._-]{2,64}$/;
|
|
5
|
+
export const x402ExactNear = Object.freeze({
|
|
6
|
+
choose(read, account, inputs, _now, ref) {
|
|
7
|
+
const o = railOption(read, account, ["near"], PAIRING, (a) => NEAR_ACCOUNT.test(a));
|
|
8
|
+
if (isRefusal(o))
|
|
9
|
+
return o;
|
|
10
|
+
const given = inputsOf(inputs, PAIRING, { publicKey: "string", accessKeyNonce: "decimal", finalHeight: "decimal" });
|
|
11
|
+
if (isRefusal(given))
|
|
12
|
+
return given;
|
|
13
|
+
return x402Chosen(PAIRING, { required: o.required, accepted: o.accepted, payer: o.address, ...given }, ref);
|
|
14
|
+
},
|
|
15
|
+
choice(chosen) {
|
|
16
|
+
const c = choiceOf(chosen);
|
|
17
|
+
const accessKeyNonce = bigintOf(c?.["accessKeyNonce"]);
|
|
18
|
+
const finalHeight = bigintOf(c?.["finalHeight"]);
|
|
19
|
+
if (c === undefined || accessKeyNonce === undefined || finalHeight === undefined) {
|
|
20
|
+
return refuse("x402/choice-malformed");
|
|
21
|
+
}
|
|
22
|
+
return { ...c, accessKeyNonce, finalHeight };
|
|
23
|
+
},
|
|
24
|
+
request: (unsigned) => unsigned.request,
|
|
25
|
+
async complete(unsigned, signature, chosen) {
|
|
26
|
+
if (!isObject(signature))
|
|
27
|
+
return refuse("x402/signature-malformed");
|
|
28
|
+
const { keyType } = signature;
|
|
29
|
+
const bytes = bytesOf(signature["bytes"]);
|
|
30
|
+
if ((keyType !== 0 && keyType !== 1) || bytes === undefined)
|
|
31
|
+
return refuse("x402/signature-malformed");
|
|
32
|
+
return identified(unsigned.complete({ keyType, bytes }), chosen);
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ss58Decode } from "@integraledger/lcp/polkadot";
|
|
2
|
+
import { bytesOf, choiceOf, isRefusal, refuse, x402Chosen } from "./common.js";
|
|
3
|
+
import { identified, railOption } from "./x402-account-rails.js";
|
|
4
|
+
const PAIRING = "x402/exact/polkadot/lcp-assets-remark";
|
|
5
|
+
export const x402ExactPolkadotLcpAssetsRemark = Object.freeze({
|
|
6
|
+
choose(read, account, _inputs, _now, ref) {
|
|
7
|
+
const o = railOption(read, account, ["polkadot"], PAIRING, (a) => !isRefusal(ss58Decode(a)));
|
|
8
|
+
if (isRefusal(o))
|
|
9
|
+
return o;
|
|
10
|
+
return x402Chosen(PAIRING, { required: o.required, accepted: o.accepted }, ref);
|
|
11
|
+
},
|
|
12
|
+
choice: (chosen) => choiceOf(chosen) ?? refuse("x402/choice-malformed"),
|
|
13
|
+
request: (unsigned) => unsigned.request,
|
|
14
|
+
async complete(unsigned, signature, chosen) {
|
|
15
|
+
const extrinsic = bytesOf(signature);
|
|
16
|
+
if (extrinsic === undefined || extrinsic.length === 0)
|
|
17
|
+
return refuse("x402/signature-malformed");
|
|
18
|
+
return identified(unsigned.complete(extrinsic), chosen);
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
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 names one, else the
|
|
4
|
+
* buyer's; the mint's decimals and token program are the buyer's reads.
|
|
5
|
+
*/
|
|
6
|
+
import type { Refusal } from "@integraledger/lcp";
|
|
7
|
+
/** A Solana address: base58 of 32 bytes. */
|
|
8
|
+
export declare const SOLANA_ADDRESS: RegExp;
|
|
9
|
+
/** `computeUnitPrice` as the build's bigint, where the choice carries one. */
|
|
10
|
+
export declare function withUnitPrice(c: Record<string, unknown>): Record<string, unknown> | Refusal;
|
|
11
|
+
export declare const x402ExactSolana: import("../types.js").BuyerPiece;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { bigintOf, inputsOf, isRefusal, refuse } from "./common.js";
|
|
2
|
+
import { railPiece, signature64 } from "./x402-rail.js";
|
|
3
|
+
const PAIRING = "x402/exact/solana";
|
|
4
|
+
/** A Solana address: base58 of 32 bytes. */
|
|
5
|
+
export const SOLANA_ADDRESS = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
6
|
+
/** `computeUnitPrice` as the build's bigint, where the choice carries one. */
|
|
7
|
+
export function withUnitPrice(c) {
|
|
8
|
+
if (c["computeUnitPrice"] === undefined)
|
|
9
|
+
return c;
|
|
10
|
+
const price = bigintOf(c["computeUnitPrice"]);
|
|
11
|
+
return price === undefined ? refuse("x402/choice-malformed") : { ...c, computeUnitPrice: price };
|
|
12
|
+
}
|
|
13
|
+
function inputs(accepted, given) {
|
|
14
|
+
const offered = accepted.extra?.["recentBlockhash"];
|
|
15
|
+
const fromOffer = typeof offered === "string" && offered !== "";
|
|
16
|
+
const read = inputsOf(given, PAIRING, {
|
|
17
|
+
decimals: "uint",
|
|
18
|
+
tokenProgram: "string",
|
|
19
|
+
...(fromOffer ? {} : { recentBlockhash: "string" }),
|
|
20
|
+
computeUnitLimit: "optional-uint",
|
|
21
|
+
computeUnitPrice: "optional-decimal",
|
|
22
|
+
});
|
|
23
|
+
if (isRefusal(read))
|
|
24
|
+
return read;
|
|
25
|
+
return fromOffer ? { ...read, recentBlockhash: offered } : read;
|
|
26
|
+
}
|
|
27
|
+
export const x402ExactSolana = railPiece({
|
|
28
|
+
pairing: PAIRING,
|
|
29
|
+
namespace: "solana",
|
|
30
|
+
address: SOLANA_ADDRESS,
|
|
31
|
+
payer: "payer",
|
|
32
|
+
now: false,
|
|
33
|
+
inputs,
|
|
34
|
+
revive: withUnitPrice,
|
|
35
|
+
answer: signature64,
|
|
36
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { choiceOf, isRefusal, refuse, x402Chosen } from "./common.js";
|
|
2
|
+
import { identified, railOption } from "./x402-account-rails.js";
|
|
3
|
+
const PAIRING = "x402/exact/starknet";
|
|
4
|
+
const FELT = /^0x[0-9a-fA-F]{1,64}$/;
|
|
5
|
+
export const x402ExactStarknet = Object.freeze({
|
|
6
|
+
choose(read, account, _inputs, now, ref) {
|
|
7
|
+
const o = railOption(read, account, ["starknet"], PAIRING, (a) => FELT.test(a));
|
|
8
|
+
if (isRefusal(o))
|
|
9
|
+
return o;
|
|
10
|
+
return x402Chosen(PAIRING, { required: o.required, accepted: o.accepted, from: o.address, now }, ref);
|
|
11
|
+
},
|
|
12
|
+
choice: (chosen) => choiceOf(chosen) ?? refuse("x402/choice-malformed"),
|
|
13
|
+
request: (unsigned) => unsigned.request,
|
|
14
|
+
async complete(unsigned, signature, chosen) {
|
|
15
|
+
if (!Array.isArray(signature) || !signature.every((s) => typeof s === "string")) {
|
|
16
|
+
return refuse("x402/signature-malformed");
|
|
17
|
+
}
|
|
18
|
+
return identified(unsigned.complete(signature), chosen);
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const x402ExactStellar: import("../types.js").BuyerPiece;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { inputsOf } from "./common.js";
|
|
2
|
+
import { railPiece, signature64 } from "./x402-rail.js";
|
|
3
|
+
const PAIRING = "x402/exact/stellar";
|
|
4
|
+
function inputs(_accepted, given) {
|
|
5
|
+
return inputsOf(given, PAIRING, { simulatedXdr: "string", currentLedger: "uint" });
|
|
6
|
+
}
|
|
7
|
+
export const x402ExactStellar = railPiece({
|
|
8
|
+
pairing: PAIRING,
|
|
9
|
+
namespace: "stellar",
|
|
10
|
+
address: /^G[A-Z2-7]{55}$/,
|
|
11
|
+
payer: null,
|
|
12
|
+
now: false,
|
|
13
|
+
inputs,
|
|
14
|
+
revive: (c) => c,
|
|
15
|
+
answer: signature64,
|
|
16
|
+
payload: (transaction) => ({ transaction }),
|
|
17
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const x402ExactSui: import("../types.js").BuyerPiece;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
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 `{signature, transaction}`.
|
|
4
|
+
*/
|
|
5
|
+
import { walletBuiltPiece } from "./x402-account-rails.js";
|
|
6
|
+
const SUI_ADDRESS = /^0x[0-9a-fA-F]{64}$/;
|
|
7
|
+
export const x402ExactSui = walletBuiltPiece("x402/exact/sui", ["sui"], (a) => SUI_ADDRESS.test(a), [
|
|
8
|
+
"signature",
|
|
9
|
+
"transaction",
|
|
10
|
+
]);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { bigintOf, bytesOf, choiceOf, inputsOf, isObject, isRefusal, refuse, x402Chosen } from "./common.js";
|
|
2
|
+
import { identified, railOption } from "./x402-account-rails.js";
|
|
3
|
+
const PAIRING = "x402/exact/tron/lcp-trc20-memo";
|
|
4
|
+
const TRON_ADDRESS = /^T[1-9A-HJ-NP-Za-km-z]{33}$/;
|
|
5
|
+
/** A block reference `{number, id}`: the number as a decimal string and the 32-byte id as `0x` hex. */
|
|
6
|
+
function refBlockOf(v) {
|
|
7
|
+
if (!isObject(v))
|
|
8
|
+
return undefined;
|
|
9
|
+
const number = bigintOf(v["number"]);
|
|
10
|
+
const id = v["id"];
|
|
11
|
+
if (number === undefined || bytesOf(id, 32) === undefined)
|
|
12
|
+
return undefined;
|
|
13
|
+
return { number, id: id };
|
|
14
|
+
}
|
|
15
|
+
export const x402ExactTronLcpTrc20Memo = Object.freeze({
|
|
16
|
+
choose(read, account, inputs, now, ref) {
|
|
17
|
+
const o = railOption(read, account, ["tron"], PAIRING, (a) => TRON_ADDRESS.test(a));
|
|
18
|
+
if (isRefusal(o))
|
|
19
|
+
return o;
|
|
20
|
+
const given = inputsOf(inputs, PAIRING, { refBlock: "object", feeLimit: "decimal" });
|
|
21
|
+
if (isRefusal(given))
|
|
22
|
+
return given;
|
|
23
|
+
if (refBlockOf(given["refBlock"]) === undefined)
|
|
24
|
+
return refuse("x402/input-missing");
|
|
25
|
+
const nowMs = (BigInt(now) * 1000n).toString();
|
|
26
|
+
return x402Chosen(PAIRING, { required: o.required, accepted: o.accepted, payer: o.address, now: nowMs, ...given }, ref);
|
|
27
|
+
},
|
|
28
|
+
choice(chosen) {
|
|
29
|
+
const c = choiceOf(chosen);
|
|
30
|
+
const refBlock = refBlockOf(c?.["refBlock"]);
|
|
31
|
+
const now = bigintOf(c?.["now"]);
|
|
32
|
+
const feeLimit = bigintOf(c?.["feeLimit"]);
|
|
33
|
+
if (c === undefined || refBlock === undefined || now === undefined || feeLimit === undefined) {
|
|
34
|
+
return refuse("x402/choice-malformed");
|
|
35
|
+
}
|
|
36
|
+
return { ...c, refBlock, now, feeLimit };
|
|
37
|
+
},
|
|
38
|
+
request: (unsigned) => unsigned.request,
|
|
39
|
+
async complete(unsigned, signature, chosen) {
|
|
40
|
+
const bytes = bytesOf(signature, 65);
|
|
41
|
+
if (bytes === undefined)
|
|
42
|
+
return refuse("x402/signature-malformed");
|
|
43
|
+
return identified(unsigned.complete(bytes), chosen);
|
|
44
|
+
},
|
|
45
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { bigintOf, bytesOf, choiceOf, inputsOf, isRefusal, refuse, x402Chosen } from "./common.js";
|
|
2
|
+
import { identified, railOption } from "./x402-account-rails.js";
|
|
3
|
+
const PAIRING = "x402/exact/tvm";
|
|
4
|
+
const RAW_ADDRESS = /^-?[0-9]{1,10}:[0-9a-fA-F]{64}$/;
|
|
5
|
+
export const x402ExactTvm = Object.freeze({
|
|
6
|
+
choose(read, account, inputs, now, ref) {
|
|
7
|
+
const o = railOption(read, account, ["tvm"], PAIRING, (a) => RAW_ADDRESS.test(a));
|
|
8
|
+
if (isRefusal(o))
|
|
9
|
+
return o;
|
|
10
|
+
const given = inputsOf(inputs, PAIRING, {
|
|
11
|
+
walletId: "uint",
|
|
12
|
+
seqno: "uint",
|
|
13
|
+
jettonWallet: "string",
|
|
14
|
+
attachNanotons: "decimal",
|
|
15
|
+
stateInit: "optional-string",
|
|
16
|
+
});
|
|
17
|
+
if (isRefusal(given))
|
|
18
|
+
return given;
|
|
19
|
+
return x402Chosen(PAIRING, { required: o.required, accepted: o.accepted, wallet: o.address, now, ...given }, ref);
|
|
20
|
+
},
|
|
21
|
+
choice(chosen) {
|
|
22
|
+
const c = choiceOf(chosen);
|
|
23
|
+
const attachNanotons = bigintOf(c?.["attachNanotons"]);
|
|
24
|
+
if (c === undefined || attachNanotons === undefined)
|
|
25
|
+
return refuse("x402/choice-malformed");
|
|
26
|
+
return { ...c, attachNanotons };
|
|
27
|
+
},
|
|
28
|
+
request: (unsigned) => unsigned.request,
|
|
29
|
+
async complete(unsigned, signature, chosen) {
|
|
30
|
+
const bytes = bytesOf(signature, 64);
|
|
31
|
+
if (bytes === undefined)
|
|
32
|
+
return refuse("x402/signature-malformed");
|
|
33
|
+
return identified(unsigned.complete(bytes), chosen);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const x402ExactXrpl: import("../types.js").BuyerPiece;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { inputsOf, refuse } from "./common.js";
|
|
2
|
+
import { railPiece } from "./x402-rail.js";
|
|
3
|
+
const PAIRING = "x402/exact/xrpl";
|
|
4
|
+
const BLOB = /^0x((?:[0-9a-fA-F]{2})+)$/;
|
|
5
|
+
function inputs(accepted, given) {
|
|
6
|
+
const ticket = accepted.extra?.["assetTransferMethod"] === "ticketSequence";
|
|
7
|
+
return inputsOf(given, PAIRING, {
|
|
8
|
+
fee: "decimal",
|
|
9
|
+
...(ticket ? { ticketSequence: "uint" } : { sequence: "uint" }),
|
|
10
|
+
lastLedgerSequence: "uint",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/** The signed blob's hex digits, from `0x` hex. */
|
|
14
|
+
function blob(signature) {
|
|
15
|
+
const m = typeof signature === "string" ? BLOB.exec(signature) : null;
|
|
16
|
+
return m === null ? refuse("x402/signature-malformed") : m[1];
|
|
17
|
+
}
|
|
18
|
+
export const x402ExactXrpl = railPiece({
|
|
19
|
+
pairing: PAIRING,
|
|
20
|
+
namespace: "xrpl",
|
|
21
|
+
address: /^r[1-9A-HJ-NP-Za-km-z]{24,34}$/,
|
|
22
|
+
payer: "account",
|
|
23
|
+
now: false,
|
|
24
|
+
inputs,
|
|
25
|
+
revive: (c) => c,
|
|
26
|
+
answer: blob,
|
|
27
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The buyer pieces shared by the x402 pairings on the Solana, Stellar, XRPL, Hedera and Algorand rails: the first option
|
|
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 signer's answer completes, with the payment identifier appended where the challenge advertises it.
|
|
5
|
+
*/
|
|
6
|
+
import type { Json, Refusal } from "@integraledger/lcp";
|
|
7
|
+
import type { PaymentRequirements } from "@integraledger/lcp/x402";
|
|
8
|
+
import type { BuyerPiece, Inputs, Signature } from "../types.js";
|
|
9
|
+
/** One x402 rail pairing's buyer piece, described by what differs between rails. */
|
|
10
|
+
export interface Rail {
|
|
11
|
+
pairing: string;
|
|
12
|
+
/** The account's CAIP-2 namespace, and the form of its address. */
|
|
13
|
+
namespace: string;
|
|
14
|
+
address: RegExp;
|
|
15
|
+
/** The choice field the account's address fills, or null when the build takes none. */
|
|
16
|
+
payer: string | null;
|
|
17
|
+
/** True when the build takes `now`. */
|
|
18
|
+
now: boolean;
|
|
19
|
+
/** The buyer's own values the build takes beside the option, as JSON, or the refusal naming the first missing. */
|
|
20
|
+
inputs(accepted: PaymentRequirements, inputs: Inputs): Record<string, Json> | Refusal;
|
|
21
|
+
/** The choice's JSON fields as the build takes them: integers as bigints where the build names bigints. */
|
|
22
|
+
revive(choice: Record<string, unknown>): Record<string, unknown> | Refusal;
|
|
23
|
+
/** The signer's answer as the build's `complete` takes it. */
|
|
24
|
+
answer(signature: Signature): unknown;
|
|
25
|
+
/** The payment's `payload`, where the build's `complete` returns only the signed transaction as a string. */
|
|
26
|
+
payload?: (completed: string) => Record<string, Json>;
|
|
27
|
+
}
|
|
28
|
+
/** A 64-byte signature given as `0x` hex, as bytes. */
|
|
29
|
+
export declare function signature64(signature: Signature): Uint8Array | Refusal;
|
|
30
|
+
/** The buyer piece for one x402 rail pairing. */
|
|
31
|
+
export declare function railPiece(rail: Rail): BuyerPiece;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { bytesOf, choiceOf, firstOption, isObject, isRefusal, refuse, withPaymentIdentifier } from "./common.js";
|
|
2
|
+
/** The x402 payment for a payload, echoing the challenge's `resource` and `extensions` unchanged, omitted when absent. */
|
|
3
|
+
function x402Payment(required, accepted, payload) {
|
|
4
|
+
return {
|
|
5
|
+
x402Version: 2,
|
|
6
|
+
...(required.resource !== undefined ? { resource: required.resource } : {}),
|
|
7
|
+
...(required.extensions !== undefined ? { extensions: required.extensions } : {}),
|
|
8
|
+
accepted,
|
|
9
|
+
payload,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/** A 64-byte signature given as `0x` hex, as bytes. */
|
|
13
|
+
export function signature64(signature) {
|
|
14
|
+
return bytesOf(signature, 64) ?? refuse("x402/signature-malformed");
|
|
15
|
+
}
|
|
16
|
+
/** The buyer piece for one x402 rail pairing. */
|
|
17
|
+
export function railPiece(rail) {
|
|
18
|
+
return Object.freeze({
|
|
19
|
+
choose(read, account, inputs, now, ref) {
|
|
20
|
+
const o = firstOption(read, account, rail.namespace, rail.pairing, rail.address);
|
|
21
|
+
if (isRefusal(o))
|
|
22
|
+
return refuse("x402/no-payable-option");
|
|
23
|
+
const given = rail.inputs(o.accepted, inputs);
|
|
24
|
+
if (isRefusal(given))
|
|
25
|
+
return given;
|
|
26
|
+
const choice = {
|
|
27
|
+
required: o.required,
|
|
28
|
+
accepted: o.accepted,
|
|
29
|
+
...(rail.payer !== null ? { [rail.payer]: o.address } : {}),
|
|
30
|
+
...(rail.now ? { now } : {}),
|
|
31
|
+
...given,
|
|
32
|
+
};
|
|
33
|
+
return { pairing: rail.pairing, choice, ref };
|
|
34
|
+
},
|
|
35
|
+
choice(chosen) {
|
|
36
|
+
const c = choiceOf(chosen);
|
|
37
|
+
if (c === undefined || !isObject(c["required"]) || !isObject(c["accepted"]))
|
|
38
|
+
return refuse("x402/choice-malformed");
|
|
39
|
+
return rail.revive(c);
|
|
40
|
+
},
|
|
41
|
+
request(unsigned) {
|
|
42
|
+
const u = unsigned;
|
|
43
|
+
return isObject(u) && isObject(u.request) ? u.request : refuse("x402/request-malformed");
|
|
44
|
+
},
|
|
45
|
+
async complete(unsigned, signature, chosen) {
|
|
46
|
+
const answer = rail.answer(signature);
|
|
47
|
+
if (isRefusal(answer))
|
|
48
|
+
return answer;
|
|
49
|
+
const c = choiceOf(chosen);
|
|
50
|
+
const completed = unsigned.complete(answer);
|
|
51
|
+
if (isRefusal(completed))
|
|
52
|
+
return completed;
|
|
53
|
+
let signed;
|
|
54
|
+
if (typeof completed === "string") {
|
|
55
|
+
if (rail.payload === undefined)
|
|
56
|
+
return refuse("x402/payload-malformed");
|
|
57
|
+
signed = x402Payment(c["required"], c["accepted"], rail.payload(completed));
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
signed = completed;
|
|
61
|
+
}
|
|
62
|
+
return withPaymentIdentifier(signed, c["required"], chosen.ref);
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const x402UptoEip155Permit2: import("../types.js").BuyerPiece;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const x402UptoSolana: import("../types.js").BuyerPiece;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { bigintOf, inputsOf, isRefusal, refuse } from "./common.js";
|
|
2
|
+
import { SOLANA_ADDRESS, withUnitPrice } from "./x402-exact-solana.js";
|
|
3
|
+
import { railPiece, signature64 } from "./x402-rail.js";
|
|
4
|
+
const PAIRING = "x402/upto/solana";
|
|
5
|
+
const U64_LIMIT = 1n << 64n;
|
|
6
|
+
/** A u64 from the platform's CSPRNG, in decimal. */
|
|
7
|
+
function randomU64() {
|
|
8
|
+
return crypto.getRandomValues(new BigUint64Array(1))[0].toString();
|
|
9
|
+
}
|
|
10
|
+
function inputs(_accepted, given) {
|
|
11
|
+
const read = inputsOf(given, PAIRING, {
|
|
12
|
+
nonce: "optional-decimal",
|
|
13
|
+
openSlot: "decimal",
|
|
14
|
+
tokenProgram: "string",
|
|
15
|
+
recentBlockhash: "string",
|
|
16
|
+
computeUnitLimit: "optional-uint",
|
|
17
|
+
computeUnitPrice: "optional-decimal",
|
|
18
|
+
});
|
|
19
|
+
if (isRefusal(read))
|
|
20
|
+
return read;
|
|
21
|
+
const nonce = read["nonce"] ?? randomU64();
|
|
22
|
+
if (bigintOf(nonce) >= U64_LIMIT || bigintOf(read["openSlot"]) >= U64_LIMIT)
|
|
23
|
+
return refuse("x402/input-missing");
|
|
24
|
+
return { ...read, nonce };
|
|
25
|
+
}
|
|
26
|
+
function revive(c) {
|
|
27
|
+
const nonce = bigintOf(c["nonce"]);
|
|
28
|
+
const openSlot = bigintOf(c["openSlot"]);
|
|
29
|
+
if (nonce === undefined || openSlot === undefined)
|
|
30
|
+
return refuse("x402/choice-malformed");
|
|
31
|
+
return withUnitPrice({ ...c, nonce, openSlot });
|
|
32
|
+
}
|
|
33
|
+
export const x402UptoSolana = railPiece({
|
|
34
|
+
pairing: PAIRING,
|
|
35
|
+
namespace: "solana",
|
|
36
|
+
address: SOLANA_ADDRESS,
|
|
37
|
+
payer: "payer",
|
|
38
|
+
now: true,
|
|
39
|
+
inputs,
|
|
40
|
+
revive,
|
|
41
|
+
answer: signature64,
|
|
42
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `transact` is `confirm`, the agreement payment when the pairing's payment is not itself a public proof, the signer,
|
|
3
|
+
* then `finish`.
|
|
4
|
+
*/
|
|
5
|
+
import type { AtrHash } from "@integraledger/lcp";
|
|
6
|
+
import type { AgreementReceipt, Binding, Declined, Fetch, Presented, Signer, TransactOptions } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* `confirm`, then, for a pairing whose payment is not itself a public proof, the agreement payment and its receipt,
|
|
9
|
+
* then the signer, then `finish`. On a decline before the signer the signer is never called. Where the build is itself
|
|
10
|
+
* the payment the signer is not called; where the pairing has nothing for the buyer to sign, `signed` is null after the
|
|
11
|
+
* comparison. When the agreement was paid first, `agreement` is its receipt. `landed` is `finish`'s, where it gives one.
|
|
12
|
+
* Options holding anything but `inputs` and `agreementSigner` are declined before any fetch or signer call.
|
|
13
|
+
*/
|
|
14
|
+
export declare function transact(doc: unknown, binding: Binding, signer: Signer, fetch: Fetch, options?: TransactOptions): Promise<{
|
|
15
|
+
signed: Presented | null;
|
|
16
|
+
landed?: unknown;
|
|
17
|
+
bytes: Uint8Array;
|
|
18
|
+
h: AtrHash;
|
|
19
|
+
agreement?: AgreementReceipt;
|
|
20
|
+
} | Declined>;
|