@strimz/sdk 0.1.1 → 0.2.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/dist/{browser-client-D6VUs85b.d.cts → browser-client-BzLGc50J.d.cts} +3 -1
- package/dist/{browser-client-D6VUs85b.d.ts → browser-client-BzLGc50J.d.ts} +3 -1
- package/dist/browser-client.cjs +32 -7
- package/dist/browser-client.cjs.map +1 -1
- package/dist/browser-client.d.cts +1 -1
- package/dist/browser-client.d.ts +1 -1
- package/dist/browser-client.js +33 -8
- package/dist/browser-client.js.map +1 -1
- package/dist/eip712.cjs +70 -0
- package/dist/eip712.cjs.map +1 -1
- package/dist/eip712.d.cts +91 -1
- package/dist/eip712.d.ts +91 -1
- package/dist/eip712.js +67 -1
- package/dist/eip712.js.map +1 -1
- package/dist/index.cjs +32 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/eip712/index.ts +13 -13
- package/src/eip712/pay-intent.ts +54 -0
- package/src/eip712/subscription-intent.ts +59 -0
- package/src/http/fetcher.ts +43 -8
- package/src/resources/checkout.ts +7 -0
package/dist/eip712.cjs
CHANGED
|
@@ -62,9 +62,79 @@ function buildPermitTypedData(params) {
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
// src/eip712/pay-intent.ts
|
|
66
|
+
var PAY_INTENT_TYPES = {
|
|
67
|
+
PayIntent: [
|
|
68
|
+
{ name: "merchantId", type: "uint256" },
|
|
69
|
+
{ name: "token", type: "address" },
|
|
70
|
+
{ name: "amount", type: "uint256" },
|
|
71
|
+
{ name: "nonce", type: "bytes32" },
|
|
72
|
+
{ name: "validBefore", type: "uint256" },
|
|
73
|
+
{ name: "ref", type: "bytes32" }
|
|
74
|
+
]
|
|
75
|
+
};
|
|
76
|
+
function buildPayIntentTypedData(params) {
|
|
77
|
+
return {
|
|
78
|
+
domain: {
|
|
79
|
+
name: "StrimzPayments",
|
|
80
|
+
version: "1",
|
|
81
|
+
chainId: params.chainId,
|
|
82
|
+
verifyingContract: params.verifyingContract
|
|
83
|
+
},
|
|
84
|
+
types: PAY_INTENT_TYPES,
|
|
85
|
+
primaryType: "PayIntent",
|
|
86
|
+
message: {
|
|
87
|
+
merchantId: params.merchantId,
|
|
88
|
+
token: params.token,
|
|
89
|
+
amount: params.amount,
|
|
90
|
+
nonce: params.nonce,
|
|
91
|
+
validBefore: params.validBefore,
|
|
92
|
+
ref: params.ref
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/eip712/subscription-intent.ts
|
|
98
|
+
var SUBSCRIPTION_INTENT_TYPES = {
|
|
99
|
+
SubscriptionIntent: [
|
|
100
|
+
{ name: "merchantId", type: "uint256" },
|
|
101
|
+
{ name: "token", type: "address" },
|
|
102
|
+
{ name: "amount", type: "uint256" },
|
|
103
|
+
{ name: "interval", type: "uint32" },
|
|
104
|
+
{ name: "startAt", type: "uint64" },
|
|
105
|
+
{ name: "endAt", type: "uint64" },
|
|
106
|
+
{ name: "permitDeadline", type: "uint256" }
|
|
107
|
+
]
|
|
108
|
+
};
|
|
109
|
+
function buildSubscriptionIntentTypedData(params) {
|
|
110
|
+
return {
|
|
111
|
+
domain: {
|
|
112
|
+
name: "StrimzSubscriptions",
|
|
113
|
+
version: "1",
|
|
114
|
+
chainId: params.chainId,
|
|
115
|
+
verifyingContract: params.verifyingContract
|
|
116
|
+
},
|
|
117
|
+
types: SUBSCRIPTION_INTENT_TYPES,
|
|
118
|
+
primaryType: "SubscriptionIntent",
|
|
119
|
+
message: {
|
|
120
|
+
merchantId: params.merchantId,
|
|
121
|
+
token: params.token,
|
|
122
|
+
amount: params.amount,
|
|
123
|
+
interval: params.interval,
|
|
124
|
+
startAt: params.startAt,
|
|
125
|
+
endAt: params.endAt,
|
|
126
|
+
permitDeadline: params.permitDeadline
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
exports.PAY_INTENT_TYPES = PAY_INTENT_TYPES;
|
|
65
132
|
exports.PERMIT_TYPES = PERMIT_TYPES;
|
|
66
133
|
exports.RECEIVE_WITH_AUTHORIZATION_TYPES = RECEIVE_WITH_AUTHORIZATION_TYPES;
|
|
134
|
+
exports.SUBSCRIPTION_INTENT_TYPES = SUBSCRIPTION_INTENT_TYPES;
|
|
135
|
+
exports.buildPayIntentTypedData = buildPayIntentTypedData;
|
|
67
136
|
exports.buildPermitTypedData = buildPermitTypedData;
|
|
68
137
|
exports.buildReceiveWithAuthorizationTypedData = buildReceiveWithAuthorizationTypedData;
|
|
138
|
+
exports.buildSubscriptionIntentTypedData = buildSubscriptionIntentTypedData;
|
|
69
139
|
//# sourceMappingURL=eip712.cjs.map
|
|
70
140
|
//# sourceMappingURL=eip712.cjs.map
|
package/dist/eip712.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/eip712/receive-with-authorization.ts","../src/eip712/permit.ts"],"names":[],"mappings":";;;AA8CO,IAAM,gCAAA,GAAmC;AAAA,EAC9C,wBAAA,EAA0B;AAAA,IACxB,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAU;AAAA,IAChC,EAAE,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,SAAA,EAAU;AAAA,IAC9B,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA,EAAU;AAAA,IACjC,EAAE,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,SAAA,EAAU;AAAA,IACtC,EAAE,IAAA,EAAM,aAAA,EAAe,IAAA,EAAM,SAAA,EAAU;AAAA,IACvC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA;AAAU;AAErC;AAWO,SAAS,uCACd,MAAA,EAC6C;AAC7C,EAAA,OAAO;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AS,MAAA,CAAO,OAAA;AAAA,MAChB,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,UAAU,MAAA,CAAO;AAAA;AACnB,GACF;AACF","file":"eip712.cjs","sourcesContent":["import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the EIP-3009 ReceiveWithAuthorization typed-data.\n *\n * - `chainId` is the EVM chain id (Arc Testnet = 5042002).\n * - `token` is the ERC-20 contract whose `receiveWithAuthorization` is\n * being invoked. Usually USDC at `0x36...` on Arc.\n * - `tokenName` and `tokenVersion` form the EIP-712 domain. Real USDC\n * on most chains uses `name=\"USD Coin\"` and `version=\"2\"`; tests\n * use whatever the mock token reports. Always read these from the\n * token contract at runtime to avoid drift.\n * - `from` is the payer. The wallet that produces the signature must\n * match this address.\n * - `to` is the recipient of the funds. For Strimz this is the\n * StrimzPayments contract address (the contract pulls funds into\n * itself, then forwards the fee and net split).\n * - `value` is the gross amount in token base units.\n * - `validAfter` / `validBefore` are unix-second timestamps bounding\n * the signature's validity. Strimz's default checkout window is\n * 5 minutes; integrators may widen this for usage-based billing.\n * - `nonce` is a single-use 32-byte value. Generate with crypto.randomBytes\n * (server) or crypto.getRandomValues (browser). The token contract\n * tracks `(authorizer, nonce) -> used` and rejects replays.\n */\nexport interface ReceiveWithAuthorizationParams {\n chainId: number\n token: `0x${string}`\n tokenName: string\n tokenVersion: string\n from: `0x${string}`\n to: `0x${string}`\n value: bigint\n validAfter: bigint\n validBefore: bigint\n nonce: `0x${string}`\n}\n\n/**\n * EIP-712 type definition for `ReceiveWithAuthorization`. Stable, and\n * shared by every EIP-3009 implementation (USDC, EURC, etc.).\n *\n * Exported so consumers can introspect or extend with sibling\n * primitive types (e.g. for x402 batched signing schemes that wrap\n * multiple authorizations in one signature).\n */\nexport const RECEIVE_WITH_AUTHORIZATION_TYPES = {\n ReceiveWithAuthorization: [\n { name: 'from', type: 'address' },\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'validAfter', type: 'uint256' },\n { name: 'validBefore', type: 'uint256' },\n { name: 'nonce', type: 'bytes32' },\n ],\n} as const\n\n/**\n * Build the typed-data structure for an EIP-3009\n * `ReceiveWithAuthorization` signature. Returns the canonical shape\n * compatible with viem, ethers, Privy, and Reown.\n *\n * Pass the result to `walletClient.signTypedData(typedData)` (viem)\n * or `signer._signTypedData(domain, types, message)` (ethers). The\n * SDK does not bind to a specific signer.\n */\nexport function buildReceiveWithAuthorizationTypedData(\n params: ReceiveWithAuthorizationParams,\n): Eip712TypedData<'ReceiveWithAuthorization'> {\n return {\n domain: {\n name: params.tokenName,\n version: params.tokenVersion,\n chainId: params.chainId,\n verifyingContract: params.token,\n },\n types: RECEIVE_WITH_AUTHORIZATION_TYPES,\n primaryType: 'ReceiveWithAuthorization',\n message: {\n from: params.from,\n to: params.to,\n value: params.value,\n validAfter: params.validAfter,\n validBefore: params.validBefore,\n nonce: params.nonce,\n },\n }\n}\n","import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the EIP-2612 Permit typed-data.\n *\n * - `chainId`, `token`, `tokenName`, `tokenVersion` form the EIP-712\n * domain (same shape as the EIP-3009 builder).\n * - `owner` is the token holder authorising the allowance. Must match\n * the signing wallet.\n * - `spender` is the contract that will pull funds. For Strimz\n * subscriptions this is the StrimzSubscriptions contract.\n * - `value` is the allowance to grant in token base units.\n * `type(uint256).max` produces an unlimited allowance and is the\n * common case for subscription enrolment.\n * - `nonce` is the owner's *current* `nonces(owner)` reading from the\n * token contract. The SDK does not fetch this. The caller is\n * expected to have just queried it. Race-free: the token rejects\n * stale nonces, so a concurrent permit on the same owner causes one\n * to fail predictably.\n * - `deadline` is the unix-second timestamp after which the permit\n * expires. Strimz default for subscription enrolment is 24h. Enough\n * headroom for a slow merchant submit pipeline without leaving an\n * indefinite signature window.\n */\nexport interface PermitParams {\n chainId: number\n token: `0x${string}`\n tokenName: string\n tokenVersion: string\n owner: `0x${string}`\n spender: `0x${string}`\n value: bigint\n nonce: bigint\n deadline: bigint\n}\n\n/**\n * EIP-712 type definition for `Permit`. Stable across every EIP-2612\n * implementation (USDC, EURC, DAI v2, etc.).\n */\nexport const PERMIT_TYPES = {\n Permit: [\n { name: 'owner', type: 'address' },\n { name: 'spender', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n} as const\n\n/**\n * Build the typed-data structure for an EIP-2612 `Permit` signature.\n * Returns the canonical shape compatible with viem, ethers, Privy,\n * and Reown.\n */\nexport function buildPermitTypedData(params: PermitParams): Eip712TypedData<'Permit'> {\n return {\n domain: {\n name: params.tokenName,\n version: params.tokenVersion,\n chainId: params.chainId,\n verifyingContract: params.token,\n },\n types: PERMIT_TYPES,\n primaryType: 'Permit',\n message: {\n owner: params.owner,\n spender: params.spender,\n value: params.value,\n nonce: params.nonce,\n deadline: params.deadline,\n },\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/eip712/receive-with-authorization.ts","../src/eip712/permit.ts","../src/eip712/pay-intent.ts","../src/eip712/subscription-intent.ts"],"names":[],"mappings":";;;AA8CO,IAAM,gCAAA,GAAmC;AAAA,EAC9C,wBAAA,EAA0B;AAAA,IACxB,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAU;AAAA,IAChC,EAAE,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,SAAA,EAAU;AAAA,IAC9B,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA,EAAU;AAAA,IACjC,EAAE,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,SAAA,EAAU;AAAA,IACtC,EAAE,IAAA,EAAM,aAAA,EAAe,IAAA,EAAM,SAAA,EAAU;AAAA,IACvC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA;AAAU;AAErC;AAWO,SAAS,uCACd,MAAA,EAC6C;AAC7C,EAAA,OAAO;AAAA,IACL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A,EAAU;AAAA,IACtC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA,EAAU;AAAA,IACjC,EAAE,IAAA,EAAM,QAAA,EAAU,IAAA,EAAM,SAAA,EAAU;AAAA,IAClC,EAAE,IAAA,EAAM,UAAA,EAAY,IAAA,EAAM,QAAA,EAAS;AAAA,IACnC,EAAE,IAAA,EAAM,SAAA,EAAW,IAAA,EAAM,QAAA,EAAS;AAAA,IAClC,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,QAAA,EAAS;AAAA,IAChC,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,SAAA;AAAU;AAE9C;AAGO,SAAS,iCACd,MAAA,EACuC;AACvC,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ;AAAA,MACN,IAAA,EAAM,qBAAA;AAAA,MACN,OAAA,EAAS,GAAA;AAAA,MACT,SAAS,MAAA,CAAO,OAAA;AAAA,MAChB,mBAAmB,MAAA,CAAO;AAAA,KAC5B;AAAA,IACA,KAAA,EAAO,yBAAA;AAAA,IACP,WAAA,EAAa,oBAAA;AAAA,IACb,OAAA,EAAS;AAAA,MACP,YAAY,MAAA,CAAO,UAAA;AAAA,MACnB,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,QAAQ,MAAA,CAAO,MAAA;AAAA,MACf,UAAU,MAAA,CAAO,QAAA;AAAA,MACjB,SAAS,MAAA,CAAO,OAAA;AAAA,MAChB,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,gBAAgB,MAAA,CAAO;AAAA;AACzB,GACF;AACF","file":"eip712.cjs","sourcesContent":["import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the EIP-3009 ReceiveWithAuthorization typed-data.\n *\n * - `chainId` is the EVM chain id (Arc Testnet = 5042002).\n * - `token` is the ERC-20 contract whose `receiveWithAuthorization` is\n * being invoked. Usually USDC at `0x36...` on Arc.\n * - `tokenName` and `tokenVersion` form the EIP-712 domain. Real USDC\n * on most chains uses `name=\"USD Coin\"` and `version=\"2\"`; tests\n * use whatever the mock token reports. Always read these from the\n * token contract at runtime to avoid drift.\n * - `from` is the payer. The wallet that produces the signature must\n * match this address.\n * - `to` is the recipient of the funds. For Strimz this is the\n * StrimzPayments contract address (the contract pulls funds into\n * itself, then forwards the fee and net split).\n * - `value` is the gross amount in token base units.\n * - `validAfter` / `validBefore` are unix-second timestamps bounding\n * the signature's validity. Strimz's default checkout window is\n * 5 minutes; integrators may widen this for usage-based billing.\n * - `nonce` is a single-use 32-byte value. Generate with crypto.randomBytes\n * (server) or crypto.getRandomValues (browser). The token contract\n * tracks `(authorizer, nonce) -> used` and rejects replays.\n */\nexport interface ReceiveWithAuthorizationParams {\n chainId: number\n token: `0x${string}`\n tokenName: string\n tokenVersion: string\n from: `0x${string}`\n to: `0x${string}`\n value: bigint\n validAfter: bigint\n validBefore: bigint\n nonce: `0x${string}`\n}\n\n/**\n * EIP-712 type definition for `ReceiveWithAuthorization`. Stable, and\n * shared by every EIP-3009 implementation (USDC, EURC, etc.).\n *\n * Exported so consumers can introspect or extend with sibling\n * primitive types (e.g. for x402 batched signing schemes that wrap\n * multiple authorizations in one signature).\n */\nexport const RECEIVE_WITH_AUTHORIZATION_TYPES = {\n ReceiveWithAuthorization: [\n { name: 'from', type: 'address' },\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'validAfter', type: 'uint256' },\n { name: 'validBefore', type: 'uint256' },\n { name: 'nonce', type: 'bytes32' },\n ],\n} as const\n\n/**\n * Build the typed-data structure for an EIP-3009\n * `ReceiveWithAuthorization` signature. Returns the canonical shape\n * compatible with viem, ethers, Privy, and Reown.\n *\n * Pass the result to `walletClient.signTypedData(typedData)` (viem)\n * or `signer._signTypedData(domain, types, message)` (ethers). The\n * SDK does not bind to a specific signer.\n */\nexport function buildReceiveWithAuthorizationTypedData(\n params: ReceiveWithAuthorizationParams,\n): Eip712TypedData<'ReceiveWithAuthorization'> {\n return {\n domain: {\n name: params.tokenName,\n version: params.tokenVersion,\n chainId: params.chainId,\n verifyingContract: params.token,\n },\n types: RECEIVE_WITH_AUTHORIZATION_TYPES,\n primaryType: 'ReceiveWithAuthorization',\n message: {\n from: params.from,\n to: params.to,\n value: params.value,\n validAfter: params.validAfter,\n validBefore: params.validBefore,\n nonce: params.nonce,\n },\n }\n}\n","import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the EIP-2612 Permit typed-data.\n *\n * - `chainId`, `token`, `tokenName`, `tokenVersion` form the EIP-712\n * domain (same shape as the EIP-3009 builder).\n * - `owner` is the token holder authorising the allowance. Must match\n * the signing wallet.\n * - `spender` is the contract that will pull funds. For Strimz\n * subscriptions this is the StrimzSubscriptions contract.\n * - `value` is the allowance to grant in token base units.\n * `type(uint256).max` produces an unlimited allowance and is the\n * common case for subscription enrolment.\n * - `nonce` is the owner's *current* `nonces(owner)` reading from the\n * token contract. The SDK does not fetch this. The caller is\n * expected to have just queried it. Race-free: the token rejects\n * stale nonces, so a concurrent permit on the same owner causes one\n * to fail predictably.\n * - `deadline` is the unix-second timestamp after which the permit\n * expires. Strimz default for subscription enrolment is 24h. Enough\n * headroom for a slow merchant submit pipeline without leaving an\n * indefinite signature window.\n */\nexport interface PermitParams {\n chainId: number\n token: `0x${string}`\n tokenName: string\n tokenVersion: string\n owner: `0x${string}`\n spender: `0x${string}`\n value: bigint\n nonce: bigint\n deadline: bigint\n}\n\n/**\n * EIP-712 type definition for `Permit`. Stable across every EIP-2612\n * implementation (USDC, EURC, DAI v2, etc.).\n */\nexport const PERMIT_TYPES = {\n Permit: [\n { name: 'owner', type: 'address' },\n { name: 'spender', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n} as const\n\n/**\n * Build the typed-data structure for an EIP-2612 `Permit` signature.\n * Returns the canonical shape compatible with viem, ethers, Privy,\n * and Reown.\n */\nexport function buildPermitTypedData(params: PermitParams): Eip712TypedData<'Permit'> {\n return {\n domain: {\n name: params.tokenName,\n version: params.tokenVersion,\n chainId: params.chainId,\n verifyingContract: params.token,\n },\n types: PERMIT_TYPES,\n primaryType: 'Permit',\n message: {\n owner: params.owner,\n spender: params.spender,\n value: params.value,\n nonce: params.nonce,\n deadline: params.deadline,\n },\n }\n}\n","import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the Strimz PayIntent. Payer signs this alongside the\n * EIP-3009 auth. Without it, a valid auth sig can be redirected to\n * pay a different merchant.\n *\n * Every field must match the corresponding argument the API will\n * submit on-chain — the contract compares them via ecrecover.\n */\nexport interface PayIntentParams {\n chainId: number\n verifyingContract: `0x${string}`\n merchantId: bigint\n token: `0x${string}`\n amount: bigint\n nonce: `0x${string}`\n validBefore: bigint\n ref: `0x${string}`\n}\n\n/** Field order matches `PAY_INTENT_TYPEHASH` in `StrimzPayments.sol`. */\nexport const PAY_INTENT_TYPES = {\n PayIntent: [\n { name: 'merchantId', type: 'uint256' },\n { name: 'token', type: 'address' },\n { name: 'amount', type: 'uint256' },\n { name: 'nonce', type: 'bytes32' },\n { name: 'validBefore', type: 'uint256' },\n { name: 'ref', type: 'bytes32' },\n ],\n} as const\n\n/** Domain name + version mirror `EIP712(\"StrimzPayments\", \"1\")`. */\nexport function buildPayIntentTypedData(params: PayIntentParams): Eip712TypedData<'PayIntent'> {\n return {\n domain: {\n name: 'StrimzPayments',\n version: '1',\n chainId: params.chainId,\n verifyingContract: params.verifyingContract,\n },\n types: PAY_INTENT_TYPES,\n primaryType: 'PayIntent',\n message: {\n merchantId: params.merchantId,\n token: params.token,\n amount: params.amount,\n nonce: params.nonce,\n validBefore: params.validBefore,\n ref: params.ref,\n },\n }\n}\n","import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the Strimz SubscriptionIntent. Payer signs this\n * alongside the ERC-2612 permit. Without it, a valid permit can be\n * used to enrol the payer in a plan they never picked.\n *\n * `permitDeadline` ties this intent to the accompanying permit —\n * they expire together.\n */\nexport interface SubscriptionIntentParams {\n chainId: number\n verifyingContract: `0x${string}`\n merchantId: bigint\n token: `0x${string}`\n amount: bigint\n interval: number\n startAt: bigint\n endAt: bigint\n permitDeadline: bigint\n}\n\n/** Field order matches `SUBSCRIPTION_INTENT_TYPEHASH` in the contract. */\nexport const SUBSCRIPTION_INTENT_TYPES = {\n SubscriptionIntent: [\n { name: 'merchantId', type: 'uint256' },\n { name: 'token', type: 'address' },\n { name: 'amount', type: 'uint256' },\n { name: 'interval', type: 'uint32' },\n { name: 'startAt', type: 'uint64' },\n { name: 'endAt', type: 'uint64' },\n { name: 'permitDeadline', type: 'uint256' },\n ],\n} as const\n\n/** Domain mirrors `EIP712(\"StrimzSubscriptions\", \"1\")`. */\nexport function buildSubscriptionIntentTypedData(\n params: SubscriptionIntentParams,\n): Eip712TypedData<'SubscriptionIntent'> {\n return {\n domain: {\n name: 'StrimzSubscriptions',\n version: '1',\n chainId: params.chainId,\n verifyingContract: params.verifyingContract,\n },\n types: SUBSCRIPTION_INTENT_TYPES,\n primaryType: 'SubscriptionIntent',\n message: {\n merchantId: params.merchantId,\n token: params.token,\n amount: params.amount,\n interval: params.interval,\n startAt: params.startAt,\n endAt: params.endAt,\n permitDeadline: params.permitDeadline,\n },\n }\n}\n"]}
|
package/dist/eip712.d.cts
CHANGED
|
@@ -179,4 +179,94 @@ declare const PERMIT_TYPES: {
|
|
|
179
179
|
*/
|
|
180
180
|
declare function buildPermitTypedData(params: PermitParams): Eip712TypedData<'Permit'>;
|
|
181
181
|
|
|
182
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Inputs for the Strimz PayIntent. Payer signs this alongside the
|
|
184
|
+
* EIP-3009 auth. Without it, a valid auth sig can be redirected to
|
|
185
|
+
* pay a different merchant.
|
|
186
|
+
*
|
|
187
|
+
* Every field must match the corresponding argument the API will
|
|
188
|
+
* submit on-chain — the contract compares them via ecrecover.
|
|
189
|
+
*/
|
|
190
|
+
interface PayIntentParams {
|
|
191
|
+
chainId: number;
|
|
192
|
+
verifyingContract: `0x${string}`;
|
|
193
|
+
merchantId: bigint;
|
|
194
|
+
token: `0x${string}`;
|
|
195
|
+
amount: bigint;
|
|
196
|
+
nonce: `0x${string}`;
|
|
197
|
+
validBefore: bigint;
|
|
198
|
+
ref: `0x${string}`;
|
|
199
|
+
}
|
|
200
|
+
/** Field order matches `PAY_INTENT_TYPEHASH` in `StrimzPayments.sol`. */
|
|
201
|
+
declare const PAY_INTENT_TYPES: {
|
|
202
|
+
readonly PayIntent: readonly [{
|
|
203
|
+
readonly name: "merchantId";
|
|
204
|
+
readonly type: "uint256";
|
|
205
|
+
}, {
|
|
206
|
+
readonly name: "token";
|
|
207
|
+
readonly type: "address";
|
|
208
|
+
}, {
|
|
209
|
+
readonly name: "amount";
|
|
210
|
+
readonly type: "uint256";
|
|
211
|
+
}, {
|
|
212
|
+
readonly name: "nonce";
|
|
213
|
+
readonly type: "bytes32";
|
|
214
|
+
}, {
|
|
215
|
+
readonly name: "validBefore";
|
|
216
|
+
readonly type: "uint256";
|
|
217
|
+
}, {
|
|
218
|
+
readonly name: "ref";
|
|
219
|
+
readonly type: "bytes32";
|
|
220
|
+
}];
|
|
221
|
+
};
|
|
222
|
+
/** Domain name + version mirror `EIP712("StrimzPayments", "1")`. */
|
|
223
|
+
declare function buildPayIntentTypedData(params: PayIntentParams): Eip712TypedData<'PayIntent'>;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Inputs for the Strimz SubscriptionIntent. Payer signs this
|
|
227
|
+
* alongside the ERC-2612 permit. Without it, a valid permit can be
|
|
228
|
+
* used to enrol the payer in a plan they never picked.
|
|
229
|
+
*
|
|
230
|
+
* `permitDeadline` ties this intent to the accompanying permit —
|
|
231
|
+
* they expire together.
|
|
232
|
+
*/
|
|
233
|
+
interface SubscriptionIntentParams {
|
|
234
|
+
chainId: number;
|
|
235
|
+
verifyingContract: `0x${string}`;
|
|
236
|
+
merchantId: bigint;
|
|
237
|
+
token: `0x${string}`;
|
|
238
|
+
amount: bigint;
|
|
239
|
+
interval: number;
|
|
240
|
+
startAt: bigint;
|
|
241
|
+
endAt: bigint;
|
|
242
|
+
permitDeadline: bigint;
|
|
243
|
+
}
|
|
244
|
+
/** Field order matches `SUBSCRIPTION_INTENT_TYPEHASH` in the contract. */
|
|
245
|
+
declare const SUBSCRIPTION_INTENT_TYPES: {
|
|
246
|
+
readonly SubscriptionIntent: readonly [{
|
|
247
|
+
readonly name: "merchantId";
|
|
248
|
+
readonly type: "uint256";
|
|
249
|
+
}, {
|
|
250
|
+
readonly name: "token";
|
|
251
|
+
readonly type: "address";
|
|
252
|
+
}, {
|
|
253
|
+
readonly name: "amount";
|
|
254
|
+
readonly type: "uint256";
|
|
255
|
+
}, {
|
|
256
|
+
readonly name: "interval";
|
|
257
|
+
readonly type: "uint32";
|
|
258
|
+
}, {
|
|
259
|
+
readonly name: "startAt";
|
|
260
|
+
readonly type: "uint64";
|
|
261
|
+
}, {
|
|
262
|
+
readonly name: "endAt";
|
|
263
|
+
readonly type: "uint64";
|
|
264
|
+
}, {
|
|
265
|
+
readonly name: "permitDeadline";
|
|
266
|
+
readonly type: "uint256";
|
|
267
|
+
}];
|
|
268
|
+
};
|
|
269
|
+
/** Domain mirrors `EIP712("StrimzSubscriptions", "1")`. */
|
|
270
|
+
declare function buildSubscriptionIntentTypedData(params: SubscriptionIntentParams): Eip712TypedData<'SubscriptionIntent'>;
|
|
271
|
+
|
|
272
|
+
export { type Eip712Domain, type Eip712Field, type Eip712TypedData, type Eip712Types, PAY_INTENT_TYPES, PERMIT_TYPES, type PayIntentParams, type PermitParams, RECEIVE_WITH_AUTHORIZATION_TYPES, type ReceiveWithAuthorizationParams, SUBSCRIPTION_INTENT_TYPES, type SubscriptionIntentParams, buildPayIntentTypedData, buildPermitTypedData, buildReceiveWithAuthorizationTypedData, buildSubscriptionIntentTypedData };
|
package/dist/eip712.d.ts
CHANGED
|
@@ -179,4 +179,94 @@ declare const PERMIT_TYPES: {
|
|
|
179
179
|
*/
|
|
180
180
|
declare function buildPermitTypedData(params: PermitParams): Eip712TypedData<'Permit'>;
|
|
181
181
|
|
|
182
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Inputs for the Strimz PayIntent. Payer signs this alongside the
|
|
184
|
+
* EIP-3009 auth. Without it, a valid auth sig can be redirected to
|
|
185
|
+
* pay a different merchant.
|
|
186
|
+
*
|
|
187
|
+
* Every field must match the corresponding argument the API will
|
|
188
|
+
* submit on-chain — the contract compares them via ecrecover.
|
|
189
|
+
*/
|
|
190
|
+
interface PayIntentParams {
|
|
191
|
+
chainId: number;
|
|
192
|
+
verifyingContract: `0x${string}`;
|
|
193
|
+
merchantId: bigint;
|
|
194
|
+
token: `0x${string}`;
|
|
195
|
+
amount: bigint;
|
|
196
|
+
nonce: `0x${string}`;
|
|
197
|
+
validBefore: bigint;
|
|
198
|
+
ref: `0x${string}`;
|
|
199
|
+
}
|
|
200
|
+
/** Field order matches `PAY_INTENT_TYPEHASH` in `StrimzPayments.sol`. */
|
|
201
|
+
declare const PAY_INTENT_TYPES: {
|
|
202
|
+
readonly PayIntent: readonly [{
|
|
203
|
+
readonly name: "merchantId";
|
|
204
|
+
readonly type: "uint256";
|
|
205
|
+
}, {
|
|
206
|
+
readonly name: "token";
|
|
207
|
+
readonly type: "address";
|
|
208
|
+
}, {
|
|
209
|
+
readonly name: "amount";
|
|
210
|
+
readonly type: "uint256";
|
|
211
|
+
}, {
|
|
212
|
+
readonly name: "nonce";
|
|
213
|
+
readonly type: "bytes32";
|
|
214
|
+
}, {
|
|
215
|
+
readonly name: "validBefore";
|
|
216
|
+
readonly type: "uint256";
|
|
217
|
+
}, {
|
|
218
|
+
readonly name: "ref";
|
|
219
|
+
readonly type: "bytes32";
|
|
220
|
+
}];
|
|
221
|
+
};
|
|
222
|
+
/** Domain name + version mirror `EIP712("StrimzPayments", "1")`. */
|
|
223
|
+
declare function buildPayIntentTypedData(params: PayIntentParams): Eip712TypedData<'PayIntent'>;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Inputs for the Strimz SubscriptionIntent. Payer signs this
|
|
227
|
+
* alongside the ERC-2612 permit. Without it, a valid permit can be
|
|
228
|
+
* used to enrol the payer in a plan they never picked.
|
|
229
|
+
*
|
|
230
|
+
* `permitDeadline` ties this intent to the accompanying permit —
|
|
231
|
+
* they expire together.
|
|
232
|
+
*/
|
|
233
|
+
interface SubscriptionIntentParams {
|
|
234
|
+
chainId: number;
|
|
235
|
+
verifyingContract: `0x${string}`;
|
|
236
|
+
merchantId: bigint;
|
|
237
|
+
token: `0x${string}`;
|
|
238
|
+
amount: bigint;
|
|
239
|
+
interval: number;
|
|
240
|
+
startAt: bigint;
|
|
241
|
+
endAt: bigint;
|
|
242
|
+
permitDeadline: bigint;
|
|
243
|
+
}
|
|
244
|
+
/** Field order matches `SUBSCRIPTION_INTENT_TYPEHASH` in the contract. */
|
|
245
|
+
declare const SUBSCRIPTION_INTENT_TYPES: {
|
|
246
|
+
readonly SubscriptionIntent: readonly [{
|
|
247
|
+
readonly name: "merchantId";
|
|
248
|
+
readonly type: "uint256";
|
|
249
|
+
}, {
|
|
250
|
+
readonly name: "token";
|
|
251
|
+
readonly type: "address";
|
|
252
|
+
}, {
|
|
253
|
+
readonly name: "amount";
|
|
254
|
+
readonly type: "uint256";
|
|
255
|
+
}, {
|
|
256
|
+
readonly name: "interval";
|
|
257
|
+
readonly type: "uint32";
|
|
258
|
+
}, {
|
|
259
|
+
readonly name: "startAt";
|
|
260
|
+
readonly type: "uint64";
|
|
261
|
+
}, {
|
|
262
|
+
readonly name: "endAt";
|
|
263
|
+
readonly type: "uint64";
|
|
264
|
+
}, {
|
|
265
|
+
readonly name: "permitDeadline";
|
|
266
|
+
readonly type: "uint256";
|
|
267
|
+
}];
|
|
268
|
+
};
|
|
269
|
+
/** Domain mirrors `EIP712("StrimzSubscriptions", "1")`. */
|
|
270
|
+
declare function buildSubscriptionIntentTypedData(params: SubscriptionIntentParams): Eip712TypedData<'SubscriptionIntent'>;
|
|
271
|
+
|
|
272
|
+
export { type Eip712Domain, type Eip712Field, type Eip712TypedData, type Eip712Types, PAY_INTENT_TYPES, PERMIT_TYPES, type PayIntentParams, type PermitParams, RECEIVE_WITH_AUTHORIZATION_TYPES, type ReceiveWithAuthorizationParams, SUBSCRIPTION_INTENT_TYPES, type SubscriptionIntentParams, buildPayIntentTypedData, buildPermitTypedData, buildReceiveWithAuthorizationTypedData, buildSubscriptionIntentTypedData };
|
package/dist/eip712.js
CHANGED
|
@@ -60,6 +60,72 @@ function buildPermitTypedData(params) {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
// src/eip712/pay-intent.ts
|
|
64
|
+
var PAY_INTENT_TYPES = {
|
|
65
|
+
PayIntent: [
|
|
66
|
+
{ name: "merchantId", type: "uint256" },
|
|
67
|
+
{ name: "token", type: "address" },
|
|
68
|
+
{ name: "amount", type: "uint256" },
|
|
69
|
+
{ name: "nonce", type: "bytes32" },
|
|
70
|
+
{ name: "validBefore", type: "uint256" },
|
|
71
|
+
{ name: "ref", type: "bytes32" }
|
|
72
|
+
]
|
|
73
|
+
};
|
|
74
|
+
function buildPayIntentTypedData(params) {
|
|
75
|
+
return {
|
|
76
|
+
domain: {
|
|
77
|
+
name: "StrimzPayments",
|
|
78
|
+
version: "1",
|
|
79
|
+
chainId: params.chainId,
|
|
80
|
+
verifyingContract: params.verifyingContract
|
|
81
|
+
},
|
|
82
|
+
types: PAY_INTENT_TYPES,
|
|
83
|
+
primaryType: "PayIntent",
|
|
84
|
+
message: {
|
|
85
|
+
merchantId: params.merchantId,
|
|
86
|
+
token: params.token,
|
|
87
|
+
amount: params.amount,
|
|
88
|
+
nonce: params.nonce,
|
|
89
|
+
validBefore: params.validBefore,
|
|
90
|
+
ref: params.ref
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/eip712/subscription-intent.ts
|
|
96
|
+
var SUBSCRIPTION_INTENT_TYPES = {
|
|
97
|
+
SubscriptionIntent: [
|
|
98
|
+
{ name: "merchantId", type: "uint256" },
|
|
99
|
+
{ name: "token", type: "address" },
|
|
100
|
+
{ name: "amount", type: "uint256" },
|
|
101
|
+
{ name: "interval", type: "uint32" },
|
|
102
|
+
{ name: "startAt", type: "uint64" },
|
|
103
|
+
{ name: "endAt", type: "uint64" },
|
|
104
|
+
{ name: "permitDeadline", type: "uint256" }
|
|
105
|
+
]
|
|
106
|
+
};
|
|
107
|
+
function buildSubscriptionIntentTypedData(params) {
|
|
108
|
+
return {
|
|
109
|
+
domain: {
|
|
110
|
+
name: "StrimzSubscriptions",
|
|
111
|
+
version: "1",
|
|
112
|
+
chainId: params.chainId,
|
|
113
|
+
verifyingContract: params.verifyingContract
|
|
114
|
+
},
|
|
115
|
+
types: SUBSCRIPTION_INTENT_TYPES,
|
|
116
|
+
primaryType: "SubscriptionIntent",
|
|
117
|
+
message: {
|
|
118
|
+
merchantId: params.merchantId,
|
|
119
|
+
token: params.token,
|
|
120
|
+
amount: params.amount,
|
|
121
|
+
interval: params.interval,
|
|
122
|
+
startAt: params.startAt,
|
|
123
|
+
endAt: params.endAt,
|
|
124
|
+
permitDeadline: params.permitDeadline
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { PAY_INTENT_TYPES, PERMIT_TYPES, RECEIVE_WITH_AUTHORIZATION_TYPES, SUBSCRIPTION_INTENT_TYPES, buildPayIntentTypedData, buildPermitTypedData, buildReceiveWithAuthorizationTypedData, buildSubscriptionIntentTypedData };
|
|
64
130
|
//# sourceMappingURL=eip712.js.map
|
|
65
131
|
//# sourceMappingURL=eip712.js.map
|
package/dist/eip712.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/eip712/receive-with-authorization.ts","../src/eip712/permit.ts"],"names":[],"mappings":";AA8CO,IAAM,gCAAA,GAAmC;AAAA,EAC9C,wBAAA,EAA0B;AA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,IAAA,EAAM,SAAA,EAAU;AAAA,IACjC,EAAE,IAAA,EAAM,UAAA,EAAY,IAAA,EAAM,SAAA;AAAU;AAExC;AAOO,SAAS,qBAAqB,MAAA,EAAiD;AACpF,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ;AAAA,MACN,MAAM,MAAA,CAAO,SAAA;AAAA,MACb,SAAS,MAAA,CAAO,YAAA;AAAA,MAChB,SAAS,MAAA,CAAO,OAAA;AAAA,MAChB,mBAAmB,MAAA,CAAO;AAAA,KAC5B;AAAA,IACA,KAAA,EAAO,YAAA;AAAA,IACP,WAAA,EAAa,QAAA;AAAA,IACb,OAAA,EAAS;AAAA,MACP,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,SAAS,MAAA,CAAO,OAAA;AAAA,MAChB,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,UAAU,MAAA,CAAO;AAAA;AACnB,GACF;AACF","file":"eip712.js","sourcesContent":["import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the EIP-3009 ReceiveWithAuthorization typed-data.\n *\n * - `chainId` is the EVM chain id (Arc Testnet = 5042002).\n * - `token` is the ERC-20 contract whose `receiveWithAuthorization` is\n * being invoked. Usually USDC at `0x36...` on Arc.\n * - `tokenName` and `tokenVersion` form the EIP-712 domain. Real USDC\n * on most chains uses `name=\"USD Coin\"` and `version=\"2\"`; tests\n * use whatever the mock token reports. Always read these from the\n * token contract at runtime to avoid drift.\n * - `from` is the payer. The wallet that produces the signature must\n * match this address.\n * - `to` is the recipient of the funds. For Strimz this is the\n * StrimzPayments contract address (the contract pulls funds into\n * itself, then forwards the fee and net split).\n * - `value` is the gross amount in token base units.\n * - `validAfter` / `validBefore` are unix-second timestamps bounding\n * the signature's validity. Strimz's default checkout window is\n * 5 minutes; integrators may widen this for usage-based billing.\n * - `nonce` is a single-use 32-byte value. Generate with crypto.randomBytes\n * (server) or crypto.getRandomValues (browser). The token contract\n * tracks `(authorizer, nonce) -> used` and rejects replays.\n */\nexport interface ReceiveWithAuthorizationParams {\n chainId: number\n token: `0x${string}`\n tokenName: string\n tokenVersion: string\n from: `0x${string}`\n to: `0x${string}`\n value: bigint\n validAfter: bigint\n validBefore: bigint\n nonce: `0x${string}`\n}\n\n/**\n * EIP-712 type definition for `ReceiveWithAuthorization`. Stable, and\n * shared by every EIP-3009 implementation (USDC, EURC, etc.).\n *\n * Exported so consumers can introspect or extend with sibling\n * primitive types (e.g. for x402 batched signing schemes that wrap\n * multiple authorizations in one signature).\n */\nexport const RECEIVE_WITH_AUTHORIZATION_TYPES = {\n ReceiveWithAuthorization: [\n { name: 'from', type: 'address' },\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'validAfter', type: 'uint256' },\n { name: 'validBefore', type: 'uint256' },\n { name: 'nonce', type: 'bytes32' },\n ],\n} as const\n\n/**\n * Build the typed-data structure for an EIP-3009\n * `ReceiveWithAuthorization` signature. Returns the canonical shape\n * compatible with viem, ethers, Privy, and Reown.\n *\n * Pass the result to `walletClient.signTypedData(typedData)` (viem)\n * or `signer._signTypedData(domain, types, message)` (ethers). The\n * SDK does not bind to a specific signer.\n */\nexport function buildReceiveWithAuthorizationTypedData(\n params: ReceiveWithAuthorizationParams,\n): Eip712TypedData<'ReceiveWithAuthorization'> {\n return {\n domain: {\n name: params.tokenName,\n version: params.tokenVersion,\n chainId: params.chainId,\n verifyingContract: params.token,\n },\n types: RECEIVE_WITH_AUTHORIZATION_TYPES,\n primaryType: 'ReceiveWithAuthorization',\n message: {\n from: params.from,\n to: params.to,\n value: params.value,\n validAfter: params.validAfter,\n validBefore: params.validBefore,\n nonce: params.nonce,\n },\n }\n}\n","import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the EIP-2612 Permit typed-data.\n *\n * - `chainId`, `token`, `tokenName`, `tokenVersion` form the EIP-712\n * domain (same shape as the EIP-3009 builder).\n * - `owner` is the token holder authorising the allowance. Must match\n * the signing wallet.\n * - `spender` is the contract that will pull funds. For Strimz\n * subscriptions this is the StrimzSubscriptions contract.\n * - `value` is the allowance to grant in token base units.\n * `type(uint256).max` produces an unlimited allowance and is the\n * common case for subscription enrolment.\n * - `nonce` is the owner's *current* `nonces(owner)` reading from the\n * token contract. The SDK does not fetch this. The caller is\n * expected to have just queried it. Race-free: the token rejects\n * stale nonces, so a concurrent permit on the same owner causes one\n * to fail predictably.\n * - `deadline` is the unix-second timestamp after which the permit\n * expires. Strimz default for subscription enrolment is 24h. Enough\n * headroom for a slow merchant submit pipeline without leaving an\n * indefinite signature window.\n */\nexport interface PermitParams {\n chainId: number\n token: `0x${string}`\n tokenName: string\n tokenVersion: string\n owner: `0x${string}`\n spender: `0x${string}`\n value: bigint\n nonce: bigint\n deadline: bigint\n}\n\n/**\n * EIP-712 type definition for `Permit`. Stable across every EIP-2612\n * implementation (USDC, EURC, DAI v2, etc.).\n */\nexport const PERMIT_TYPES = {\n Permit: [\n { name: 'owner', type: 'address' },\n { name: 'spender', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n} as const\n\n/**\n * Build the typed-data structure for an EIP-2612 `Permit` signature.\n * Returns the canonical shape compatible with viem, ethers, Privy,\n * and Reown.\n */\nexport function buildPermitTypedData(params: PermitParams): Eip712TypedData<'Permit'> {\n return {\n domain: {\n name: params.tokenName,\n version: params.tokenVersion,\n chainId: params.chainId,\n verifyingContract: params.token,\n },\n types: PERMIT_TYPES,\n primaryType: 'Permit',\n message: {\n owner: params.owner,\n spender: params.spender,\n value: params.value,\n nonce: params.nonce,\n deadline: params.deadline,\n },\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/eip712/receive-with-authorization.ts","../src/eip712/permit.ts","../src/eip712/pay-intent.ts","../src/eip712/subscription-intent.ts"],"names":[],"mappings":";AA8CO,IAAM,gCAAA,GAAmC;AAAA,EAC9C,wBAAA,EAA0B;AAAA,IACxB,EAAE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AA,MACd,QAAQ,MAAA,CAAO,MAAA;AAAA,MACf,UAAU,MAAA,CAAO,QAAA;AAAA,MACjB,SAAS,MAAA,CAAO,OAAA;AAAA,MAChB,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,gBAAgB,MAAA,CAAO;AAAA;AACzB,GACF;AACF","file":"eip712.js","sourcesContent":["import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the EIP-3009 ReceiveWithAuthorization typed-data.\n *\n * - `chainId` is the EVM chain id (Arc Testnet = 5042002).\n * - `token` is the ERC-20 contract whose `receiveWithAuthorization` is\n * being invoked. Usually USDC at `0x36...` on Arc.\n * - `tokenName` and `tokenVersion` form the EIP-712 domain. Real USDC\n * on most chains uses `name=\"USD Coin\"` and `version=\"2\"`; tests\n * use whatever the mock token reports. Always read these from the\n * token contract at runtime to avoid drift.\n * - `from` is the payer. The wallet that produces the signature must\n * match this address.\n * - `to` is the recipient of the funds. For Strimz this is the\n * StrimzPayments contract address (the contract pulls funds into\n * itself, then forwards the fee and net split).\n * - `value` is the gross amount in token base units.\n * - `validAfter` / `validBefore` are unix-second timestamps bounding\n * the signature's validity. Strimz's default checkout window is\n * 5 minutes; integrators may widen this for usage-based billing.\n * - `nonce` is a single-use 32-byte value. Generate with crypto.randomBytes\n * (server) or crypto.getRandomValues (browser). The token contract\n * tracks `(authorizer, nonce) -> used` and rejects replays.\n */\nexport interface ReceiveWithAuthorizationParams {\n chainId: number\n token: `0x${string}`\n tokenName: string\n tokenVersion: string\n from: `0x${string}`\n to: `0x${string}`\n value: bigint\n validAfter: bigint\n validBefore: bigint\n nonce: `0x${string}`\n}\n\n/**\n * EIP-712 type definition for `ReceiveWithAuthorization`. Stable, and\n * shared by every EIP-3009 implementation (USDC, EURC, etc.).\n *\n * Exported so consumers can introspect or extend with sibling\n * primitive types (e.g. for x402 batched signing schemes that wrap\n * multiple authorizations in one signature).\n */\nexport const RECEIVE_WITH_AUTHORIZATION_TYPES = {\n ReceiveWithAuthorization: [\n { name: 'from', type: 'address' },\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'validAfter', type: 'uint256' },\n { name: 'validBefore', type: 'uint256' },\n { name: 'nonce', type: 'bytes32' },\n ],\n} as const\n\n/**\n * Build the typed-data structure for an EIP-3009\n * `ReceiveWithAuthorization` signature. Returns the canonical shape\n * compatible with viem, ethers, Privy, and Reown.\n *\n * Pass the result to `walletClient.signTypedData(typedData)` (viem)\n * or `signer._signTypedData(domain, types, message)` (ethers). The\n * SDK does not bind to a specific signer.\n */\nexport function buildReceiveWithAuthorizationTypedData(\n params: ReceiveWithAuthorizationParams,\n): Eip712TypedData<'ReceiveWithAuthorization'> {\n return {\n domain: {\n name: params.tokenName,\n version: params.tokenVersion,\n chainId: params.chainId,\n verifyingContract: params.token,\n },\n types: RECEIVE_WITH_AUTHORIZATION_TYPES,\n primaryType: 'ReceiveWithAuthorization',\n message: {\n from: params.from,\n to: params.to,\n value: params.value,\n validAfter: params.validAfter,\n validBefore: params.validBefore,\n nonce: params.nonce,\n },\n }\n}\n","import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the EIP-2612 Permit typed-data.\n *\n * - `chainId`, `token`, `tokenName`, `tokenVersion` form the EIP-712\n * domain (same shape as the EIP-3009 builder).\n * - `owner` is the token holder authorising the allowance. Must match\n * the signing wallet.\n * - `spender` is the contract that will pull funds. For Strimz\n * subscriptions this is the StrimzSubscriptions contract.\n * - `value` is the allowance to grant in token base units.\n * `type(uint256).max` produces an unlimited allowance and is the\n * common case for subscription enrolment.\n * - `nonce` is the owner's *current* `nonces(owner)` reading from the\n * token contract. The SDK does not fetch this. The caller is\n * expected to have just queried it. Race-free: the token rejects\n * stale nonces, so a concurrent permit on the same owner causes one\n * to fail predictably.\n * - `deadline` is the unix-second timestamp after which the permit\n * expires. Strimz default for subscription enrolment is 24h. Enough\n * headroom for a slow merchant submit pipeline without leaving an\n * indefinite signature window.\n */\nexport interface PermitParams {\n chainId: number\n token: `0x${string}`\n tokenName: string\n tokenVersion: string\n owner: `0x${string}`\n spender: `0x${string}`\n value: bigint\n nonce: bigint\n deadline: bigint\n}\n\n/**\n * EIP-712 type definition for `Permit`. Stable across every EIP-2612\n * implementation (USDC, EURC, DAI v2, etc.).\n */\nexport const PERMIT_TYPES = {\n Permit: [\n { name: 'owner', type: 'address' },\n { name: 'spender', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'nonce', type: 'uint256' },\n { name: 'deadline', type: 'uint256' },\n ],\n} as const\n\n/**\n * Build the typed-data structure for an EIP-2612 `Permit` signature.\n * Returns the canonical shape compatible with viem, ethers, Privy,\n * and Reown.\n */\nexport function buildPermitTypedData(params: PermitParams): Eip712TypedData<'Permit'> {\n return {\n domain: {\n name: params.tokenName,\n version: params.tokenVersion,\n chainId: params.chainId,\n verifyingContract: params.token,\n },\n types: PERMIT_TYPES,\n primaryType: 'Permit',\n message: {\n owner: params.owner,\n spender: params.spender,\n value: params.value,\n nonce: params.nonce,\n deadline: params.deadline,\n },\n }\n}\n","import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the Strimz PayIntent. Payer signs this alongside the\n * EIP-3009 auth. Without it, a valid auth sig can be redirected to\n * pay a different merchant.\n *\n * Every field must match the corresponding argument the API will\n * submit on-chain — the contract compares them via ecrecover.\n */\nexport interface PayIntentParams {\n chainId: number\n verifyingContract: `0x${string}`\n merchantId: bigint\n token: `0x${string}`\n amount: bigint\n nonce: `0x${string}`\n validBefore: bigint\n ref: `0x${string}`\n}\n\n/** Field order matches `PAY_INTENT_TYPEHASH` in `StrimzPayments.sol`. */\nexport const PAY_INTENT_TYPES = {\n PayIntent: [\n { name: 'merchantId', type: 'uint256' },\n { name: 'token', type: 'address' },\n { name: 'amount', type: 'uint256' },\n { name: 'nonce', type: 'bytes32' },\n { name: 'validBefore', type: 'uint256' },\n { name: 'ref', type: 'bytes32' },\n ],\n} as const\n\n/** Domain name + version mirror `EIP712(\"StrimzPayments\", \"1\")`. */\nexport function buildPayIntentTypedData(params: PayIntentParams): Eip712TypedData<'PayIntent'> {\n return {\n domain: {\n name: 'StrimzPayments',\n version: '1',\n chainId: params.chainId,\n verifyingContract: params.verifyingContract,\n },\n types: PAY_INTENT_TYPES,\n primaryType: 'PayIntent',\n message: {\n merchantId: params.merchantId,\n token: params.token,\n amount: params.amount,\n nonce: params.nonce,\n validBefore: params.validBefore,\n ref: params.ref,\n },\n }\n}\n","import type { Eip712TypedData } from './types.js'\n\n/**\n * Inputs for the Strimz SubscriptionIntent. Payer signs this\n * alongside the ERC-2612 permit. Without it, a valid permit can be\n * used to enrol the payer in a plan they never picked.\n *\n * `permitDeadline` ties this intent to the accompanying permit —\n * they expire together.\n */\nexport interface SubscriptionIntentParams {\n chainId: number\n verifyingContract: `0x${string}`\n merchantId: bigint\n token: `0x${string}`\n amount: bigint\n interval: number\n startAt: bigint\n endAt: bigint\n permitDeadline: bigint\n}\n\n/** Field order matches `SUBSCRIPTION_INTENT_TYPEHASH` in the contract. */\nexport const SUBSCRIPTION_INTENT_TYPES = {\n SubscriptionIntent: [\n { name: 'merchantId', type: 'uint256' },\n { name: 'token', type: 'address' },\n { name: 'amount', type: 'uint256' },\n { name: 'interval', type: 'uint32' },\n { name: 'startAt', type: 'uint64' },\n { name: 'endAt', type: 'uint64' },\n { name: 'permitDeadline', type: 'uint256' },\n ],\n} as const\n\n/** Domain mirrors `EIP712(\"StrimzSubscriptions\", \"1\")`. */\nexport function buildSubscriptionIntentTypedData(\n params: SubscriptionIntentParams,\n): Eip712TypedData<'SubscriptionIntent'> {\n return {\n domain: {\n name: 'StrimzSubscriptions',\n version: '1',\n chainId: params.chainId,\n verifyingContract: params.verifyingContract,\n },\n types: SUBSCRIPTION_INTENT_TYPES,\n primaryType: 'SubscriptionIntent',\n message: {\n merchantId: params.merchantId,\n token: params.token,\n amount: params.amount,\n interval: params.interval,\n startAt: params.startAt,\n endAt: params.endAt,\n permitDeadline: params.permitDeadline,\n },\n }\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -216,10 +216,18 @@ var Fetcher = class {
|
|
|
216
216
|
}
|
|
217
217
|
backoffFor(attempt) {
|
|
218
218
|
const expo = this.initialBackoffMs * Math.pow(2, attempt);
|
|
219
|
-
|
|
220
|
-
return Math.min(expo + jitter, 8e3);
|
|
219
|
+
return Math.min(expo + cryptoJitter(this.initialBackoffMs), 8e3);
|
|
221
220
|
}
|
|
222
221
|
};
|
|
222
|
+
function cryptoJitter(maxMs) {
|
|
223
|
+
const g = globalThis;
|
|
224
|
+
if (g.crypto?.getRandomValues) {
|
|
225
|
+
const buf = new Uint32Array(1);
|
|
226
|
+
g.crypto.getRandomValues(buf);
|
|
227
|
+
return (buf[0] ?? 0) / 4294967295 * maxMs;
|
|
228
|
+
}
|
|
229
|
+
return Math.random() * maxMs;
|
|
230
|
+
}
|
|
223
231
|
function isIdempotent(spec) {
|
|
224
232
|
if (spec.method === "GET" || spec.method === "DELETE") return true;
|
|
225
233
|
return spec.idempotencyKey != null;
|
|
@@ -227,16 +235,29 @@ function isIdempotent(spec) {
|
|
|
227
235
|
async function parseErrorBody(res) {
|
|
228
236
|
try {
|
|
229
237
|
const json = await res.json();
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (typeof json === "object" && json !== null && "code" in json && "message" in json) {
|
|
234
|
-
return json;
|
|
238
|
+
const raw = typeof json === "object" && json !== null && "error" in json ? json.error : json;
|
|
239
|
+
if (typeof raw === "object" && raw !== null && "code" in raw && "message" in raw) {
|
|
240
|
+
return sanitiseErrorBody(raw);
|
|
235
241
|
}
|
|
236
242
|
} catch {
|
|
237
243
|
}
|
|
238
244
|
return { code: "api_error", message: `HTTP ${res.status}` };
|
|
239
245
|
}
|
|
246
|
+
var ALLOWED_DETAIL_KEYS = /* @__PURE__ */ new Set(["issues", "field", "reason", "chargeAttemptId"]);
|
|
247
|
+
function sanitiseErrorBody(raw) {
|
|
248
|
+
const details = typeof raw.details === "object" && raw.details !== null ? Object.fromEntries(
|
|
249
|
+
Object.entries(raw.details).filter(
|
|
250
|
+
([k]) => ALLOWED_DETAIL_KEYS.has(k)
|
|
251
|
+
)
|
|
252
|
+
) : void 0;
|
|
253
|
+
return {
|
|
254
|
+
code: typeof raw.code === "string" ? raw.code : "api_error",
|
|
255
|
+
message: typeof raw.message === "string" ? raw.message : "Request failed",
|
|
256
|
+
param: typeof raw.param === "string" ? raw.param : void 0,
|
|
257
|
+
requestId: typeof raw.requestId === "string" ? raw.requestId : void 0,
|
|
258
|
+
details: details && Object.keys(details).length > 0 ? details : void 0
|
|
259
|
+
};
|
|
260
|
+
}
|
|
240
261
|
function parseRetryAfter(res) {
|
|
241
262
|
const v = res.headers.get("Retry-After");
|
|
242
263
|
if (!v) return void 0;
|
|
@@ -728,6 +749,10 @@ var CheckoutResource = class extends BaseResource {
|
|
|
728
749
|
plan(id) {
|
|
729
750
|
return this.get(`/v1/checkout/plans/${encodeURIComponent(id)}`, sharedTypes.subscriptionPlanSchema);
|
|
730
751
|
}
|
|
752
|
+
/** Load the merchant's public brand card by id. */
|
|
753
|
+
merchant(id) {
|
|
754
|
+
return this.get(`/v1/checkout/merchants/${encodeURIComponent(id)}`, sharedTypes.merchantPublicBrandSchema);
|
|
755
|
+
}
|
|
731
756
|
};
|
|
732
757
|
var TokensResource = class extends BaseResource {
|
|
733
758
|
/**
|