@integraledger/lcp-binding-canton-x402 0.9.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/CHANGELOG.md +12 -0
- package/LICENSE +202 -0
- package/NOTICE +14 -0
- package/README.md +119 -0
- package/dist/adapter.d.ts +113 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +122 -0
- package/dist/adapter.js.map +1 -0
- package/dist/constants.d.ts +37 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +47 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +62 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +81 -0
- package/dist/manifest.js.map +1 -0
- package/dist/memo.d.ts +29 -0
- package/dist/memo.d.ts.map +1 -0
- package/dist/memo.js +73 -0
- package/dist/memo.js.map +1 -0
- package/package.json +62 -0
- package/src/adapter.ts +265 -0
- package/src/constants.ts +65 -0
- package/src/index.ts +24 -0
- package/src/manifest.ts +82 -0
- package/src/memo.ts +80 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canton / Daml constants for the LCP transfer-memo binding.
|
|
3
|
+
*
|
|
4
|
+
* **Canton has a native arbitrary-bytes carrier, and this binding uses it.** x402's `exact` scheme for
|
|
5
|
+
* Canton defines `PaymentRequirements.extra.memo` — "Seller-defined UTF-8 string, max 256 bytes. When
|
|
6
|
+
* present, the client MUST include it in the transfer's metadata" — and its facilitator rule 12 rejects
|
|
7
|
+
* `invalid_exact_canton_memo_mismatch` when the transfer metadata does not carry the identical value under
|
|
8
|
+
* `x402.memo`. Seller-committed, payer-echoed, facilitator-verified, and riding the same transaction as
|
|
9
|
+
* the value.
|
|
10
|
+
*
|
|
11
|
+
* Daml is often said to have no native arbitrary-bytes carrier — no memo, no metadata label, no nonce. That
|
|
12
|
+
* is true of the LEDGER's own primitives and false of a payment settled through x402, which is why this
|
|
13
|
+
* rail exists beside `@integraledger/lcp-binding-canton`'s overlay contract rather than instead of it.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* The transfer-metadata key the facilitator compares against `extra.memo`. The host's, read exactly: a
|
|
17
|
+
* metadata map carrying our value under a different key is a transfer no facilitator checked.
|
|
18
|
+
*/
|
|
19
|
+
export const CANTON_X402_MEMO_KEY = "x402.memo";
|
|
20
|
+
/** The scheme's stated ceiling for `extra.memo`. A canonical atrHash is 66 UTF-8 bytes. */
|
|
21
|
+
export const CANTON_X402_MEMO_MAX_BYTES = 256;
|
|
22
|
+
const SANDBOX = {
|
|
23
|
+
network: "sandbox",
|
|
24
|
+
explorerBase: "http://localhost:7500",
|
|
25
|
+
caip2: "canton:sandbox",
|
|
26
|
+
};
|
|
27
|
+
const DEVNET = {
|
|
28
|
+
network: "devnet",
|
|
29
|
+
explorerBase: "https://scan.global.dev.sync.global",
|
|
30
|
+
caip2: "canton:devnet",
|
|
31
|
+
};
|
|
32
|
+
const MAINNET = {
|
|
33
|
+
network: "mainnet",
|
|
34
|
+
explorerBase: "https://scan.sync.global",
|
|
35
|
+
caip2: "canton:mainnet",
|
|
36
|
+
};
|
|
37
|
+
/** The constants for one environment. Which Canton rail you want is the real choice: this one only reaches
|
|
38
|
+
* payments settled through x402's Canton-Coin scheme, and `@integraledger/lcp-binding-canton`'s overlay
|
|
39
|
+
* covers everything else. */
|
|
40
|
+
export function getCantonX402Config(network) {
|
|
41
|
+
if (network === "sandbox")
|
|
42
|
+
return SANDBOX;
|
|
43
|
+
if (network === "devnet")
|
|
44
|
+
return DEVNET;
|
|
45
|
+
return MAINNET;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,WAAW,CAAC;AAEhD,2FAA2F;AAC3F,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAe9C,MAAM,OAAO,GAA4B;IACvC,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,uBAAuB;IACrC,KAAK,EAAE,gBAAgB;CACxB,CAAC;AAEF,MAAM,MAAM,GAA4B;IACtC,OAAO,EAAE,QAAQ;IACjB,YAAY,EAAE,qCAAqC;IACnD,KAAK,EAAE,eAAe;CACvB,CAAC;AAEF,MAAM,OAAO,GAA4B;IACvC,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,0BAA0B;IACxC,KAAK,EAAE,gBAAgB;CACxB,CAAC;AAEF;;8BAE8B;AAC9B,MAAM,UAAU,mBAAmB,CACjC,OAA0B;IAE1B,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC;IAC1C,IAAI,OAAO,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IACxC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { type CantonX402Adapter, type CantonX402Reader, type CantonX402ReaderConfig, type CantonX402Settlement, type CantonX402SettlementRef, type CantonX402TransferView, createCantonX402Adapter, makeCantonX402Reader, } from "./adapter.js";
|
|
2
|
+
export { CANTON_X402_MEMO_KEY, CANTON_X402_MEMO_MAX_BYTES, type CantonX402Network, type CantonX402NetworkConfig, getCantonX402Config, } from "./constants.js";
|
|
3
|
+
export { CANTON_X402_MANIFEST } from "./manifest.js";
|
|
4
|
+
export { decodeTransferMemo, encodeTransferMemo, readTransferMemoAtrHash, x402MemoRequirement, } from "./memo.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAC1B,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createCantonX402Adapter, makeCantonX402Reader, } from "./adapter.js";
|
|
2
|
+
export { CANTON_X402_MEMO_KEY, CANTON_X402_MEMO_MAX_BYTES, getCantonX402Config, } from "./constants.js";
|
|
3
|
+
export { CANTON_X402_MANIFEST } from "./manifest.js";
|
|
4
|
+
export { decodeTransferMemo, encodeTransferMemo, readTransferMemoAtrHash, x402MemoRequirement, } from "./memo.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAG1B,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { BindingManifest } from "@integraledger/lcp-binding-core";
|
|
2
|
+
/**
|
|
3
|
+
* The Canton transfer-memo binding manifest.
|
|
4
|
+
*
|
|
5
|
+
* **pattern = "native-field"** (canonical LCP §8.3.1). x402's `exact` scheme for Canton defines
|
|
6
|
+
* `PaymentRequirements.extra.memo` — "Seller-defined UTF-8 string, max 256 bytes. When present, the
|
|
7
|
+
* client MUST include it in the transfer's metadata" — and its facilitator safety check 12 rejects
|
|
8
|
+
* `invalid_exact_canton_memo_mismatch` unless the transfer metadata carries the identical value under
|
|
9
|
+
* `x402.memo`. The atrHash therefore rides a field the host defined, on the transaction that moves the
|
|
10
|
+
* money.
|
|
11
|
+
*
|
|
12
|
+
* **THIS IS A SECOND CANTON RAIL, NOT A REPLACEMENT.** `@integraledger/lcp-binding-canton` binds the same
|
|
13
|
+
* chain through an `LcpAnchor` overlay contract, and it is not obsolete: x402's exact-Canton scheme
|
|
14
|
+
* settles **Canton Coin only** ("`asset`: `\"CC\"`. Settles Canton Coin only", instrument fixed to
|
|
15
|
+
* `Amulet`, via `transfer-factory`, relayed by a facilitator). Every other Canton deployment — any
|
|
16
|
+
* instrument, any synchronizer, DvP and fund and bond workflows, no facilitator — still has no native
|
|
17
|
+
* field to ride, and the overlay is the only carrier there.
|
|
18
|
+
*
|
|
19
|
+
* Where BOTH apply, this one wins on every axis: the weld rides the SAME transaction as the payment
|
|
20
|
+
* rather than a separate contract create; it is enforced by the facilitator rather than by nobody; and it
|
|
21
|
+
* binds the asset rather than declaring `assetBinding: "none"`. That is LCP §8.3's own ordering, and it is
|
|
22
|
+
* why the overlay's docblock now says it is an overlay by CHOICE rather than by necessity — the claim that
|
|
23
|
+
* Daml has no native arbitrary-bytes carrier was simply false.
|
|
24
|
+
*
|
|
25
|
+
* One chain, two carriers, two bindings, for the same reason EVM has three (`evm:x402`, `evm:escrow`,
|
|
26
|
+
* `evm:mpp`): a manifest can honestly describe exactly one carrier.
|
|
27
|
+
*
|
|
28
|
+
* **protocol = "x402"**, and the declaration is substantive. `extra.memo` is x402's field, its 256-byte
|
|
29
|
+
* ceiling is x402's ceiling, and the enforcement is an x402 facilitator's. A deployment settling Canton
|
|
30
|
+
* Coin outside x402 does not get this carrier, and saying so is the point of the axis: an absent
|
|
31
|
+
* `protocol` is a positive claim of protocol-neutrality, which this binding cannot make.
|
|
32
|
+
*
|
|
33
|
+
* **assetBinding = "carried"** — the memo rides a `TransferFactory_Transfer` whose own fields name the
|
|
34
|
+
* receiver, the amount and the instrument, and `CantonX402TransferView` carries all three to the caller. That
|
|
35
|
+
* is the axis's actual test: not that the value exists on-chain, but that a consumer can reach it. The
|
|
36
|
+
* overlay could not, which is why it honestly said `"none"`.
|
|
37
|
+
*
|
|
38
|
+
* **recovery.zeroPartyRecoverable = false** — unchanged, and for the unchanged reason. Daml contract and
|
|
39
|
+
* transaction visibility is limited to stakeholders, so a neutral verifier holding only a settlement
|
|
40
|
+
* reference sees nothing until the payer, the merchant or the DSO grants access. §8.3 asks whether an
|
|
41
|
+
* auditor can reconstruct the atrHash from the settlement reference alone WITHOUT trusting either party to
|
|
42
|
+
* produce records; on Canton they cannot, whichever carrier is used. WLD-3 makes the direction of the
|
|
43
|
+
* error normative — understating costs nothing, overstating is non-conformance.
|
|
44
|
+
*
|
|
45
|
+
* **recovery.forwardIndexable = false** — a participant's update stream is one participant's view, not a
|
|
46
|
+
* chain-global forward index, and the memo is a metadata value rather than an indexed key. Honest for the
|
|
47
|
+
* same reason the overlay's participant query was.
|
|
48
|
+
*
|
|
49
|
+
* **successGate = "structural"** — a Canton transfer that did not commit produces no update, so there is
|
|
50
|
+
* no failed view whose memo could be misread as a settlement. The transfer either executed and its
|
|
51
|
+
* metadata exists, or it did not and nothing does.
|
|
52
|
+
*
|
|
53
|
+
* **weldGrades["x402-memo"] = "tx"** — the memo is committed by the payer's signed
|
|
54
|
+
* `TransferFactory_Transfer`, not by a detached signature over the atrHash bytes. The payer signs the
|
|
55
|
+
* prepared transaction (which contains the memo), so the commitment rides the transaction. Per LCP §8.3 /
|
|
56
|
+
* WLD-3 that is tx-grade.
|
|
57
|
+
*
|
|
58
|
+
* **finality.reversible = false** — once the transfer executes, its input holdings are consumed and Canton
|
|
59
|
+
* has no reversal; recourse is the record's elected forum (PAY-3/RCS-5), never dispute resolution.
|
|
60
|
+
*/
|
|
61
|
+
export declare const CANTON_X402_MANIFEST: BindingManifest;
|
|
62
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAGvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,eAAO,MAAM,oBAAoB,EAAE,eAmBlC,CAAC"}
|
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { CANTON_X402_MEMO_KEY } from "./constants.js";
|
|
2
|
+
/**
|
|
3
|
+
* The Canton transfer-memo binding manifest.
|
|
4
|
+
*
|
|
5
|
+
* **pattern = "native-field"** (canonical LCP §8.3.1). x402's `exact` scheme for Canton defines
|
|
6
|
+
* `PaymentRequirements.extra.memo` — "Seller-defined UTF-8 string, max 256 bytes. When present, the
|
|
7
|
+
* client MUST include it in the transfer's metadata" — and its facilitator safety check 12 rejects
|
|
8
|
+
* `invalid_exact_canton_memo_mismatch` unless the transfer metadata carries the identical value under
|
|
9
|
+
* `x402.memo`. The atrHash therefore rides a field the host defined, on the transaction that moves the
|
|
10
|
+
* money.
|
|
11
|
+
*
|
|
12
|
+
* **THIS IS A SECOND CANTON RAIL, NOT A REPLACEMENT.** `@integraledger/lcp-binding-canton` binds the same
|
|
13
|
+
* chain through an `LcpAnchor` overlay contract, and it is not obsolete: x402's exact-Canton scheme
|
|
14
|
+
* settles **Canton Coin only** ("`asset`: `\"CC\"`. Settles Canton Coin only", instrument fixed to
|
|
15
|
+
* `Amulet`, via `transfer-factory`, relayed by a facilitator). Every other Canton deployment — any
|
|
16
|
+
* instrument, any synchronizer, DvP and fund and bond workflows, no facilitator — still has no native
|
|
17
|
+
* field to ride, and the overlay is the only carrier there.
|
|
18
|
+
*
|
|
19
|
+
* Where BOTH apply, this one wins on every axis: the weld rides the SAME transaction as the payment
|
|
20
|
+
* rather than a separate contract create; it is enforced by the facilitator rather than by nobody; and it
|
|
21
|
+
* binds the asset rather than declaring `assetBinding: "none"`. That is LCP §8.3's own ordering, and it is
|
|
22
|
+
* why the overlay's docblock now says it is an overlay by CHOICE rather than by necessity — the claim that
|
|
23
|
+
* Daml has no native arbitrary-bytes carrier was simply false.
|
|
24
|
+
*
|
|
25
|
+
* One chain, two carriers, two bindings, for the same reason EVM has three (`evm:x402`, `evm:escrow`,
|
|
26
|
+
* `evm:mpp`): a manifest can honestly describe exactly one carrier.
|
|
27
|
+
*
|
|
28
|
+
* **protocol = "x402"**, and the declaration is substantive. `extra.memo` is x402's field, its 256-byte
|
|
29
|
+
* ceiling is x402's ceiling, and the enforcement is an x402 facilitator's. A deployment settling Canton
|
|
30
|
+
* Coin outside x402 does not get this carrier, and saying so is the point of the axis: an absent
|
|
31
|
+
* `protocol` is a positive claim of protocol-neutrality, which this binding cannot make.
|
|
32
|
+
*
|
|
33
|
+
* **assetBinding = "carried"** — the memo rides a `TransferFactory_Transfer` whose own fields name the
|
|
34
|
+
* receiver, the amount and the instrument, and `CantonX402TransferView` carries all three to the caller. That
|
|
35
|
+
* is the axis's actual test: not that the value exists on-chain, but that a consumer can reach it. The
|
|
36
|
+
* overlay could not, which is why it honestly said `"none"`.
|
|
37
|
+
*
|
|
38
|
+
* **recovery.zeroPartyRecoverable = false** — unchanged, and for the unchanged reason. Daml contract and
|
|
39
|
+
* transaction visibility is limited to stakeholders, so a neutral verifier holding only a settlement
|
|
40
|
+
* reference sees nothing until the payer, the merchant or the DSO grants access. §8.3 asks whether an
|
|
41
|
+
* auditor can reconstruct the atrHash from the settlement reference alone WITHOUT trusting either party to
|
|
42
|
+
* produce records; on Canton they cannot, whichever carrier is used. WLD-3 makes the direction of the
|
|
43
|
+
* error normative — understating costs nothing, overstating is non-conformance.
|
|
44
|
+
*
|
|
45
|
+
* **recovery.forwardIndexable = false** — a participant's update stream is one participant's view, not a
|
|
46
|
+
* chain-global forward index, and the memo is a metadata value rather than an indexed key. Honest for the
|
|
47
|
+
* same reason the overlay's participant query was.
|
|
48
|
+
*
|
|
49
|
+
* **successGate = "structural"** — a Canton transfer that did not commit produces no update, so there is
|
|
50
|
+
* no failed view whose memo could be misread as a settlement. The transfer either executed and its
|
|
51
|
+
* metadata exists, or it did not and nothing does.
|
|
52
|
+
*
|
|
53
|
+
* **weldGrades["x402-memo"] = "tx"** — the memo is committed by the payer's signed
|
|
54
|
+
* `TransferFactory_Transfer`, not by a detached signature over the atrHash bytes. The payer signs the
|
|
55
|
+
* prepared transaction (which contains the memo), so the commitment rides the transaction. Per LCP §8.3 /
|
|
56
|
+
* WLD-3 that is tx-grade.
|
|
57
|
+
*
|
|
58
|
+
* **finality.reversible = false** — once the transfer executes, its input holdings are consumed and Canton
|
|
59
|
+
* has no reversal; recourse is the record's elected forum (PAY-3/RCS-5), never dispute resolution.
|
|
60
|
+
*/
|
|
61
|
+
export const CANTON_X402_MANIFEST = {
|
|
62
|
+
rail: "canton:x402",
|
|
63
|
+
pattern: "native-field",
|
|
64
|
+
protocol: "x402",
|
|
65
|
+
nativeField: CANTON_X402_MEMO_KEY,
|
|
66
|
+
recovery: {
|
|
67
|
+
onChain: true,
|
|
68
|
+
zeroPartyRecoverable: false,
|
|
69
|
+
forwardIndexable: false,
|
|
70
|
+
},
|
|
71
|
+
assetBinding: "carried",
|
|
72
|
+
successGate: "structural",
|
|
73
|
+
indexing: `participant-updates:transfer.meta.${CANTON_X402_MEMO_KEY}`,
|
|
74
|
+
finality: {
|
|
75
|
+
reversible: false,
|
|
76
|
+
note: "a Canton transfer consumes the input holdings it names and Canton has no reversal, so an executed transfer's memo is permanent; recourse is the record's elected forum (PAY-3/RCS-5), never dispute resolution",
|
|
77
|
+
},
|
|
78
|
+
weldGrades: { "x402-memo": "tx" },
|
|
79
|
+
lifecycleStates: ["proposed", "settled"],
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAoB;IACnD,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,cAAc;IACvB,QAAQ,EAAE,MAAM;IAChB,WAAW,EAAE,oBAAoB;IACjC,QAAQ,EAAE;QACR,OAAO,EAAE,IAAI;QACb,oBAAoB,EAAE,KAAK;QAC3B,gBAAgB,EAAE,KAAK;KACxB;IACD,YAAY,EAAE,SAAS;IACvB,WAAW,EAAE,YAAY;IACzB,QAAQ,EAAE,qCAAqC,oBAAoB,EAAE;IACrE,QAAQ,EAAE;QACR,UAAU,EAAE,KAAK;QACjB,IAAI,EAAE,gNAAgN;KACvN;IACD,UAAU,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE;IACjC,eAAe,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC;CACzC,CAAC"}
|
package/dist/memo.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `extra` fragment a Canton seller merges into its x402 `PaymentRequirements`.
|
|
3
|
+
*
|
|
4
|
+
* Returned as an object rather than a bare string so the call site reads as what it is — the seller
|
|
5
|
+
* ADVERTISING a value it is committing to — and so a future scheme field can join it without changing
|
|
6
|
+
* every caller. Mirrors `binding-tempo-mpp`'s `mppMethodDetailsMemo`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function x402MemoRequirement(atrHash: string): {
|
|
9
|
+
readonly memo: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The memo string carrying `atrHash`: the canonical `0x`-prefixed lowercase form, verbatim.
|
|
13
|
+
*
|
|
14
|
+
* No bare-hex variant is emitted or accepted. The host calls this a "seller-defined UTF-8 string" and
|
|
15
|
+
* compares it byte-for-byte against the transfer metadata, so any second spelling would be a second wire
|
|
16
|
+
* value that a facilitator would reject against the first.
|
|
17
|
+
*/
|
|
18
|
+
export declare function encodeTransferMemo(atrHash: string): string;
|
|
19
|
+
/** Decode a memo string back to an atrHash, or `null` if it is not a well-formed one. */
|
|
20
|
+
export declare function decodeTransferMemo(memo: string): `0x${string}` | null;
|
|
21
|
+
/**
|
|
22
|
+
* Read the atrHash out of a transfer's on-ledger metadata map, or `null` if it carries none.
|
|
23
|
+
*
|
|
24
|
+
* The key is the host's — `x402.memo`, quoted in rule 12 above — and it is read EXACTLY. A metadata map
|
|
25
|
+
* carrying our value under some other key is a transfer that no facilitator checked, so treating it as a
|
|
26
|
+
* weld would assert a commitment nobody made.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readTransferMemoAtrHash(meta: Readonly<Record<string, string>> | undefined): `0x${string}` | null;
|
|
29
|
+
//# sourceMappingURL=memo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memo.d.ts","sourceRoot":"","sources":["../src/memo.ts"],"names":[],"mappings":"AAqCA;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG;IACpD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAEA;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,yFAAyF;AACzF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE,GAAG,IAAI,CAErE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,GACjD,KAAK,MAAM,EAAE,GAAG,IAAI,CAItB"}
|
package/dist/memo.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Canton transfer-memo atrHash codec — PURE, no Daml SDK, no HTTP.
|
|
3
|
+
*
|
|
4
|
+
* **THE CARRIER.** x402's `exact` scheme for Canton defines `PaymentRequirements.extra.memo`:
|
|
5
|
+
*
|
|
6
|
+
* > `extra.memo` (optional): Seller-defined UTF-8 string, max 256 bytes. When present, the client MUST
|
|
7
|
+
* > include it in the transfer's metadata.
|
|
8
|
+
*
|
|
9
|
+
* and makes it facilitator-enforced (scheme §Safety Checks, rule 12):
|
|
10
|
+
*
|
|
11
|
+
* > **Memo.** If `paymentRequirements.extra.memo` is set, the transfer metadata MUST carry the identical
|
|
12
|
+
* > value under `x402.memo`. Reject with `invalid_exact_canton_memo_mismatch`.
|
|
13
|
+
*
|
|
14
|
+
* So the SELLER names the value, the PAYER must echo it into the transfer that moves the money, and a
|
|
15
|
+
* THIRD PARTY refuses to relay the payment if they disagree. That is a §8.3.1 Native Field with an
|
|
16
|
+
* unusually strong commitment story, and it rides the same transaction as the value — which is what the
|
|
17
|
+
* overlay it replaces could never do.
|
|
18
|
+
*
|
|
19
|
+
* **WHY THIS CARRIER AND NOT AN OVERLAY CONTRACT.** Canton's other binding,
|
|
20
|
+
* `@integraledger/lcp-binding-canton`, welds through a custom `LcpAnchor` Daml template. Where this scheme
|
|
21
|
+
* applies, the memo is stronger on every axis: it rides the SAME transaction as the payment rather than a
|
|
22
|
+
* separate contract create, the facilitator checks it before relaying, and the transfer's own fields name
|
|
23
|
+
* the asset. LCP §8.3's ordering puts Overlay Contract below Native Field for exactly these reasons. The
|
|
24
|
+
* overlay covers what this scheme cannot reach — it settles Canton Coin only.
|
|
25
|
+
*
|
|
26
|
+
* **THE 256-BYTE CEILING NEEDS NO RUNTIME CHECK.** A canonical atrHash is exactly 66 UTF-8 bytes and the
|
|
27
|
+
* host allows 256, so a length guard here could never fire — it would be an unreachable branch asserting
|
|
28
|
+
* a fact the type of the input already settles. `CANTON_X402_MEMO_MAX_BYTES` records the host's limit and
|
|
29
|
+
* `constants.test.ts` proves an atrHash fits inside it; that is where a fact about the host belongs.
|
|
30
|
+
*
|
|
31
|
+
* `encodeTransferMemo` fails LOUD on a malformed atrHash (never advertise a memo we could not later
|
|
32
|
+
* verify); `decodeTransferMemo` returns `null` for anything that is not one, so a scan over a party's
|
|
33
|
+
* transfers can skip foreign memos without treating them as errors.
|
|
34
|
+
*/
|
|
35
|
+
import { canonicalAtrHash, isAtrHash } from "@integraledger/lcp-kernel";
|
|
36
|
+
import { CANTON_X402_MEMO_KEY } from "./constants.js";
|
|
37
|
+
/**
|
|
38
|
+
* The `extra` fragment a Canton seller merges into its x402 `PaymentRequirements`.
|
|
39
|
+
*
|
|
40
|
+
* Returned as an object rather than a bare string so the call site reads as what it is — the seller
|
|
41
|
+
* ADVERTISING a value it is committing to — and so a future scheme field can join it without changing
|
|
42
|
+
* every caller. Mirrors `binding-tempo-mpp`'s `mppMethodDetailsMemo`.
|
|
43
|
+
*/
|
|
44
|
+
export function x402MemoRequirement(atrHash) {
|
|
45
|
+
return { memo: encodeTransferMemo(atrHash) };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The memo string carrying `atrHash`: the canonical `0x`-prefixed lowercase form, verbatim.
|
|
49
|
+
*
|
|
50
|
+
* No bare-hex variant is emitted or accepted. The host calls this a "seller-defined UTF-8 string" and
|
|
51
|
+
* compares it byte-for-byte against the transfer metadata, so any second spelling would be a second wire
|
|
52
|
+
* value that a facilitator would reject against the first.
|
|
53
|
+
*/
|
|
54
|
+
export function encodeTransferMemo(atrHash) {
|
|
55
|
+
return canonicalAtrHash(atrHash, "encodeTransferMemo");
|
|
56
|
+
}
|
|
57
|
+
/** Decode a memo string back to an atrHash, or `null` if it is not a well-formed one. */
|
|
58
|
+
export function decodeTransferMemo(memo) {
|
|
59
|
+
return isAtrHash(memo) ? canonicalAtrHash(memo, "decodeTransferMemo") : null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Read the atrHash out of a transfer's on-ledger metadata map, or `null` if it carries none.
|
|
63
|
+
*
|
|
64
|
+
* The key is the host's — `x402.memo`, quoted in rule 12 above — and it is read EXACTLY. A metadata map
|
|
65
|
+
* carrying our value under some other key is a transfer that no facilitator checked, so treating it as a
|
|
66
|
+
* weld would assert a commitment nobody made.
|
|
67
|
+
*/
|
|
68
|
+
export function readTransferMemoAtrHash(meta) {
|
|
69
|
+
// `?? ""` rather than an `undefined` branch: an absent key and a foreign memo are the same answer, and
|
|
70
|
+
// "" is not a well-formed atrHash, so the decoder already gives it.
|
|
71
|
+
return decodeTransferMemo(meta?.[CANTON_X402_MEMO_KEY] ?? "");
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=memo.js.map
|
package/dist/memo.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memo.js","sourceRoot":"","sources":["../src/memo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IAGjD,OAAO,EAAE,IAAI,EAAE,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;AAC/C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,OAAO,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;AACzD,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,IAAkD;IAElD,uGAAuG;IACvG,oEAAoE;IACpE,OAAO,kBAAkB,CAAC,IAAI,EAAE,CAAC,oBAAoB,CAAC,IAAI,EAAE,CAAC,CAAC;AAChE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@integraledger/lcp-binding-canton-x402",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Welds an ATR hash into a Canton Coin settlement over x402's exact scheme.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"lcp",
|
|
7
|
+
"legal-context-protocol",
|
|
8
|
+
"legal-terms",
|
|
9
|
+
"agentic-commerce",
|
|
10
|
+
"settlement",
|
|
11
|
+
"atr-hash",
|
|
12
|
+
"canton",
|
|
13
|
+
"daml",
|
|
14
|
+
"x402"
|
|
15
|
+
],
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"src",
|
|
28
|
+
"CHANGELOG.md",
|
|
29
|
+
"LICENSE",
|
|
30
|
+
"NOTICE"
|
|
31
|
+
],
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"registry": "https://registry.npmjs.org",
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/IntegraLedger/integra-protocol.git",
|
|
39
|
+
"directory": "packages/binding-canton-x402"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/IntegraLedger/integra-protocol/issues"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/IntegraLedger/integra-protocol/tree/main/packages/binding-canton-x402#readme",
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@integraledger/lcp-kernel": "0.9.0",
|
|
47
|
+
"@integraledger/lcp-binding-core": "0.9.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "24.13.3",
|
|
51
|
+
"vitest": "4.1.10"
|
|
52
|
+
},
|
|
53
|
+
"license": "Apache-2.0",
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=24"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsc -p tsconfig.build.json",
|
|
59
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
60
|
+
"test": "vitest run"
|
|
61
|
+
}
|
|
62
|
+
}
|