@4mica/sdk 1.2.10 → 1.2.11
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/dist/package.json +80 -0
- package/dist/{index.d.ts → src/index.d.ts} +1 -0
- package/dist/{index.js → src/index.js} +1 -0
- package/dist/{rpc.js → src/rpc.js} +3 -1
- package/dist/src/wallet/cdp.d.ts +11 -0
- package/dist/src/wallet/cdp.js +85 -0
- package/dist/src/wallet/index.d.ts +2 -0
- package/dist/src/wallet/index.js +5 -0
- package/dist/{x402 → src/x402}/index.js +3 -2
- package/package.json +1 -1
- /package/dist/{abi → src/abi}/core4mica.d.ts +0 -0
- /package/dist/{abi → src/abi}/core4mica.js +0 -0
- /package/dist/{abi → src/abi}/erc20.d.ts +0 -0
- /package/dist/{abi → src/abi}/erc20.js +0 -0
- /package/dist/{auth.d.ts → src/auth.d.ts} +0 -0
- /package/dist/{auth.js → src/auth.js} +0 -0
- /package/dist/{bls.d.ts → src/bls.d.ts} +0 -0
- /package/dist/{bls.js → src/bls.js} +0 -0
- /package/dist/{chain.d.ts → src/chain.d.ts} +0 -0
- /package/dist/{chain.js → src/chain.js} +0 -0
- /package/dist/{client → src/client}/index.d.ts +0 -0
- /package/dist/{client → src/client}/index.js +0 -0
- /package/dist/{client → src/client}/recipient.d.ts +0 -0
- /package/dist/{client → src/client}/recipient.js +0 -0
- /package/dist/{client → src/client}/shared.d.ts +0 -0
- /package/dist/{client → src/client}/shared.js +0 -0
- /package/dist/{client → src/client}/user.d.ts +0 -0
- /package/dist/{client → src/client}/user.js +0 -0
- /package/dist/{config.d.ts → src/config.d.ts} +0 -0
- /package/dist/{config.js → src/config.js} +0 -0
- /package/dist/{constants.d.ts → src/constants.d.ts} +0 -0
- /package/dist/{constants.js → src/constants.js} +0 -0
- /package/dist/{contract.d.ts → src/contract.d.ts} +0 -0
- /package/dist/{contract.js → src/contract.js} +0 -0
- /package/dist/{debug.d.ts → src/debug.d.ts} +0 -0
- /package/dist/{debug.js → src/debug.js} +0 -0
- /package/dist/{errors.d.ts → src/errors.d.ts} +0 -0
- /package/dist/{errors.js → src/errors.js} +0 -0
- /package/dist/{guarantee.d.ts → src/guarantee.d.ts} +0 -0
- /package/dist/{guarantee.js → src/guarantee.js} +0 -0
- /package/dist/{http.d.ts → src/http.d.ts} +0 -0
- /package/dist/{http.js → src/http.js} +0 -0
- /package/dist/{models.d.ts → src/models.d.ts} +0 -0
- /package/dist/{models.js → src/models.js} +0 -0
- /package/dist/{networks.d.ts → src/networks.d.ts} +0 -0
- /package/dist/{networks.js → src/networks.js} +0 -0
- /package/dist/{payment.d.ts → src/payment.d.ts} +0 -0
- /package/dist/{payment.js → src/payment.js} +0 -0
- /package/dist/{rpc.d.ts → src/rpc.d.ts} +0 -0
- /package/dist/{serde.d.ts → src/serde.d.ts} +0 -0
- /package/dist/{serde.js → src/serde.js} +0 -0
- /package/dist/{signing.d.ts → src/signing.d.ts} +0 -0
- /package/dist/{signing.js → src/signing.js} +0 -0
- /package/dist/{utils.d.ts → src/utils.d.ts} +0 -0
- /package/dist/{utils.js → src/utils.js} +0 -0
- /package/dist/{validation.d.ts → src/validation.d.ts} +0 -0
- /package/dist/{validation.js → src/validation.js} +0 -0
- /package/dist/{x402 → src/x402}/index.d.ts +0 -0
- /package/dist/{x402 → src/x402}/models.d.ts +0 -0
- /package/dist/{x402 → src/x402}/models.js +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@4mica/sdk",
|
|
3
|
+
"version": "1.2.11",
|
|
4
|
+
"description": "TypeScript SDK for interacting with the 4Mica payment network",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/4mica-Network/ts-sdk-4mica.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/4mica-Network/ts-sdk-4mica#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/4mica-Network/ts-sdk-4mica/issues"
|
|
13
|
+
},
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"types": "dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"4mica",
|
|
34
|
+
"payments",
|
|
35
|
+
"payment-network",
|
|
36
|
+
"blockchain",
|
|
37
|
+
"sdk",
|
|
38
|
+
"typescript",
|
|
39
|
+
"ethers"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{ recursive: true, force: true })\"",
|
|
43
|
+
"build": "npm run clean && tsc -p tsconfig.build.json",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|
|
46
|
+
"example:base-sepolia:x402-v2": "node_modules/.bin/tsx examples/base-sepolia-x402-facilitator-e2e.ts",
|
|
47
|
+
"example:manual:agents": "node_modules/.bin/tsx examples/manual-agents/demo.ts",
|
|
48
|
+
"example:wachai:v2": "node_modules/.bin/tsx examples/wachai-v2-demo/demo.ts",
|
|
49
|
+
"example:deposit": "node_modules/.bin/tsx examples/deposit.ts",
|
|
50
|
+
"example:yield": "node_modules/.bin/tsx examples/yield.ts",
|
|
51
|
+
"lint": "eslint . --ext .ts",
|
|
52
|
+
"fmt": "prettier --check \"{src,tests}/**/*.{ts,js,json}\""
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@noble/curves": "^2.2.0",
|
|
56
|
+
"@quillai-network/wachai-validation-sdk": "^0.1.0",
|
|
57
|
+
"viem": "^2.45.1"
|
|
58
|
+
},
|
|
59
|
+
"optionalDependencies": {
|
|
60
|
+
"@coinbase/cdp-sdk": "^1.49.2"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@4mica/x402": "^1.2.5",
|
|
64
|
+
"@coinbase/cdp-sdk": "^1.49.2",
|
|
65
|
+
"@eslint/js": "^9.39.2",
|
|
66
|
+
"@types/node": "^25.2.0",
|
|
67
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
68
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
69
|
+
"dotenv-cli": "^11.0.0",
|
|
70
|
+
"eslint": "^9.39.2",
|
|
71
|
+
"eslint-config-prettier": "^10.1.8",
|
|
72
|
+
"eslint-plugin-react": "^7.37.5",
|
|
73
|
+
"globals": "^17.3.0",
|
|
74
|
+
"prettier": "^3.8.1",
|
|
75
|
+
"tsx": "^4.21.0",
|
|
76
|
+
"typescript": "^5.3.3",
|
|
77
|
+
"typescript-eslint": "^8.54.0",
|
|
78
|
+
"vitest": "^4.0.17"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -5,6 +5,8 @@ const constants_1 = require("./constants");
|
|
|
5
5
|
const models_1 = require("./models");
|
|
6
6
|
const errors_1 = require("./errors");
|
|
7
7
|
const http_1 = require("./http");
|
|
8
|
+
const package_json_1 = require("../package.json");
|
|
9
|
+
const SDK_CLIENT_HEADER_VALUE = `ts-sdk-4mica/${package_json_1.version}`;
|
|
8
10
|
function serializeTabId(tabId) {
|
|
9
11
|
return `0x${BigInt(tabId).toString(16)}`;
|
|
10
12
|
}
|
|
@@ -31,7 +33,7 @@ class RpcProxy {
|
|
|
31
33
|
return this;
|
|
32
34
|
}
|
|
33
35
|
async headers() {
|
|
34
|
-
const headers = {};
|
|
36
|
+
const headers = { 'x-4mica-sdk': SDK_CLIENT_HEADER_VALUE };
|
|
35
37
|
if (this.adminApiKey) {
|
|
36
38
|
headers[constants_1.ADMIN_API_KEY_HEADER] = this.adminApiKey;
|
|
37
39
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Account } from 'viem';
|
|
2
|
+
export interface CdpAccountConfig {
|
|
3
|
+
/** CDP API key ID from the Coinbase Developer Platform dashboard. */
|
|
4
|
+
apiKeyId: string;
|
|
5
|
+
/** CDP API key secret from the Coinbase Developer Platform dashboard. */
|
|
6
|
+
apiKeySecret: string;
|
|
7
|
+
/** Idempotency name — getOrCreateAccount always returns the same wallet for a given name. */
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
/** Creates a viem Account backed by a Coinbase CDP MPC wallet (private key never leaves CDP). */
|
|
11
|
+
export declare function createCdpAccount(config: CdpAccountConfig): Promise<Account>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createCdpAccount = createCdpAccount;
|
|
37
|
+
const viem_1 = require("viem");
|
|
38
|
+
const accounts_1 = require("viem/accounts");
|
|
39
|
+
/** Creates a viem Account backed by a Coinbase CDP MPC wallet (private key never leaves CDP). */
|
|
40
|
+
async function createCdpAccount(config) {
|
|
41
|
+
const { CdpClient } = await Promise.resolve().then(() => __importStar(require('@coinbase/cdp-sdk')));
|
|
42
|
+
const cdp = new CdpClient({
|
|
43
|
+
apiKeyId: config.apiKeyId,
|
|
44
|
+
apiKeySecret: config.apiKeySecret,
|
|
45
|
+
});
|
|
46
|
+
const evmAccount = await cdp.evm.getOrCreateAccount({ name: config.name });
|
|
47
|
+
const address = evmAccount.address;
|
|
48
|
+
async function signMessage({ message }) {
|
|
49
|
+
if (typeof message === 'string') {
|
|
50
|
+
// CDP's signMessage applies the EIP-191 prefix internally.
|
|
51
|
+
const result = await cdp.evm.signMessage({ address, message });
|
|
52
|
+
return result.signature;
|
|
53
|
+
}
|
|
54
|
+
const hash = (0, viem_1.hashMessage)(message);
|
|
55
|
+
const result = await cdp.evm.signHash({ address, hash });
|
|
56
|
+
return result.signature;
|
|
57
|
+
}
|
|
58
|
+
async function signTypedData(parameters) {
|
|
59
|
+
const { domain, types, primaryType, message } = parameters;
|
|
60
|
+
if (domain && types && primaryType && message) {
|
|
61
|
+
try {
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
+
const payload = { address, domain, types, primaryType, message };
|
|
64
|
+
const result = await cdp.evm.signTypedData(payload);
|
|
65
|
+
return result.signature;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// Fall back to hash-then-sign if CDP rejects the typed-data structure.
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const hash = (0, viem_1.hashTypedData)(parameters);
|
|
72
|
+
const result = await cdp.evm.signHash({ address, hash });
|
|
73
|
+
return result.signature;
|
|
74
|
+
}
|
|
75
|
+
async function signTransaction(transaction, options) {
|
|
76
|
+
const serializer = options?.serializer ?? viem_1.serializeTransaction;
|
|
77
|
+
const hash = (0, viem_1.keccak256)(serializer(transaction));
|
|
78
|
+
const result = await cdp.evm.signHash({ address, hash });
|
|
79
|
+
const { r, s, yParity } = (0, viem_1.hexToSignature)(result.signature);
|
|
80
|
+
return serializer(transaction, { r, s, yParity });
|
|
81
|
+
}
|
|
82
|
+
// viem's signTypedData generic cannot be satisfied by a hand-rolled adapter without casting — same pattern as hdKeyToAccount.
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
84
|
+
return (0, accounts_1.toAccount)({ address, signMessage, signTypedData, signTransaction });
|
|
85
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCdpAccount = void 0;
|
|
4
|
+
var cdp_1 = require("./cdp");
|
|
5
|
+
Object.defineProperty(exports, "createCdpAccount", { enumerable: true, get: function () { return cdp_1.createCdpAccount; } });
|
|
@@ -106,8 +106,9 @@ class X402Flow {
|
|
|
106
106
|
*/
|
|
107
107
|
async signPaymentV2(paymentRequired, accepted, userAddress) {
|
|
108
108
|
X402Flow.validateScheme(accepted.scheme);
|
|
109
|
-
const
|
|
110
|
-
const
|
|
109
|
+
const isV2Claims = hasValidationPolicy(accepted.extra);
|
|
110
|
+
const tab = await this.requestTab(isV2Claims ? 2 : 1, accepted, userAddress, paymentRequired.resource);
|
|
111
|
+
const claims = isV2Claims
|
|
111
112
|
? this.buildClaimsV2(accepted, tab, userAddress)
|
|
112
113
|
: this.buildClaims(accepted, tab, userAddress);
|
|
113
114
|
const signature = await this.signer.signPayment(claims, models_1.SigningScheme.EIP712);
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|