@metalntwx/metal-pay 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 +104 -38
- package/dist/clearing-abi.d.ts +1836 -0
- package/dist/clearing-abi.js +2361 -0
- package/dist/clearing-client.d.ts +96 -159
- package/dist/clearing-client.js +412 -553
- package/dist/clearing-codec.d.ts +57 -0
- package/dist/clearing-codec.js +173 -0
- package/dist/clearing-custody.d.ts +202 -0
- package/dist/clearing-custody.js +552 -0
- package/dist/clearing-server.d.ts +30 -49
- package/dist/clearing-server.js +87 -67
- package/dist/clearing-x402.d.ts +38 -0
- package/dist/clearing-x402.js +249 -0
- package/dist/client.d.ts +14 -15
- package/dist/client.js +53 -22
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/mandates/account.d.ts +9 -4
- package/dist/mandates/account.js +15 -11
- package/dist/mandates/binding.d.ts +4 -27
- package/dist/mandates/binding.js +5 -9
- package/dist/mandates/checkout.js +5 -5
- package/dist/mandates/client.js +4 -3
- package/dist/mandates/l3a.d.ts +2 -2
- package/dist/mandates/l3a.js +5 -4
- package/dist/mandates/seller.d.ts +1 -1
- package/dist/mandates/seller.js +4 -4
- package/dist/mandates/verify.d.ts +4 -6
- package/dist/mandates/verify.js +147 -82
- package/dist/mandates/vi/credential.js +4 -4
- package/dist/networks.d.ts +9 -1
- package/dist/networks.js +105 -4
- package/dist/node.d.ts +11 -0
- package/dist/node.js +97 -0
- package/package.json +18 -11
- package/src/clearing-abi.ts +2361 -0
- package/src/clearing-client.test.ts +850 -0
- package/src/clearing-client.ts +612 -0
- package/src/clearing-codec.test.ts +57 -0
- package/src/clearing-codec.ts +251 -0
- package/src/clearing-custody.test.ts +763 -0
- package/src/clearing-custody.ts +743 -0
- package/src/clearing-fixture.json +37 -0
- package/src/clearing-server.test.ts +450 -0
- package/src/clearing-server.ts +123 -0
- package/src/clearing-x402.test.ts +181 -0
- package/src/clearing-x402.ts +328 -0
- package/src/client.test.ts +333 -0
- package/src/client.ts +195 -0
- package/src/index.ts +33 -0
- package/src/mandates/account.ts +95 -0
- package/src/mandates/binding.ts +280 -0
- package/src/mandates/chain.ts +68 -0
- package/src/mandates/checkout.ts +368 -0
- package/src/mandates/client.ts +159 -0
- package/src/mandates/extension.ts +48 -0
- package/src/mandates/index.ts +121 -0
- package/src/mandates/ingest.ts +42 -0
- package/src/mandates/jcs.ts +16 -0
- package/src/mandates/l3a.ts +216 -0
- package/src/mandates/seller.ts +91 -0
- package/src/mandates/verify.ts +625 -0
- package/src/mandates/vi/credential.ts +477 -0
- package/src/mandates/vi/issue.ts +118 -0
- package/src/mandates/vi/sd-jwt.ts +189 -0
- package/src/networks.test.ts +177 -0
- package/src/networks.ts +242 -0
- package/src/node.test.ts +24 -0
- package/src/node.ts +96 -0
- package/src/server.test.ts +223 -0
- package/src/server.ts +77 -0
- package/dist/clearing.d.ts +0 -204
- package/dist/clearing.js +0 -151
- package/dist/file-storage.d.ts +0 -39
- package/dist/file-storage.js +0 -195
package/dist/node.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { DatabaseSync } from "node:sqlite";
|
|
2
|
+
import { mkdir, open, readFile, rename } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { randomBytes } from "node:crypto";
|
|
5
|
+
import { createClearingSigner } from "./clearing-codec.js";
|
|
6
|
+
/** A persistent P-256 account and receipt journal for a single server process. */
|
|
7
|
+
export async function openClearingWallet(directory) {
|
|
8
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
9
|
+
// SQLite holds an OS lock for the wallet lifetime and releases it on crash.
|
|
10
|
+
const owner = new DatabaseSync(join(directory, "owner.sqlite"));
|
|
11
|
+
try {
|
|
12
|
+
owner.exec("PRAGMA locking_mode=EXCLUSIVE; BEGIN EXCLUSIVE; CREATE TABLE IF NOT EXISTS owner (id INTEGER)");
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
owner.close();
|
|
16
|
+
throw new Error("clearing wallet is already in use", { cause: error });
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const keyPath = join(directory, "account.key");
|
|
20
|
+
let key;
|
|
21
|
+
try {
|
|
22
|
+
key = (await readFile(keyPath, "utf8")).trim();
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (error.code !== "ENOENT")
|
|
26
|
+
throw error;
|
|
27
|
+
for (;;) {
|
|
28
|
+
key = `0x${randomBytes(32).toString("hex")}`;
|
|
29
|
+
try {
|
|
30
|
+
createClearingSigner(key);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
/* Rejection sample the scalar. */
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const file = await open(keyPath, "wx", 0o600);
|
|
38
|
+
try {
|
|
39
|
+
await file.writeFile(key);
|
|
40
|
+
await file.sync();
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
await file.close();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const parent = await open(directory, "r");
|
|
47
|
+
try {
|
|
48
|
+
await parent.sync();
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
await parent.close();
|
|
52
|
+
}
|
|
53
|
+
const signer = createClearingSigner(key);
|
|
54
|
+
const statePath = join(directory, "payments.json");
|
|
55
|
+
const store = {
|
|
56
|
+
async load() {
|
|
57
|
+
try {
|
|
58
|
+
return JSON.parse(await readFile(statePath, "utf8"));
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error.code === "ENOENT")
|
|
62
|
+
return null;
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
async save(state) {
|
|
67
|
+
const file = await open(statePath + ".next", "w", 0o600);
|
|
68
|
+
try {
|
|
69
|
+
await file.writeFile(JSON.stringify(state));
|
|
70
|
+
await file.sync();
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
await file.close();
|
|
74
|
+
}
|
|
75
|
+
await rename(statePath + ".next", statePath);
|
|
76
|
+
const parent = await open(directory, "r");
|
|
77
|
+
try {
|
|
78
|
+
await parent.sync();
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
await parent.close();
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
signer,
|
|
87
|
+
store,
|
|
88
|
+
async close() {
|
|
89
|
+
owner.close();
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
owner.close();
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metalntwx/metal-pay",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Agent payments on Metal for the official x402 packages:
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Agent payments on Metal for the official x402 packages: native Bajillion clearing, on-chain exact payments, durable payer wallets, seller integration, and mandates, which let an agent pay from its owner's account within limits Metal enforces.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
"directory": "sdks/metal-pay"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": "^22.13.0 || >=23.4.0"
|
|
14
|
+
},
|
|
12
15
|
"main": "./dist/index.js",
|
|
13
16
|
"types": "./dist/index.d.ts",
|
|
14
17
|
"exports": {
|
|
@@ -16,9 +19,9 @@
|
|
|
16
19
|
"types": "./dist/index.d.ts",
|
|
17
20
|
"default": "./dist/index.js"
|
|
18
21
|
},
|
|
19
|
-
"./
|
|
20
|
-
"types": "./dist/
|
|
21
|
-
"default": "./dist/
|
|
22
|
+
"./node": {
|
|
23
|
+
"types": "./dist/node.d.ts",
|
|
24
|
+
"default": "./dist/node.js"
|
|
22
25
|
},
|
|
23
26
|
"./mandates": {
|
|
24
27
|
"types": "./dist/mandates/index.d.ts",
|
|
@@ -26,21 +29,25 @@
|
|
|
26
29
|
}
|
|
27
30
|
},
|
|
28
31
|
"files": [
|
|
29
|
-
"dist"
|
|
32
|
+
"dist",
|
|
33
|
+
"src"
|
|
30
34
|
],
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"@noble/curves": "
|
|
33
|
-
"@x402/core": "^2.21.0",
|
|
34
|
-
"@x402/evm": "^2.21.0",
|
|
35
|
-
"@x402/fetch": "^2.21.0"
|
|
36
|
+
"@noble/curves": "1.9.7"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
39
|
+
"@x402/core": ">=2.28.0 <3",
|
|
40
|
+
"@x402/evm": ">=2.28.0 <3",
|
|
41
|
+
"@x402/fetch": ">=2.28.0 <3",
|
|
38
42
|
"viem": "^2"
|
|
39
43
|
},
|
|
40
44
|
"devDependencies": {
|
|
41
45
|
"@metalntwx/metal-ts": "0.3.2",
|
|
42
46
|
"@types/node": "^24.13.2",
|
|
43
|
-
"@x402/
|
|
47
|
+
"@x402/core": "2.28.0",
|
|
48
|
+
"@x402/evm": "2.28.0",
|
|
49
|
+
"@x402/fetch": "2.28.0",
|
|
50
|
+
"@x402/hono": "2.28.0",
|
|
44
51
|
"hono": "4.13.7",
|
|
45
52
|
"tsx": "^4.23.0",
|
|
46
53
|
"typescript": "~6.0.2",
|