@heraldprotocol/mpp 0.0.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 +116 -0
- package/dist/cjs/client.cjs +242 -0
- package/dist/cjs/client.cjs.map +1 -0
- package/dist/cjs/client.d.cts +112 -0
- package/dist/cjs/index.cjs +71 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +54 -0
- package/dist/cjs/server.cjs +397 -0
- package/dist/cjs/server.cjs.map +1 -0
- package/dist/cjs/server.d.cts +84 -0
- package/dist/cjs/types-CKXzdGiJ.d.cts +3 -0
- package/dist/esm/chunk-CRRGQQSN.js +45 -0
- package/dist/esm/chunk-CRRGQQSN.js.map +1 -0
- package/dist/esm/chunk-XBFBAAXJ.js +87 -0
- package/dist/esm/chunk-XBFBAAXJ.js.map +1 -0
- package/dist/esm/client.d.ts +112 -0
- package/dist/esm/client.js +150 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/index.d.ts +54 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/server.d.ts +84 -0
- package/dist/esm/server.js +260 -0
- package/dist/esm/server.js.map +1 -0
- package/dist/esm/types-CKXzdGiJ.d.ts +3 -0
- package/package.json +61 -0
- package/src/Methods.ts +43 -0
- package/src/client/Charge.ts +195 -0
- package/src/client/Methods.ts +29 -0
- package/src/client/index.ts +2 -0
- package/src/defaults.ts +100 -0
- package/src/index.ts +1 -0
- package/src/server/Charge.ts +382 -0
- package/src/server/Methods.ts +29 -0
- package/src/server/index.ts +2 -0
- package/src/types.ts +1 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// src/defaults.ts
|
|
2
|
+
var chainId = {
|
|
3
|
+
mainnet: 16661,
|
|
4
|
+
testnet: 16602
|
|
5
|
+
};
|
|
6
|
+
var USDC_E = "0x1f3aa82227281ca364bfb3d253b0f1af1da6473e";
|
|
7
|
+
var currency = {
|
|
8
|
+
[chainId.mainnet]: USDC_E
|
|
9
|
+
};
|
|
10
|
+
var decimals = 6;
|
|
11
|
+
var rpcUrl = {
|
|
12
|
+
[chainId.mainnet]: "https://evmrpc.0g.ai",
|
|
13
|
+
[chainId.testnet]: "https://evmrpc-testnet.0g.ai"
|
|
14
|
+
};
|
|
15
|
+
var erc3009Abi = [
|
|
16
|
+
{
|
|
17
|
+
type: "function",
|
|
18
|
+
name: "transferWithAuthorization",
|
|
19
|
+
inputs: [
|
|
20
|
+
{ name: "from", type: "address" },
|
|
21
|
+
{ name: "to", type: "address" },
|
|
22
|
+
{ name: "value", type: "uint256" },
|
|
23
|
+
{ name: "validAfter", type: "uint256" },
|
|
24
|
+
{ name: "validBefore", type: "uint256" },
|
|
25
|
+
{ name: "nonce", type: "bytes32" },
|
|
26
|
+
{ name: "v", type: "uint8" },
|
|
27
|
+
{ name: "r", type: "bytes32" },
|
|
28
|
+
{ name: "s", type: "bytes32" }
|
|
29
|
+
],
|
|
30
|
+
outputs: [],
|
|
31
|
+
stateMutability: "nonpayable"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: "function",
|
|
35
|
+
name: "receiveWithAuthorization",
|
|
36
|
+
inputs: [
|
|
37
|
+
{ name: "from", type: "address" },
|
|
38
|
+
{ name: "to", type: "address" },
|
|
39
|
+
{ name: "value", type: "uint256" },
|
|
40
|
+
{ name: "validAfter", type: "uint256" },
|
|
41
|
+
{ name: "validBefore", type: "uint256" },
|
|
42
|
+
{ name: "nonce", type: "bytes32" },
|
|
43
|
+
{ name: "v", type: "uint8" },
|
|
44
|
+
{ name: "r", type: "bytes32" },
|
|
45
|
+
{ name: "s", type: "bytes32" }
|
|
46
|
+
],
|
|
47
|
+
outputs: [],
|
|
48
|
+
stateMutability: "nonpayable"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: "function",
|
|
52
|
+
name: "name",
|
|
53
|
+
inputs: [],
|
|
54
|
+
outputs: [{ name: "", type: "string" }],
|
|
55
|
+
stateMutability: "view"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: "function",
|
|
59
|
+
name: "version",
|
|
60
|
+
inputs: [],
|
|
61
|
+
outputs: [{ name: "", type: "string" }],
|
|
62
|
+
stateMutability: "view"
|
|
63
|
+
}
|
|
64
|
+
];
|
|
65
|
+
var erc3009Tokens = {
|
|
66
|
+
[USDC_E.toLowerCase()]: {
|
|
67
|
+
name: "Bridged USDC",
|
|
68
|
+
version: "2"
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
function resolveCurrency(parameters) {
|
|
72
|
+
const id = parameters.chainId ?? (parameters.testnet ? chainId.testnet : chainId.mainnet);
|
|
73
|
+
const resolved = currency[id];
|
|
74
|
+
if (!resolved)
|
|
75
|
+
throw new Error(`No default currency configured for chainId ${id}.`);
|
|
76
|
+
return resolved;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export {
|
|
80
|
+
chainId,
|
|
81
|
+
decimals,
|
|
82
|
+
rpcUrl,
|
|
83
|
+
erc3009Abi,
|
|
84
|
+
erc3009Tokens,
|
|
85
|
+
resolveCurrency
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=chunk-XBFBAAXJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/defaults.ts"],"sourcesContent":["export const chainId = {\n mainnet: 16661,\n testnet: 16602,\n} as const;\n\nexport type ChainId = (typeof chainId)[keyof typeof chainId];\n\nconst USDC_E = \"0x1f3aa82227281ca364bfb3d253b0f1af1da6473e\";\n\n/** Chain ID → default currency. */\nexport const currency: Partial<Record<ChainId, string>> = {\n [chainId.mainnet]: USDC_E,\n};\n\n/** Default token decimals for USDC.e. */\nexport const decimals = 6;\n\n/** Default RPC URLs per chain. */\nexport const rpcUrl: Record<number, string> = {\n [chainId.mainnet]: \"https://evmrpc.0g.ai\",\n [chainId.testnet]: \"https://evmrpc-testnet.0g.ai\",\n};\n\n/** ERC-3009 ABI (`transferWithAuthorization`, `receiveWithAuthorization`). */\nexport const erc3009Abi = [\n {\n type: \"function\",\n name: \"transferWithAuthorization\",\n inputs: [\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 { name: \"v\", type: \"uint8\" },\n { name: \"r\", type: \"bytes32\" },\n { name: \"s\", type: \"bytes32\" },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"receiveWithAuthorization\",\n inputs: [\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 { name: \"v\", type: \"uint8\" },\n { name: \"r\", type: \"bytes32\" },\n { name: \"s\", type: \"bytes32\" },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"name\",\n inputs: [],\n outputs: [{ name: \"\", type: \"string\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"version\",\n inputs: [],\n outputs: [{ name: \"\", type: \"string\" }],\n stateMutability: \"view\",\n },\n] as const;\n\n/**\n * Known tokens that support ERC-3009 (TransferWithAuthorization).\n * Keyed by lowercase address for case-insensitive lookup.\n */\nexport const erc3009Tokens: Record<string, { name: string; version: string }> =\n {\n [USDC_E.toLowerCase()]: {\n name: \"Bridged USDC\",\n version: \"2\",\n },\n };\n\n/** Resolves the default currency for a given chain. */\nexport function resolveCurrency(parameters: {\n chainId?: number | undefined;\n testnet?: boolean | undefined;\n}): string {\n const id =\n parameters.chainId ??\n (parameters.testnet ? chainId.testnet : chainId.mainnet);\n const resolved = currency[id as ChainId];\n if (!resolved)\n throw new Error(`No default currency configured for chainId ${id}.`);\n return resolved;\n}\n"],"m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AAM,UAAU;AAAA,IAC/B;AAAA,IACA,SAAS,CAAC;AAAA,IACV,iBAAiB;AAAA,EACnB;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,QAAQ,CAAC;AAAA,IACT,SAAS,CAAC,EAAE,MAAM,IAAI,MAAM,SAAS,CAAC;AAAA,IACtC,iBAAiB;AAAA,EACnB;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,QAAQ,CAAC;AAAA,IACT,SAAS,CAAC,EAAE,MAAM,IAAI,MAAM,SAAS,CAAC;AAAA,IACtC,iBAAiB;AAAA,EACnB;AACF;AAMO,IAAM,gBACX;AAAA,EACE,CAAC,OAAO,YAAY,CAAC,GAAG;AAAA,IACtB,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AACF;AAGK,SAAS,gBAAgB,YAGrB;AACT,QAAM,KACJ,WAAW,YACV,WAAW,UAAU,QAAQ,UAAU,QAAQ;AAClD,QAAM,WAAW,SAAS,EAAa;AACvC,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,8CAA8C,EAAE,GAAG;AACrE,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Account, Address, Client } from 'viem';
|
|
2
|
+
import { Method, z } from 'mppx';
|
|
3
|
+
import { M as MaybePromise } from './types-CKXzdGiJ.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a 0G charge method intent for usage on the client.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { zerog } from "@heraldprotocol/mpp/client";
|
|
11
|
+
* import { privateKeyToAccount } from "viem/accounts";
|
|
12
|
+
*
|
|
13
|
+
* const charge = zerog.charge({
|
|
14
|
+
* account: privateKeyToAccount("0x..."),
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare function charge(parameters?: charge.Parameters): Method.Client<{
|
|
19
|
+
readonly name: "zerog";
|
|
20
|
+
readonly intent: "charge";
|
|
21
|
+
readonly schema: {
|
|
22
|
+
readonly credential: {
|
|
23
|
+
readonly payload: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
|
|
24
|
+
hash: z.ZodMiniString<string>;
|
|
25
|
+
type: z.ZodMiniLiteral<"hash">;
|
|
26
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
27
|
+
type: z.ZodMiniLiteral<"authorization">;
|
|
28
|
+
from: z.ZodMiniString<string>;
|
|
29
|
+
to: z.ZodMiniString<string>;
|
|
30
|
+
value: z.ZodMiniString<string>;
|
|
31
|
+
validAfter: z.ZodMiniString<string>;
|
|
32
|
+
validBefore: z.ZodMiniString<string>;
|
|
33
|
+
nonce: z.ZodMiniString<string>;
|
|
34
|
+
signature: z.ZodMiniString<string>;
|
|
35
|
+
}, z.core.$strip>], "type">;
|
|
36
|
+
};
|
|
37
|
+
readonly request: z.ZodMiniPipe<z.ZodMiniObject<{
|
|
38
|
+
amount: z.ZodMiniString<string>;
|
|
39
|
+
chainId: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
40
|
+
currency: z.ZodMiniString<string>;
|
|
41
|
+
decimals: z.ZodMiniNumber<number>;
|
|
42
|
+
description: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
43
|
+
externalId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
44
|
+
recipient: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
45
|
+
}, z.core.$strip>, z.ZodMiniTransform<{
|
|
46
|
+
methodDetails?: {
|
|
47
|
+
chainId: number;
|
|
48
|
+
} | undefined;
|
|
49
|
+
amount: string;
|
|
50
|
+
currency: string;
|
|
51
|
+
description?: string | undefined;
|
|
52
|
+
externalId?: string | undefined;
|
|
53
|
+
recipient?: string | undefined;
|
|
54
|
+
}, {
|
|
55
|
+
amount: string;
|
|
56
|
+
currency: string;
|
|
57
|
+
decimals: number;
|
|
58
|
+
chainId?: number | undefined;
|
|
59
|
+
description?: string | undefined;
|
|
60
|
+
externalId?: string | undefined;
|
|
61
|
+
recipient?: string | undefined;
|
|
62
|
+
}>>;
|
|
63
|
+
};
|
|
64
|
+
}, z.ZodMiniObject<{
|
|
65
|
+
account: z.ZodMiniOptional<z.ZodMiniCustom<`0x${string}` | Account, `0x${string}` | Account>>;
|
|
66
|
+
mode: z.ZodMiniOptional<z.ZodMiniEnum<{
|
|
67
|
+
push: "push";
|
|
68
|
+
pull: "pull";
|
|
69
|
+
}>>;
|
|
70
|
+
}, z.core.$strip>>;
|
|
71
|
+
declare namespace charge {
|
|
72
|
+
type Parameters = {
|
|
73
|
+
/** Account to use for signing. */
|
|
74
|
+
account?: Account | Address | undefined;
|
|
75
|
+
/** Function that returns a viem Client for the given chain ID. */
|
|
76
|
+
getClient?: ((parameters: {
|
|
77
|
+
chainId?: number | undefined;
|
|
78
|
+
}) => MaybePromise<Client>) | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Controls how the charge transaction is submitted.
|
|
81
|
+
*
|
|
82
|
+
* - `'push'`: Client broadcasts the transaction and sends the tx hash.
|
|
83
|
+
* - `'pull'`: Client signs an ERC-3009 TransferWithAuthorization
|
|
84
|
+
* message. Server calls `transferWithAuthorization` and pays gas.
|
|
85
|
+
*
|
|
86
|
+
* @default `'push'` for JSON-RPC accounts, `'pull'` for local accounts.
|
|
87
|
+
*/
|
|
88
|
+
mode?: "push" | "pull" | undefined;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Creates a 0G `charge` client method.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { Mppx } from "mppx/client";
|
|
98
|
+
* import { zerog } from "@heraldprotocol/mpp/client";
|
|
99
|
+
*
|
|
100
|
+
* const mppx = Mppx.create({
|
|
101
|
+
* methods: [zerog({ account })],
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare function zerog(parameters?: zerog.Parameters): readonly [Method.AnyClient];
|
|
106
|
+
declare namespace zerog {
|
|
107
|
+
type Parameters = charge.Parameters;
|
|
108
|
+
/** Creates a 0G `charge` client method for one-time ERC-20 token transfers. */
|
|
109
|
+
const charge: typeof charge;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { charge, zerog };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
chainId,
|
|
3
|
+
erc3009Tokens,
|
|
4
|
+
rpcUrl
|
|
5
|
+
} from "./chunk-XBFBAAXJ.js";
|
|
6
|
+
import {
|
|
7
|
+
charge
|
|
8
|
+
} from "./chunk-CRRGQQSN.js";
|
|
9
|
+
|
|
10
|
+
// src/client/Charge.ts
|
|
11
|
+
import { Credential, Method, z } from "mppx";
|
|
12
|
+
import { encodeFunctionData, erc20Abi } from "viem";
|
|
13
|
+
import { parseAccount } from "viem/accounts";
|
|
14
|
+
import { sendTransactionSync, signTypedData } from "viem/actions";
|
|
15
|
+
function charge2(parameters = {}) {
|
|
16
|
+
const resolveAccount = (client, override) => {
|
|
17
|
+
const raw = override ?? parameters.account;
|
|
18
|
+
if (raw) return typeof raw === "string" ? parseAccount(raw) : raw;
|
|
19
|
+
if (client.account) return client.account;
|
|
20
|
+
throw new Error(
|
|
21
|
+
"No `account` provided. Pass `account` to parameters or context."
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
const resolveClient = async (chainId2) => {
|
|
25
|
+
if (parameters.getClient) return parameters.getClient({ chainId: chainId2 });
|
|
26
|
+
const id = chainId2 ?? chainId.mainnet;
|
|
27
|
+
const url = rpcUrl[id];
|
|
28
|
+
if (!url) throw new Error(`No RPC URL configured for chainId ${id}.`);
|
|
29
|
+
const { createClient, http } = await import("viem");
|
|
30
|
+
return createClient({ chain: { id }, transport: http(url) });
|
|
31
|
+
};
|
|
32
|
+
return Method.toClient(charge, {
|
|
33
|
+
context: z.object({
|
|
34
|
+
account: z.optional(z.custom()),
|
|
35
|
+
mode: z.optional(z.enum(["push", "pull"]))
|
|
36
|
+
}),
|
|
37
|
+
async createCredential({ challenge, context }) {
|
|
38
|
+
const chainId2 = challenge.request.methodDetails?.chainId;
|
|
39
|
+
const client = await resolveClient(chainId2);
|
|
40
|
+
const account = resolveAccount(client, context?.account);
|
|
41
|
+
const mode = context?.mode ?? parameters.mode ?? (account.type === "json-rpc" ? "push" : "pull");
|
|
42
|
+
const { request } = challenge;
|
|
43
|
+
const amount = BigInt(request.amount);
|
|
44
|
+
const currency = request.currency;
|
|
45
|
+
const recipient = request.recipient;
|
|
46
|
+
if (mode === "pull") {
|
|
47
|
+
const tokenMeta = erc3009Tokens[currency.toLowerCase()];
|
|
48
|
+
if (!tokenMeta) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Token ${currency} does not support ERC-3009 (TransferWithAuthorization). Cannot use pull mode.`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
const resolvedChainId = chainId2 ?? client.chain?.id;
|
|
54
|
+
if (!resolvedChainId)
|
|
55
|
+
throw new Error("Could not determine chainId for EIP-712 domain.");
|
|
56
|
+
const { name: tokenName, version: tokenVersion } = tokenMeta;
|
|
57
|
+
const validAfter = 0n;
|
|
58
|
+
const validBefore = challenge.expires ? BigInt(Math.floor(new Date(challenge.expires).getTime() / 1e3)) : BigInt(Math.floor(Date.now() / 1e3) + 3600);
|
|
59
|
+
const nonce = randomNonce();
|
|
60
|
+
const signature = await signTypedData(client, {
|
|
61
|
+
account,
|
|
62
|
+
domain: {
|
|
63
|
+
name: tokenName,
|
|
64
|
+
version: tokenVersion,
|
|
65
|
+
chainId: resolvedChainId,
|
|
66
|
+
verifyingContract: currency
|
|
67
|
+
},
|
|
68
|
+
types: {
|
|
69
|
+
TransferWithAuthorization: [
|
|
70
|
+
{ name: "from", type: "address" },
|
|
71
|
+
{ name: "to", type: "address" },
|
|
72
|
+
{ name: "value", type: "uint256" },
|
|
73
|
+
{ name: "validAfter", type: "uint256" },
|
|
74
|
+
{ name: "validBefore", type: "uint256" },
|
|
75
|
+
{ name: "nonce", type: "bytes32" }
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
primaryType: "TransferWithAuthorization",
|
|
79
|
+
message: {
|
|
80
|
+
from: account.address,
|
|
81
|
+
to: recipient,
|
|
82
|
+
value: amount,
|
|
83
|
+
validAfter,
|
|
84
|
+
validBefore,
|
|
85
|
+
nonce
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return Credential.serialize({
|
|
89
|
+
challenge,
|
|
90
|
+
payload: {
|
|
91
|
+
type: "authorization",
|
|
92
|
+
from: account.address,
|
|
93
|
+
to: recipient,
|
|
94
|
+
value: amount.toString(),
|
|
95
|
+
validAfter: validAfter.toString(),
|
|
96
|
+
validBefore: validBefore.toString(),
|
|
97
|
+
nonce,
|
|
98
|
+
signature
|
|
99
|
+
},
|
|
100
|
+
source: `did:pkh:eip155:${resolvedChainId}:${account.address}`
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (mode === "push") {
|
|
104
|
+
const receipt = await sendTransactionSync(client, {
|
|
105
|
+
account,
|
|
106
|
+
chain: client.chain,
|
|
107
|
+
to: currency,
|
|
108
|
+
data: encodeFunctionData({
|
|
109
|
+
abi: erc20Abi,
|
|
110
|
+
functionName: "transfer",
|
|
111
|
+
args: [recipient, amount]
|
|
112
|
+
})
|
|
113
|
+
});
|
|
114
|
+
const hash = receipt.transactionHash;
|
|
115
|
+
return Credential.serialize({
|
|
116
|
+
challenge,
|
|
117
|
+
payload: { hash, type: "hash" },
|
|
118
|
+
source: `did:pkh:eip155:${chainId2 ?? client.chain?.id}:${account.address}`
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
throw new Error(`Unsupported mode: ${mode}`);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function randomNonce() {
|
|
126
|
+
const bytes = new Uint8Array(32);
|
|
127
|
+
if (typeof crypto !== "undefined") {
|
|
128
|
+
crypto.getRandomValues(bytes);
|
|
129
|
+
} else if (typeof globalThis !== "undefined" && "crypto" in globalThis) {
|
|
130
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
131
|
+
} else {
|
|
132
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
133
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return `0x${[...bytes].map((b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/client/Methods.ts
|
|
140
|
+
function zerog(parameters = {}) {
|
|
141
|
+
return [charge2(parameters)];
|
|
142
|
+
}
|
|
143
|
+
((zerog2) => {
|
|
144
|
+
zerog2.charge = charge2;
|
|
145
|
+
})(zerog || (zerog = {}));
|
|
146
|
+
export {
|
|
147
|
+
charge2 as charge,
|
|
148
|
+
zerog
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/Charge.ts","../../src/client/Methods.ts"],"sourcesContent":["import type { Account, Address, Chain, Client } from \"viem\";\nimport { Credential, Method, z } from \"mppx\";\nimport { encodeFunctionData, erc20Abi } from \"viem\";\nimport { parseAccount } from \"viem/accounts\";\nimport { sendTransactionSync, signTypedData } from \"viem/actions\";\n\nimport type { MaybePromise } from \"../types.js\";\nimport * as defaults from \"../defaults.js\";\nimport * as Methods from \"../Methods.js\";\n\n/**\n * Creates a 0G charge method intent for usage on the client.\n *\n * @example\n * ```ts\n * import { zerog } from \"@heraldprotocol/mpp/client\";\n * import { privateKeyToAccount } from \"viem/accounts\";\n *\n * const charge = zerog.charge({\n * account: privateKeyToAccount(\"0x...\"),\n * });\n * ```\n */\nexport function charge(parameters: charge.Parameters = {}) {\n const resolveAccount = (\n client: Client,\n override?: Account | Address | undefined\n ): Account => {\n const raw = override ?? parameters.account;\n if (raw) return typeof raw === \"string\" ? parseAccount(raw) : raw;\n if (client.account) return client.account;\n throw new Error(\n \"No `account` provided. Pass `account` to parameters or context.\"\n );\n };\n\n const resolveClient = async (\n chainId?: number | undefined\n ): Promise<Client> => {\n if (parameters.getClient) return parameters.getClient({ chainId });\n const id = chainId ?? defaults.chainId.mainnet;\n const url = defaults.rpcUrl[id];\n if (!url) throw new Error(`No RPC URL configured for chainId ${id}.`);\n const { createClient, http } = await import(\"viem\");\n return createClient({ chain: { id } as Chain, transport: http(url) });\n };\n\n return Method.toClient(Methods.charge, {\n context: z.object({\n account: z.optional(z.custom<Account | Address>()),\n mode: z.optional(z.enum([\"push\", \"pull\"])),\n }),\n\n async createCredential({ challenge, context }) {\n const chainId = challenge.request.methodDetails?.chainId as\n | number\n | undefined;\n const client = await resolveClient(chainId);\n const account = resolveAccount(client, context?.account);\n\n const mode =\n context?.mode ??\n parameters.mode ??\n (account.type === \"json-rpc\" ? \"push\" : \"pull\");\n\n const { request } = challenge;\n const amount = BigInt(request.amount);\n const currency = request.currency as Address;\n const recipient = request.recipient as Address;\n\n if (mode === \"pull\") {\n const tokenMeta = defaults.erc3009Tokens[currency.toLowerCase()];\n if (!tokenMeta) {\n throw new Error(\n `Token ${currency} does not support ERC-3009 (TransferWithAuthorization). ` +\n `Cannot use pull mode.`\n );\n }\n\n const resolvedChainId = chainId ?? client.chain?.id;\n if (!resolvedChainId)\n throw new Error(\"Could not determine chainId for EIP-712 domain.\");\n\n const { name: tokenName, version: tokenVersion } = tokenMeta;\n\n const validAfter = 0n;\n const validBefore = challenge.expires\n ? BigInt(Math.floor(new Date(challenge.expires).getTime() / 1000))\n : BigInt(Math.floor(Date.now() / 1000) + 3600); // 1 hour default\n const nonce = randomNonce();\n\n const signature = await signTypedData(client, {\n account,\n domain: {\n name: tokenName,\n version: tokenVersion,\n chainId: resolvedChainId,\n verifyingContract: currency,\n },\n types: {\n TransferWithAuthorization: [\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 },\n primaryType: \"TransferWithAuthorization\",\n message: {\n from: account.address,\n to: recipient,\n value: amount,\n validAfter,\n validBefore,\n nonce,\n },\n });\n\n return Credential.serialize({\n challenge,\n payload: {\n type: \"authorization\" as const,\n from: account.address,\n to: recipient,\n value: amount.toString(),\n validAfter: validAfter.toString(),\n validBefore: validBefore.toString(),\n nonce,\n signature,\n },\n source: `did:pkh:eip155:${resolvedChainId}:${account.address}`,\n });\n }\n\n if (mode === \"push\") {\n const receipt = await sendTransactionSync(client, {\n account,\n chain: client.chain,\n to: currency,\n data: encodeFunctionData({\n abi: erc20Abi,\n functionName: \"transfer\",\n args: [recipient, amount],\n }),\n });\n const hash = receipt.transactionHash;\n return Credential.serialize({\n challenge,\n payload: { hash, type: \"hash\" },\n source: `did:pkh:eip155:${chainId ?? client.chain?.id}:${account.address}`,\n });\n }\n\n throw new Error(`Unsupported mode: ${mode}`);\n },\n });\n}\n\nexport declare namespace charge {\n type Parameters = {\n /** Account to use for signing. */\n account?: Account | Address | undefined;\n /** Function that returns a viem Client for the given chain ID. */\n getClient?:\n | ((parameters: { chainId?: number | undefined }) => MaybePromise<Client>)\n | undefined;\n /**\n * Controls how the charge transaction is submitted.\n *\n * - `'push'`: Client broadcasts the transaction and sends the tx hash.\n * - `'pull'`: Client signs an ERC-3009 TransferWithAuthorization\n * message. Server calls `transferWithAuthorization` and pays gas.\n *\n * @default `'push'` for JSON-RPC accounts, `'pull'` for local accounts.\n */\n mode?: \"push\" | \"pull\" | undefined;\n };\n}\n\n/** Generates a random 32-byte hex nonce. */\nfunction randomNonce(): `0x${string}` {\n const bytes = new Uint8Array(32);\n if (typeof crypto !== \"undefined\") {\n crypto.getRandomValues(bytes);\n } else if (typeof globalThis !== \"undefined\" && \"crypto\" in globalThis) {\n (globalThis as unknown as { crypto: Crypto }).crypto.getRandomValues(bytes);\n } else {\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Math.floor(Math.random() * 256);\n }\n }\n return `0x${[...bytes].map((b) => b.toString(16).padStart(2, \"0\")).join(\"\")}`;\n}\n","import type { Method } from \"mppx\";\n\nimport { charge as charge_ } from \"./Charge.js\";\n\n/**\n * Creates a 0G `charge` client method.\n *\n * @example\n * ```ts\n * import { Mppx } from \"mppx/client\";\n * import { zerog } from \"@heraldprotocol/mpp/client\";\n *\n * const mppx = Mppx.create({\n * methods: [zerog({ account })],\n * });\n * ```\n */\nexport function zerog(\n parameters: zerog.Parameters = {}\n): readonly [Method.AnyClient] {\n return [charge_(parameters)] as const;\n}\n\nexport namespace zerog {\n export type Parameters = charge_.Parameters;\n\n /** Creates a 0G `charge` client method for one-time ERC-20 token transfers. */\n export const charge = charge_;\n}\n"],"mappings":";;;;;;;;;;AACA,SAAS,YAAY,QAAQ,SAAS;AACtC,SAAS,oBAAoB,gBAAgB;AAC7C,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB,qBAAqB;AAmB5C,SAASA,QAAO,aAAgC,CAAC,GAAG;AACzD,QAAM,iBAAiB,CACrB,QACA,aACY;AACZ,UAAM,MAAM,YAAY,WAAW;AACnC,QAAI,IAAK,QAAO,OAAO,QAAQ,WAAW,aAAa,GAAG,IAAI;AAC9D,QAAI,OAAO,QAAS,QAAO,OAAO;AAClC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,gBAAgB,OACpBC,aACoB;AACpB,QAAI,WAAW,UAAW,QAAO,WAAW,UAAU,EAAE,SAAAA,SAAQ,CAAC;AACjE,UAAM,KAAKA,YAAoB,QAAQ;AACvC,UAAM,MAAe,OAAO,EAAE;AAC9B,QAAI,CAAC,IAAK,OAAM,IAAI,MAAM,qCAAqC,EAAE,GAAG;AACpE,UAAM,EAAE,cAAc,KAAK,IAAI,MAAM,OAAO,MAAM;AAClD,WAAO,aAAa,EAAE,OAAO,EAAE,GAA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AE,IAAI,QAAQ,OAAO;AAAA,QAC1E,CAAC;AAAA,MACH;AAEA,YAAM,IAAI,MAAM,qBAAqB,IAAI,EAAE;AAAA,IAC7C;AAAA,EACF,CAAC;AACH;AAwBA,SAAS,cAA6B;AACpC,QAAM,QAAQ,IAAI,WAAW,EAAE;AAC/B,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO,gBAAgB,KAAK;AAAA,EAC9B,WAAW,OAAO,eAAe,eAAe,YAAY,YAAY;AACtE,IAAC,WAA6C,OAAO,gBAAgB,KAAK;AAAA,EAC5E,OAAO;AACL,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,YAAM,CAAC,IAAI,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG;AAAA,IAC3C;AAAA,EACF;AACA,SAAO,KAAK,CAAC,GAAG,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC;AAC7E;;;ACjLO,SAAS,MACd,aAA+B,CAAC,GACH;AAC7B,SAAO,CAACC,QAAQ,UAAU,CAAC;AAC7B;AAAA,CAEO,CAAUC,WAAV;AAIE,EAAMA,OAAA,SAASD;AAAA,GAJP;","names":["charge","chainId","charge","zerog"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from 'mppx';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 0G charge intent for one-time ERC-20 token transfers.
|
|
5
|
+
*/
|
|
6
|
+
declare const charge: {
|
|
7
|
+
readonly name: "zerog";
|
|
8
|
+
readonly intent: "charge";
|
|
9
|
+
readonly schema: {
|
|
10
|
+
readonly credential: {
|
|
11
|
+
readonly payload: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
|
|
12
|
+
hash: z.ZodMiniString<string>;
|
|
13
|
+
type: z.ZodMiniLiteral<"hash">;
|
|
14
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
15
|
+
type: z.ZodMiniLiteral<"authorization">;
|
|
16
|
+
from: z.ZodMiniString<string>;
|
|
17
|
+
to: z.ZodMiniString<string>;
|
|
18
|
+
value: z.ZodMiniString<string>;
|
|
19
|
+
validAfter: z.ZodMiniString<string>;
|
|
20
|
+
validBefore: z.ZodMiniString<string>;
|
|
21
|
+
nonce: z.ZodMiniString<string>;
|
|
22
|
+
signature: z.ZodMiniString<string>;
|
|
23
|
+
}, z.core.$strip>], "type">;
|
|
24
|
+
};
|
|
25
|
+
readonly request: z.ZodMiniPipe<z.ZodMiniObject<{
|
|
26
|
+
amount: z.ZodMiniString<string>;
|
|
27
|
+
chainId: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
28
|
+
currency: z.ZodMiniString<string>;
|
|
29
|
+
decimals: z.ZodMiniNumber<number>;
|
|
30
|
+
description: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
31
|
+
externalId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
32
|
+
recipient: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
33
|
+
}, z.core.$strip>, z.ZodMiniTransform<{
|
|
34
|
+
methodDetails?: {
|
|
35
|
+
chainId: number;
|
|
36
|
+
} | undefined;
|
|
37
|
+
amount: string;
|
|
38
|
+
currency: string;
|
|
39
|
+
description?: string | undefined;
|
|
40
|
+
externalId?: string | undefined;
|
|
41
|
+
recipient?: string | undefined;
|
|
42
|
+
}, {
|
|
43
|
+
amount: string;
|
|
44
|
+
currency: string;
|
|
45
|
+
decimals: number;
|
|
46
|
+
chainId?: number | undefined;
|
|
47
|
+
description?: string | undefined;
|
|
48
|
+
externalId?: string | undefined;
|
|
49
|
+
recipient?: string | undefined;
|
|
50
|
+
}>>;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { charge };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Client, Account, Address } from 'viem';
|
|
2
|
+
import { Method, Store } from 'mppx';
|
|
3
|
+
import { M as MaybePromise } from './types-CKXzdGiJ.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a 0G charge method intent for usage on the server.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { zerog } from "@heraldprotocol/mpp/server";
|
|
11
|
+
*
|
|
12
|
+
* const charge = zerog.charge({
|
|
13
|
+
* recipient: "0x...",
|
|
14
|
+
* currency: "0x...",
|
|
15
|
+
* account: privateKeyToAccount("0x..."),
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function charge(parameters?: charge.Parameters): Method.AnyServer;
|
|
20
|
+
declare namespace charge {
|
|
21
|
+
type StoreItemMap = {
|
|
22
|
+
[key: `mppx:charge:${string}`]: number;
|
|
23
|
+
};
|
|
24
|
+
type Parameters = {
|
|
25
|
+
/** Default payment amount (human-readable, e.g. "1.50"). */
|
|
26
|
+
amount?: string | undefined;
|
|
27
|
+
/** ERC-20 token contract address. */
|
|
28
|
+
currency?: string | undefined;
|
|
29
|
+
/** Token decimals. @default 6 */
|
|
30
|
+
decimals?: number | undefined;
|
|
31
|
+
/** Human-readable description. */
|
|
32
|
+
description?: string | undefined;
|
|
33
|
+
/** External identifier to echo back in receipt. */
|
|
34
|
+
externalId?: string | undefined;
|
|
35
|
+
/** Recipient address for payments. */
|
|
36
|
+
recipient?: string | undefined;
|
|
37
|
+
/** Testnet mode. */
|
|
38
|
+
testnet?: boolean | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Whether to wait for the charge transaction to confirm on-chain.
|
|
41
|
+
* @default true
|
|
42
|
+
*/
|
|
43
|
+
waitForConfirmation?: boolean | undefined;
|
|
44
|
+
/** Function that returns a viem Client for the given chain ID. */
|
|
45
|
+
getClient?: ((parameters: {
|
|
46
|
+
chainId?: number | undefined;
|
|
47
|
+
}) => MaybePromise<Client>) | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Server account used to broadcast `transferWithAuthorization` transactions.
|
|
50
|
+
* Required when accepting `authorization` payloads. The server pays gas
|
|
51
|
+
* from this account.
|
|
52
|
+
*/
|
|
53
|
+
account?: Account | Address | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Store for transaction hash replay protection.
|
|
56
|
+
*
|
|
57
|
+
* Use a shared store in multi-instance deployments so consumed hashes are
|
|
58
|
+
* visible across all server instances.
|
|
59
|
+
*/
|
|
60
|
+
store?: Store.Store | undefined;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Creates a 0G `charge` server method.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { Mppx } from "mppx/server";
|
|
70
|
+
* import { zerog } from "@heraldprotocol/mpp/server";
|
|
71
|
+
*
|
|
72
|
+
* const mppx = Mppx.create({
|
|
73
|
+
* methods: [zerog({ recipient: "0x...", currency: "0x..." })],
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function zerog(parameters?: zerog.Parameters): readonly [Method.AnyServer];
|
|
78
|
+
declare namespace zerog {
|
|
79
|
+
type Parameters = charge.Parameters;
|
|
80
|
+
/** Creates a 0G `charge` method for one-time ERC-20 token transfers. */
|
|
81
|
+
const charge: typeof charge;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { charge, zerog };
|