@opendatalabs/vana-sdk 3.4.1 → 3.5.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.
Files changed (33) hide show
  1. package/dist/account/personal-server-lite-owner-binding.cjs +3 -3
  2. package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -1
  3. package/dist/account/personal-server-lite-owner-binding.d.ts +2 -2
  4. package/dist/account/personal-server-lite-owner-binding.js +1 -1
  5. package/dist/account/personal-server-lite-owner-binding.js.map +1 -1
  6. package/dist/index.browser.d.ts +2 -1
  7. package/dist/index.browser.js +133 -6
  8. package/dist/index.browser.js.map +4 -4
  9. package/dist/index.node.cjs +138 -6
  10. package/dist/index.node.cjs.map +4 -4
  11. package/dist/index.node.d.ts +2 -1
  12. package/dist/index.node.js +133 -6
  13. package/dist/index.node.js.map +4 -4
  14. package/dist/{protocol/personal-server-lite-owner-binding.cjs → personal-server-lite/owner-binding.cjs} +5 -5
  15. package/dist/personal-server-lite/owner-binding.cjs.map +1 -0
  16. package/dist/{protocol/personal-server-lite-owner-binding.d.ts → personal-server-lite/owner-binding.d.ts} +3 -3
  17. package/dist/{protocol/personal-server-lite-owner-binding.js → personal-server-lite/owner-binding.js} +2 -2
  18. package/dist/personal-server-lite/owner-binding.js.map +1 -0
  19. package/dist/protocol/escrow.cjs +146 -0
  20. package/dist/protocol/escrow.cjs.map +1 -0
  21. package/dist/protocol/escrow.d.ts +336 -0
  22. package/dist/protocol/escrow.js +118 -0
  23. package/dist/protocol/escrow.js.map +1 -0
  24. package/dist/protocol/escrow.test.d.ts +1 -0
  25. package/dist/protocol/personal-server-registration.cjs +16 -4
  26. package/dist/protocol/personal-server-registration.cjs.map +1 -1
  27. package/dist/protocol/personal-server-registration.d.ts +5 -2
  28. package/dist/protocol/personal-server-registration.js +16 -4
  29. package/dist/protocol/personal-server-registration.js.map +1 -1
  30. package/package.json +1 -1
  31. package/dist/protocol/personal-server-lite-owner-binding.cjs.map +0 -1
  32. package/dist/protocol/personal-server-lite-owner-binding.js.map +0 -1
  33. /package/dist/{protocol/personal-server-lite-owner-binding.test.d.ts → personal-server-lite/owner-binding.test.d.ts} +0 -0
@@ -0,0 +1,118 @@
1
+ const GENERIC_PAYMENT_TYPES = {
2
+ GenericPayment: [
3
+ { name: "payerAddress", type: "address" },
4
+ { name: "opType", type: "string" },
5
+ { name: "opId", type: "bytes32" },
6
+ { name: "asset", type: "address" },
7
+ { name: "amount", type: "uint256" },
8
+ { name: "paymentNonce", type: "uint256" }
9
+ ]
10
+ };
11
+ function genericPaymentDomain(chainId, escrowContract) {
12
+ return {
13
+ name: "Vana Data Portability",
14
+ version: "1",
15
+ chainId,
16
+ verifyingContract: escrowContract
17
+ };
18
+ }
19
+ const ESCROW_DEPOSIT_ABI = [
20
+ {
21
+ type: "function",
22
+ name: "depositNative",
23
+ stateMutability: "payable",
24
+ inputs: [{ name: "account", type: "address" }],
25
+ outputs: []
26
+ },
27
+ {
28
+ type: "function",
29
+ name: "depositToken",
30
+ stateMutability: "nonpayable",
31
+ inputs: [
32
+ { name: "account", type: "address" },
33
+ { name: "token", type: "address" },
34
+ { name: "amount", type: "uint256" }
35
+ ],
36
+ outputs: []
37
+ }
38
+ ];
39
+ const NATIVE_ASSET_ADDRESS = "0x0000000000000000000000000000000000000000";
40
+ function createEscrowGatewayClient(baseUrl) {
41
+ const base = baseUrl.replace(/\/+$/, "");
42
+ async function throwOnError(res, context) {
43
+ if (!res.ok) {
44
+ let detail = "";
45
+ try {
46
+ const body = await res.json();
47
+ if (body.error) detail = `: ${body.error}`;
48
+ } catch {
49
+ }
50
+ throw new Error(
51
+ `Escrow gateway error (${context}): ${res.status} ${res.statusText}${detail}`
52
+ );
53
+ }
54
+ }
55
+ return {
56
+ async submitDeposit({ txHash }) {
57
+ const res = await fetch(`${base}/v1/escrow/deposit`, {
58
+ method: "POST",
59
+ headers: { "Content-Type": "application/json" },
60
+ body: JSON.stringify({ txHash })
61
+ });
62
+ if (res.status !== 200 && res.status !== 202) {
63
+ await throwOnError(res, "POST /v1/escrow/deposit");
64
+ }
65
+ return res.json();
66
+ },
67
+ async getEscrowBalance(account) {
68
+ const res = await fetch(
69
+ `${base}/v1/escrow/balance?account=${encodeURIComponent(account)}`
70
+ );
71
+ await throwOnError(res, "GET /v1/escrow/balance");
72
+ return res.json();
73
+ },
74
+ async syncEscrowBalance(account) {
75
+ const res = await fetch(
76
+ `${base}/v1/escrow/balance/sync?account=${encodeURIComponent(account)}`,
77
+ { method: "POST" }
78
+ );
79
+ await throwOnError(res, "POST /v1/escrow/balance/sync");
80
+ return res.json();
81
+ },
82
+ async payForOp({
83
+ payerAddress,
84
+ opType,
85
+ opId,
86
+ asset,
87
+ amount,
88
+ paymentNonce,
89
+ signature
90
+ }) {
91
+ const res = await fetch(`${base}/v1/escrow/pay`, {
92
+ method: "POST",
93
+ headers: {
94
+ "Content-Type": "application/json",
95
+ Authorization: `Web3Signed ${signature}`
96
+ },
97
+ body: JSON.stringify({
98
+ payerAddress,
99
+ opType,
100
+ opId,
101
+ asset,
102
+ amount,
103
+ paymentNonce
104
+ })
105
+ });
106
+ await throwOnError(res, "POST /v1/escrow/pay");
107
+ return res.json();
108
+ }
109
+ };
110
+ }
111
+ export {
112
+ ESCROW_DEPOSIT_ABI,
113
+ GENERIC_PAYMENT_TYPES,
114
+ NATIVE_ASSET_ADDRESS,
115
+ createEscrowGatewayClient,
116
+ genericPaymentDomain
117
+ };
118
+ //# sourceMappingURL=escrow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/protocol/escrow.ts"],"sourcesContent":["/**\n * DPv2 escrow payment helpers.\n *\n * Covers the three-phase flow used by builders to pay for data access:\n *\n * 1. **Deposit** — call `depositNative` or `depositToken` on the\n * DataPortabilityEscrow contract, then notify the gateway.\n * 2. **Balance** — read or force-sync the gateway's off-chain credit view.\n * 3. **Pay** — sign a `GenericPayment` EIP-712 message and POST it to the\n * gateway's `/v1/escrow/pay` endpoint.\n *\n * The gateway is the authority on balances; the on-chain contract is the\n * authority on what has been settled. Nothing in this module touches the\n * chain directly — signing is done by the caller's wallet.\n *\n * @category Protocol\n * @module escrow\n */\n\nimport type { TypedDataDomain } from \"viem\";\n\n// ---------------------------------------------------------------------------\n// EIP-712 — GenericPayment\n// ---------------------------------------------------------------------------\n\n/**\n * EIP-712 typed-data types for a generic op payment.\n *\n * The gateway verifies that the recovered signer == `payerAddress` and that\n * the (payer, paymentNonce) pair has not been seen before. Use a\n * monotonically-increasing nonce; the first payment for any payer should\n * start at 1.\n */\nexport const GENERIC_PAYMENT_TYPES = {\n GenericPayment: [\n { name: \"payerAddress\", type: \"address\" },\n { name: \"opType\", type: \"string\" },\n { name: \"opId\", type: \"bytes32\" },\n { name: \"asset\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n { name: \"paymentNonce\", type: \"uint256\" },\n ],\n} as const;\n\n/**\n * EIP-712 message payload for a generic op payment.\n *\n * - `opType` is currently `\"grant\"`. Additional types (file, builder, schema)\n * may be added in future protocol versions.\n * - `opId` is the bytes32 id of the operation being paid for (e.g. `grantId`).\n * - `asset` is the ERC-20 token address, or the zero address for native VANA.\n * - `amount` is the total amount in base units (wei for VANA). Must match the\n * sum the gateway expects for the current lifecycle of the op.\n * - `paymentNonce` must be a positive integer unique per `payerAddress`. Use 1\n * for the first payment; increment by at least 1 for each subsequent call.\n */\nexport interface GenericPaymentMessage {\n payerAddress: `0x${string}`;\n opType: string;\n opId: `0x${string}`;\n asset: `0x${string}`;\n amount: bigint;\n paymentNonce: bigint;\n}\n\n/**\n * Returns the EIP-712 domain for signing a `GenericPayment` message.\n *\n * The verifying contract is the `DataPortabilityEscrow` contract; all gateway\n * deployments share the same domain name and version.\n *\n * @param chainId - Chain ID of the Vana network (e.g. 1480 mainnet, 14800 testnet).\n * @param escrowContract - Deployed address of DataPortabilityEscrow.\n */\nexport function genericPaymentDomain(\n chainId: number,\n escrowContract: `0x${string}`,\n): TypedDataDomain {\n return {\n name: \"Vana Data Portability\",\n version: \"1\",\n chainId,\n verifyingContract: escrowContract,\n };\n}\n\n// ---------------------------------------------------------------------------\n// On-chain deposit ABI fragments\n// ---------------------------------------------------------------------------\n\n/**\n * Minimal ABI for the two deposit entry points on `DataPortabilityEscrow`.\n *\n * - `depositNative(address account)` payable — credits native VANA.\n * - `depositToken(address account, address token, uint256 amount)` — credits\n * an ERC-20 token (caller must have pre-approved the escrow contract).\n *\n * Pass this to viem's `writeContract` or encode it manually.\n */\nexport const ESCROW_DEPOSIT_ABI = [\n {\n type: \"function\",\n name: \"depositNative\",\n stateMutability: \"payable\",\n inputs: [{ name: \"account\", type: \"address\" }],\n outputs: [],\n },\n {\n type: \"function\",\n name: \"depositToken\",\n stateMutability: \"nonpayable\",\n inputs: [\n { name: \"account\", type: \"address\" },\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n outputs: [],\n },\n] as const;\n\n/**\n * The zero address used by the DataPortabilityEscrow contract to represent\n * native VANA in `asset` fields of events and balance responses.\n */\nexport const NATIVE_ASSET_ADDRESS =\n \"0x0000000000000000000000000000000000000000\" as const;\n\n// ---------------------------------------------------------------------------\n// Gateway API client\n// ---------------------------------------------------------------------------\n\n/**\n * Per-asset balance entry returned by the gateway's escrow balance endpoints.\n *\n * - `balance` — gross finalized credit (deposits credited so far).\n * - `pendingAmount` — sum of submitted deposits not yet confirmed.\n * - `authorizedAmount` — sum of all in-flight payments authorized by\n * `/v1/escrow/pay` (soft-lock). May include payments not yet settled\n * on-chain.\n * - `availableAmount` — `max(balance − authorizedAmount, 0)`. This is what\n * the payer can authorize before the gateway rejects with 402.\n */\nexport interface EscrowBalanceEntry {\n asset: string;\n balance: string;\n pendingAmount: string;\n authorizedAmount: string;\n availableAmount: string;\n updatedAt: string | null;\n}\n\nexport interface SubmittedDepositEntry {\n txHash: string;\n submittedAt: string;\n claimedAsset: string;\n claimedAmount: string;\n}\n\nexport interface FinalizedDepositEntry {\n txHash: string;\n finalizedAt: string | null;\n blockNumber: string | null;\n claimedAsset: string;\n claimedAmount: string;\n}\n\nexport interface FailedDepositEntry {\n txHash: string;\n submittedAt: string;\n claimedAsset: string;\n claimedAmount: string;\n lastError: string | null;\n}\n\n/** Full balance read response from `GET /v1/escrow/balance`. */\nexport interface EscrowBalanceResult {\n account: string;\n balances: EscrowBalanceEntry[];\n deposits: {\n submitted: SubmittedDepositEntry[];\n finalized: FinalizedDepositEntry[];\n failed: FailedDepositEntry[];\n };\n}\n\n/**\n * Response from `POST /v1/escrow/balance/sync`.\n *\n * Extends {@link EscrowBalanceResult} with a `sync` summary of what the\n * lazy-confirmation pass did.\n */\nexport interface EscrowBalanceSyncResult extends EscrowBalanceResult {\n sync:\n | { scanned: number; finalized: number; stillPending: number; failed: number }\n | { skipped: true };\n}\n\n/** Response from `POST /v1/escrow/deposit`. */\nexport interface DepositSubmissionResult {\n success: true;\n txHash: string;\n account: string;\n status: \"submitted\" | \"finalized\" | \"failed\";\n blockNumber?: string | null;\n submittedAt: string;\n finalizedAt?: string | null;\n lastError?: string | null;\n}\n\n/** Breakdown returned by a successful `POST /v1/escrow/pay`. */\nexport interface PaymentBreakdown {\n registrationFee: string;\n dataAccessFee: string;\n /** True when this call settled the registration fee for the op. */\n registrationPaid: boolean;\n}\n\n/** Response from `POST /v1/escrow/pay`. */\nexport interface EscrowPayResult {\n success: true;\n opType: string;\n opId: string;\n payerAddress: string;\n asset: string;\n amount: string;\n breakdown: PaymentBreakdown;\n paymentNonce: string;\n paidAt: string;\n}\n\n/**\n * Parameters for submitting a deposit tx hash to the gateway.\n *\n * The gateway will decode the `account` from the tx's calldata and\n * credit the identified account once the tx reaches the configured\n * confirmation depth.\n */\nexport interface SubmitDepositParams {\n /** 0x-prefixed 32-byte transaction hash. */\n txHash: `0x${string}`;\n}\n\n/**\n * Parameters for the generic op payment endpoint (`POST /v1/escrow/pay`).\n *\n * The `signature` is an EIP-712 signature over a `GenericPayment` message\n * (see {@link GENERIC_PAYMENT_TYPES} and {@link genericPaymentDomain}).\n * Build and sign the typed data with your wallet before calling\n * {@link EscrowGatewayClient.payForOp}.\n */\nexport interface PayForOpParams {\n payerAddress: `0x${string}`;\n opType: string;\n opId: `0x${string}`;\n asset: `0x${string}`;\n /** Decimal string representation of the uint256 amount. */\n amount: string;\n /** Decimal string representation of the uint256 nonce. */\n paymentNonce: string;\n /** 0x-prefixed 65-byte EIP-712 signature hex string. */\n signature: `0x${string}`;\n}\n\n/**\n * Minimal client for the gateway's escrow endpoints.\n *\n * Construct with {@link createEscrowGatewayClient}.\n */\nexport interface EscrowGatewayClient {\n /**\n * Notify the gateway of a submitted deposit transaction.\n *\n * The gateway decodes the credited account from the on-chain tx calldata\n * and starts tracking the deposit. Call this immediately after your\n * `depositNative` or `depositToken` tx is broadcast (it accepts pending\n * mempool txs). Returns `202` while the tx awaits confirmation.\n */\n submitDeposit(params: SubmitDepositParams): Promise<DepositSubmissionResult>;\n\n /**\n * Read the current escrow balance for an account.\n *\n * Pure read — no chain calls. To force a reconciliation pass first,\n * use {@link syncEscrowBalance}.\n */\n getEscrowBalance(account: `0x${string}`): Promise<EscrowBalanceResult>;\n\n /**\n * Force a reconciliation pass then return the updated balance.\n *\n * Triggers the gateway's lazy-confirmation worker for the account — any\n * submitted deposits that have reached the configured confirmation level\n * are credited before the balance is returned. Prefer this over\n * {@link getEscrowBalance} when you need a fresh view after a deposit.\n */\n syncEscrowBalance(account: `0x${string}`): Promise<EscrowBalanceSyncResult>;\n\n /**\n * Authorize a payment against the payer's escrow balance.\n *\n * The caller must:\n * 1. Assemble a {@link GenericPaymentMessage}.\n * 2. Sign it with `signTypedData` using {@link GENERIC_PAYMENT_TYPES} and\n * the domain from {@link genericPaymentDomain}.\n * 3. Pass the message fields + signature here.\n *\n * The gateway verifies the signature, checks the soft-lock balance, and\n * records the payment. Returns 402 if the payer has insufficient balance.\n */\n payForOp(params: PayForOpParams): Promise<EscrowPayResult>;\n}\n\n/**\n * Creates a client for the gateway escrow endpoints.\n *\n * @param baseUrl - Base URL of the DP RPC gateway\n * (e.g. `\"https://dp.vana.org\"`). Trailing slashes are trimmed.\n *\n * @example\n * ```typescript\n * import {\n * createEscrowGatewayClient,\n * genericPaymentDomain,\n * GENERIC_PAYMENT_TYPES,\n * } from \"@opendatalabs/vana-sdk/node\";\n *\n * const escrow = createEscrowGatewayClient(\"https://dp.vana.org\");\n *\n * // 1. Submit your deposit tx hash after broadcasting depositNative on-chain\n * const deposit = await escrow.submitDeposit({ txHash: \"0xabc…\" });\n *\n * // 2. Force-sync and read the updated balance\n * const { balances } = await escrow.syncEscrowBalance(\"0xpayerAddress\");\n *\n * // 3. Sign and authorize a grant payment\n * const sig = await walletClient.signTypedData({\n * domain: genericPaymentDomain(1480, \"0xEscrowContract\"),\n * types: GENERIC_PAYMENT_TYPES,\n * primaryType: \"GenericPayment\",\n * message: {\n * payerAddress: \"0xpayerAddress\",\n * opType: \"grant\",\n * opId: \"0xgrantId\",\n * asset: \"0x0000000000000000000000000000000000000000\",\n * amount: 1000000000000000000n,\n * paymentNonce: 1n,\n * },\n * });\n * const result = await escrow.payForOp({\n * payerAddress: \"0xpayerAddress\",\n * opType: \"grant\",\n * opId: \"0xgrantId\",\n * asset: \"0x0000000000000000000000000000000000000000\",\n * amount: \"1000000000000000000\",\n * paymentNonce: \"1\",\n * signature: sig,\n * });\n * ```\n */\nexport function createEscrowGatewayClient(\n baseUrl: string,\n): EscrowGatewayClient {\n const base = baseUrl.replace(/\\/+$/, \"\");\n\n async function throwOnError(res: Response, context: string): Promise<void> {\n if (!res.ok) {\n let detail = \"\";\n try {\n const body = (await res.json()) as { error?: string };\n if (body.error) detail = `: ${body.error}`;\n } catch {\n // Ignore JSON parse errors; use status text only.\n }\n throw new Error(\n `Escrow gateway error (${context}): ${res.status} ${res.statusText}${detail}`,\n );\n }\n }\n\n return {\n async submitDeposit({ txHash }) {\n const res = await fetch(`${base}/v1/escrow/deposit`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ txHash }),\n });\n // 202 Accepted and 200 OK are both success states for deposit submission.\n if (res.status !== 200 && res.status !== 202) {\n await throwOnError(res, \"POST /v1/escrow/deposit\");\n }\n return res.json() as Promise<DepositSubmissionResult>;\n },\n\n async getEscrowBalance(account) {\n const res = await fetch(\n `${base}/v1/escrow/balance?account=${encodeURIComponent(account)}`,\n );\n await throwOnError(res, \"GET /v1/escrow/balance\");\n return res.json() as Promise<EscrowBalanceResult>;\n },\n\n async syncEscrowBalance(account) {\n const res = await fetch(\n `${base}/v1/escrow/balance/sync?account=${encodeURIComponent(account)}`,\n { method: \"POST\" },\n );\n await throwOnError(res, \"POST /v1/escrow/balance/sync\");\n return res.json() as Promise<EscrowBalanceSyncResult>;\n },\n\n async payForOp({\n payerAddress,\n opType,\n opId,\n asset,\n amount,\n paymentNonce,\n signature,\n }) {\n const res = await fetch(`${base}/v1/escrow/pay`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Web3Signed ${signature}`,\n },\n body: JSON.stringify({\n payerAddress,\n opType,\n opId,\n asset,\n amount,\n paymentNonce,\n }),\n });\n await throwOnError(res, \"POST /v1/escrow/pay\");\n return res.json() as Promise<EscrowPayResult>;\n },\n };\n}\n"],"mappings":"AAiCO,MAAM,wBAAwB;AAAA,EACnC,gBAAgB;AAAA,IACd,EAAE,MAAM,gBAAgB,MAAM,UAAU;AAAA,IACxC,EAAE,MAAM,UAAU,MAAM,SAAS;AAAA,IACjC,EAAE,MAAM,QAAQ,MAAM,UAAU;AAAA,IAChC,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,IACjC,EAAE,MAAM,UAAU,MAAM,UAAU;AAAA,IAClC,EAAE,MAAM,gBAAgB,MAAM,UAAU;AAAA,EAC1C;AACF;AAgCO,SAAS,qBACd,SACA,gBACiB;AACjB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IACA,mBAAmB;AAAA,EACrB;AACF;AAeO,M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AM,iBAAiB,SAAS;AAC9B,YAAM,MAAM,MAAM;AAAA,QAChB,GAAG,IAAI,8BAA8B,mBAAmB,OAAO,CAAC;AAAA,MAClE;AACA,YAAM,aAAa,KAAK,wBAAwB;AAChD,aAAO,IAAI,KAAK;AAAA,IAClB;AAAA,IAEA,MAAM,kBAAkB,SAAS;AAC/B,YAAM,MAAM,MAAM;AAAA,QAChB,GAAG,IAAI,mCAAmC,mBAAmB,OAAO,CAAC;AAAA,QACrE,EAAE,QAAQ,OAAO;AAAA,MACnB;AACA,YAAM,aAAa,KAAK,8BAA8B;AACtD,aAAO,IAAI,KAAK;AAAA,IAClB;AAAA,IAEA,MAAM,SAAS;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,GAAG;AACD,YAAM,MAAM,MAAM,MAAM,GAAG,IAAI,kBAAkB;AAAA,QAC/C,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,gBAAgB;AAAA,UAChB,eAAe,cAAc,SAAS;AAAA,QACxC;AAAA,QACA,MAAM,KAAK,UAAU;AAAA,UACnB;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AACD,YAAM,aAAa,KAAK,qBAAqB;AAC7C,aAAO,IAAI,KAAK;AAAA,IAClB;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1 @@
1
+ export {};
@@ -29,8 +29,13 @@ __export(personal_server_registration_exports, {
29
29
  module.exports = __toCommonJS(personal_server_registration_exports);
30
30
  var import_viem = require("viem");
31
31
  var import_eip712 = require("./eip712");
32
- const PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
33
- const PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
32
+ var import_definitions = require("../chains/definitions");
33
+ var import_addresses = require("../generated/addresses");
34
+ const PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = import_definitions.vanaMainnet.id;
35
+ const PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = (0, import_addresses.getContractAddress)(
36
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
37
+ "DataPortabilityServers"
38
+ );
34
39
  function assertAddress(value, name) {
35
40
  if (!(0, import_viem.isAddress)(value)) {
36
41
  throw new Error(`${name} must be a valid EVM address`);
@@ -45,6 +50,12 @@ function getAccountAddress(account) {
45
50
  function isPersonalServerRegistrationSigner(source) {
46
51
  return "address" in source && typeof source.signTypedData === "function";
47
52
  }
53
+ function getDefaultServerRegistrationContract(chainId) {
54
+ return (0, import_addresses.getContractAddress)(
55
+ chainId,
56
+ "DataPortabilityServers"
57
+ );
58
+ }
48
59
  function createViemPersonalServerRegistrationSigner(source, options = {}) {
49
60
  if (isPersonalServerRegistrationSigner(source)) {
50
61
  return source;
@@ -67,12 +78,13 @@ function personalServerRegistrationDomain(input = {}) {
67
78
  if (input.config) {
68
79
  return (0, import_eip712.serverRegistrationDomain)(input.config);
69
80
  }
70
- const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
81
+ const chainId = input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID;
82
+ const verifyingContract = input.verifyingContract ?? getDefaultServerRegistrationContract(chainId);
71
83
  assertAddress(verifyingContract, "verifyingContract");
72
84
  return {
73
85
  name: "Vana Data Portability",
74
86
  version: "1",
75
- chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
87
+ chainId,
76
88
  verifyingContract
77
89
  };
78
90
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/protocol/personal-server-registration.ts"],"sourcesContent":["/**\n * Personal Server registration typed-data and signing helpers.\n *\n * These helpers are protocol-owned and runtime-neutral. Apps can sign with\n * viem local accounts, wallet clients, Account products, or any equivalent\n * signer by adapting to {@link PersonalServerRegistrationSigner}.\n *\n * @category Protocol\n */\n\nimport {\n isAddress,\n type Account,\n type Address,\n type Hex,\n type TypedDataDomain,\n type TypedDataDefinition,\n} from \"viem\";\nimport {\n SERVER_REGISTRATION_TYPES,\n serverRegistrationDomain,\n type DataPortabilityGatewayConfig,\n type ServerRegistrationMessage,\n} from \"./eip712\";\n\nexport const PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;\nexport const PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT =\n \"0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c\" as const;\n\nexport type PersonalServerRegistrationTypedData = TypedDataDefinition<\n typeof SERVER_REGISTRATION_TYPES,\n \"ServerRegistration\"\n> & {\n message: ServerRegistrationMessage;\n};\n\nexport interface PersonalServerRegistrationSigner {\n address: Address;\n signTypedData(\n typedData: PersonalServerRegistrationTypedData,\n ): Promise<Hex> | Hex;\n}\n\nexport interface ViemPersonalServerRegistrationWalletClient {\n account?: Account | Address | null;\n signTypedData(\n typedData: PersonalServerRegistrationTypedData & {\n account?: Account | Address;\n },\n ): Promise<Hex>;\n}\n\nexport type ViemPersonalServerRegistrationSignerSource =\n | PersonalServerRegistrationSigner\n | ViemPersonalServerRegistrationWalletClient;\n\nexport interface BuildPersonalServerRegistrationTypedDataInput {\n ownerAddress: Address;\n serverAddress: Address;\n serverPublicKey: string;\n serverUrl: string;\n config?: DataPortabilityGatewayConfig;\n chainId?: number;\n verifyingContract?: Address;\n}\n\nexport interface BuildPersonalServerRegistrationSignatureInput {\n signer: PersonalServerRegistrationSigner;\n serverAddress: Address;\n serverPublicKey: string;\n serverUrl: string;\n config?: DataPortabilityGatewayConfig;\n chainId?: number;\n verifyingContract?: Address;\n}\n\nexport interface PersonalServerRegistrationSignature {\n signature: Hex;\n signerAddress: Address;\n typedData: PersonalServerRegistrationTypedData;\n}\n\nexport interface PersonalServerRegistrationDomainInput {\n config?: DataPortabilityGatewayConfig;\n chainId?: number;\n verifyingContract?: Address;\n}\n\nfunction assertAddress(value: Address, name: string): void {\n if (!isAddress(value)) {\n throw new Error(`${name} must be a valid EVM address`);\n }\n}\n\nfunction getAccountAddress(\n account: Account | Address | null | undefined,\n): Address | undefined {\n if (!account) {\n return undefined;\n }\n\n return typeof account === \"string\" ? account : account.address;\n}\n\nfunction isPersonalServerRegistrationSigner(\n source: ViemPersonalServerRegistrationSignerSource,\n): source is PersonalServerRegistrationSigner {\n return \"address\" in source && typeof source.signTypedData === \"function\";\n}\n\nexport function createViemPersonalServerRegistrationSigner(\n source: ViemPersonalServerRegistrationSignerSource,\n options: { account?: Account | Address } = {},\n): PersonalServerRegistrationSigner {\n if (isPersonalServerRegistrationSigner(source)) {\n return source;\n }\n\n const accountAddress =\n getAccountAddress(options.account) ?? getAccountAddress(source.account);\n\n if (accountAddress) {\n return {\n address: accountAddress,\n signTypedData: (typedData) =>\n source.signTypedData({\n ...typedData,\n account: options.account ?? source.account ?? accountAddress,\n }),\n };\n }\n\n throw new Error(\n \"Viem wallet client requires an account option or account property\",\n );\n}\n\nexport function personalServerRegistrationDomain(\n input: PersonalServerRegistrationDomainInput = {},\n): TypedDataDomain {\n if (input.config) {\n return serverRegistrationDomain(input.config);\n }\n\n const verifyingContract =\n input.verifyingContract ??\n PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;\n assertAddress(verifyingContract, \"verifyingContract\");\n\n return {\n name: \"Vana Data Portability\",\n version: \"1\",\n chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,\n verifyingContract,\n };\n}\n\nexport function buildPersonalServerRegistrationTypedData(\n input: BuildPersonalServerRegistrationTypedDataInput,\n): PersonalServerRegistrationTypedData {\n assertAddress(input.ownerAddress, \"ownerAddress\");\n assertAddress(input.serverAddress, \"serverAddress\");\n\n return {\n domain: personalServerRegistrationDomain(input),\n types: SERVER_REGISTRATION_TYPES,\n primaryType: \"ServerRegistration\",\n message: {\n ownerAddress: input.ownerAddress,\n serverAddress: input.serverAddress,\n publicKey: input.serverPublicKey,\n serverUrl: input.serverUrl,\n },\n };\n}\n\nexport async function buildPersonalServerRegistrationSignature(\n input: BuildPersonalServerRegistrationSignatureInput,\n): Promise<PersonalServerRegistrationSignature> {\n const typedData = buildPersonalServerRegistrationTypedData({\n ownerAddress: input.signer.address,\n serverAddress: input.serverAddress,\n serverPublicKey: input.serverPublicKey,\n serverUrl: input.serverUrl,\n config: input.config,\n chainId: input.chainId,\n verifyingContract: input.verifyingContract,\n });\n const signature = await input.signer.signTypedData(typedData);\n\n return {\n signature,\n signerAddress: input.signer.address,\n typedData,\n };\n}\n\nexport const registerPersonalServerSignature =\n buildPersonalServerRegistrationSignature;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,kBAOO;AACP,oBAKO;AAEA,MAAM,gDAAgD;AACtD,MAAM,0DACX;AA6DF,SAAS,cAAc,OAAgB,MAAoB;AACzD,MAAI,KAAC,uBAAU,KAAK,GAAG;AACrB,UAAM,IAAI,MAAM,GAAG,IAAI,8BAA8B;AAAA,EACvD;AACF;AAEA,SAAS,kBACP,SACqB;AACrB,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,YAAY,WAAW,UAAU,QAAQ;AACzD;AAEA,SAAS,mCACP,QAC4C;AAC5C,SAAO,aAAa,UAAU,OAAO,OAAO,kBAAkB;AAChE;AAEO,SAAS,2CACd,QACA,UAA2C,CAAC,GACV;AAClC,MAAI,mCAAmC,MAAM,GAAG;AAC9C,WAAO;AAAA,EACT;AAEA,QAAM,iBACJ,kBAAkB,QAAQ,OAAO,KAAK,kBAAkB,OAAO,OAAO;AAExE,MAAI,gBAAgB;AAClB,WAAO;AAAA,MACL,SAAS;AAAA,MACT,eAAe,CAAC,cACd,OAAO,cAAc;AAAA,QACnB,GAAG;AAAA,QACH,SAAS,QAAQ,WAAW,OAAO,WAAW;AAAA,MAChD,CAAC;AAAA,IACL;AAAA,EACF;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;AAEO,SAAS,iCACd,QAA+C,CAAC,GAC/B;AACjB,MAAI,MAAM,QAAQ;AAChB,eAAO,wCAAyB,MAAM,MAAM;AAAA,EAC9C;AAEA,QAAM,oBACJ,MAAM,qBACN;AACF,gBAAc,mBAAmB,mBAAmB;AAEpD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,SAAS,MAAM,WAAW;AAAA,IAC1B;AAAA,EACF;AACF;AAEO,SAAS,yCACd,OACqC;AACrC,gBAAc,MAAM,cAAc,cAAc;AAChD,gBAAc,MAAM,eAAe,eAAe;AAElD,SAAO;AAAA,IACL,QAAQ,iCAAiC,KAAK;AAAA,IAC9C,OAAO;AAAA,IACP,aAAa;AAAA,IACb,SAAS;AAAA,MACP,cAAc,MAAM;AAAA,MACpB,eAAe,MAAM;AAAA,MACrB,WAAW,MAAM;AAAA,MACjB,WAAW,MAAM;AAAA,IACnB;AAAA,EACF;AACF;AAEA,eAAsB,yCACpB,OAC8C;AAC9C,QAAM,YAAY,yCAAyC;AAAA,IACzD,cAAc,MAAM,OAAO;AAAA,IAC3B,eAAe,MAAM;AAAA,IACrB,iBAAiB,MAAM;AAAA,IACvB,WAAW,MAAM;AAAA,IACjB,QAAQ,MAAM;AAAA,IACd,SAAS,MAAM;AAAA,IACf,mBAAmB,MAAM;AAAA,EAC3B,CAAC;AACD,QAAM,YAAY,MAAM,MAAM,OAAO,cAAc,SAAS;AAE5D,SAAO;AAAA,IACL;AAAA,IACA,eAAe,MAAM,OAAO;AAAA,IAC5B;AAAA,EACF;AACF;AAEO,MAAM,kCACX;","names":[]}
1
+ {"version":3,"sources":["../../src/protocol/personal-server-registration.ts"],"sourcesContent":["/**\n * Personal Server registration typed-data and signing helpers.\n *\n * These helpers are protocol-owned and runtime-neutral. Apps can sign with\n * viem local accounts, wallet clients, Account products, or any equivalent\n * signer by adapting to {@link PersonalServerRegistrationSigner}.\n *\n * @category Protocol\n */\n\nimport {\n isAddress,\n type Account,\n type Address,\n type Hex,\n type TypedDataDomain,\n type TypedDataDefinition,\n} from \"viem\";\nimport {\n SERVER_REGISTRATION_TYPES,\n serverRegistrationDomain,\n type DataPortabilityGatewayConfig,\n type ServerRegistrationMessage,\n} from \"./eip712\";\nimport { vanaMainnet } from \"../chains/definitions\";\nimport { getContractAddress } from \"../generated/addresses\";\n\ntype SupportedContractAddressChainId = Parameters<typeof getContractAddress>[0];\n\nexport const PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID =\n vanaMainnet.id as SupportedContractAddressChainId;\nexport const PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT =\n getContractAddress(\n PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,\n \"DataPortabilityServers\",\n );\n\nexport type PersonalServerRegistrationTypedData = TypedDataDefinition<\n typeof SERVER_REGISTRATION_TYPES,\n \"ServerRegistration\"\n> & {\n message: ServerRegistrationMessage;\n};\n\nexport interface PersonalServerRegistrationSigner {\n address: Address;\n signTypedData(\n typedData: PersonalServerRegistrationTypedData,\n ): Promise<Hex> | Hex;\n}\n\nexport interface ViemPersonalServerRegistrationWalletClient {\n account?: Account | Address | null;\n signTypedData(\n typedData: PersonalServerRegistrationTypedData & {\n account?: Account | Address;\n },\n ): Promise<Hex>;\n}\n\nexport type ViemPersonalServerRegistrationSignerSource =\n | PersonalServerRegistrationSigner\n | ViemPersonalServerRegistrationWalletClient;\n\nexport interface BuildPersonalServerRegistrationTypedDataInput {\n ownerAddress: Address;\n serverAddress: Address;\n serverPublicKey: string;\n serverUrl: string;\n config?: DataPortabilityGatewayConfig;\n chainId?: number;\n verifyingContract?: Address;\n}\n\nexport interface BuildPersonalServerRegistrationSignatureInput {\n signer: PersonalServerRegistrationSigner;\n serverAddress: Address;\n serverPublicKey: string;\n serverUrl: string;\n config?: DataPortabilityGatewayConfig;\n chainId?: number;\n verifyingContract?: Address;\n}\n\nexport interface PersonalServerRegistrationSignature {\n signature: Hex;\n signerAddress: Address;\n typedData: PersonalServerRegistrationTypedData;\n}\n\nexport interface PersonalServerRegistrationDomainInput {\n config?: DataPortabilityGatewayConfig;\n chainId?: number;\n verifyingContract?: Address;\n}\n\nfunction assertAddress(value: Address, name: string): void {\n if (!isAddress(value)) {\n throw new Error(`${name} must be a valid EVM address`);\n }\n}\n\nfunction getAccountAddress(\n account: Account | Address | null | undefined,\n): Address | undefined {\n if (!account) {\n return undefined;\n }\n\n return typeof account === \"string\" ? account : account.address;\n}\n\nfunction isPersonalServerRegistrationSigner(\n source: ViemPersonalServerRegistrationSignerSource,\n): source is PersonalServerRegistrationSigner {\n return \"address\" in source && typeof source.signTypedData === \"function\";\n}\n\nfunction getDefaultServerRegistrationContract(chainId: number): Address {\n return getContractAddress(\n chainId as SupportedContractAddressChainId,\n \"DataPortabilityServers\",\n );\n}\n\nexport function createViemPersonalServerRegistrationSigner(\n source: ViemPersonalServerRegistrationSignerSource,\n options: { account?: Account | Address } = {},\n): PersonalServerRegistrationSigner {\n if (isPersonalServerRegistrationSigner(source)) {\n return source;\n }\n\n const accountAddress =\n getAccountAddress(options.account) ?? getAccountAddress(source.account);\n\n if (accountAddress) {\n return {\n address: accountAddress,\n signTypedData: (typedData) =>\n source.signTypedData({\n ...typedData,\n account: options.account ?? source.account ?? accountAddress,\n }),\n };\n }\n\n throw new Error(\n \"Viem wallet client requires an account option or account property\",\n );\n}\n\nexport function personalServerRegistrationDomain(\n input: PersonalServerRegistrationDomainInput = {},\n): TypedDataDomain {\n if (input.config) {\n return serverRegistrationDomain(input.config);\n }\n\n const chainId =\n input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID;\n const verifyingContract =\n input.verifyingContract ?? getDefaultServerRegistrationContract(chainId);\n assertAddress(verifyingContract, \"verifyingContract\");\n\n return {\n name: \"Vana Data Portability\",\n version: \"1\",\n chainId,\n verifyingContract,\n };\n}\n\nexport function buildPersonalServerRegistrationTypedData(\n input: BuildPersonalServerRegistrationTypedDataInput,\n): PersonalServerRegistrationTypedData {\n assertAddress(input.ownerAddress, \"ownerAddress\");\n assertAddress(input.serverAddress, \"serverAddress\");\n\n return {\n domain: personalServerRegistrationDomain(input),\n types: SERVER_REGISTRATION_TYPES,\n primaryType: \"ServerRegistration\",\n message: {\n ownerAddress: input.ownerAddress,\n serverAddress: input.serverAddress,\n publicKey: input.serverPublicKey,\n serverUrl: input.serverUrl,\n },\n };\n}\n\nexport async function buildPersonalServerRegistrationSignature(\n input: BuildPersonalServerRegistrationSignatureInput,\n): Promise<PersonalServerRegistrationSignature> {\n const typedData = buildPersonalServerRegistrationTypedData({\n ownerAddress: input.signer.address,\n serverAddress: input.serverAddress,\n serverPublicKey: input.serverPublicKey,\n serverUrl: input.serverUrl,\n config: input.config,\n chainId: input.chainId,\n verifyingContract: input.verifyingContract,\n });\n const signature = await input.signer.signTypedData(typedData);\n\n return {\n signature,\n signerAddress: input.signer.address,\n typedData,\n };\n}\n\nexport const registerPersonalServerSignature =\n buildPersonalServerRegistrationSignature;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,kBAOO;AACP,oBAKO;AACP,yBAA4B;AAC5B,uBAAmC;AAI5B,MAAM,gDACX,+BAAY;AACP,MAAM,8DACX;AAAA,EACE;AAAA,EACA;AACF;AA6DF,SAAS,cAAc,OAAgB,MAAoB;AACzD,MAAI,KAAC,uBAAU,KAAK,GAAG;AACrB,UAAM,IAAI,MAAM,GAAG,IAAI,8BAA8B;AAAA,EACvD;AACF;AAEA,SAAS,kBACP,SACqB;AACrB,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,YAAY,WAAW,UAAU,QAAQ;AAC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cAAc,MAAM,OAAO;AAAA,IAC3B,eAAe,MAAM;AAAA,IACrB,iBAAiB,MAAM;AAAA,IACvB,WAAW,MAAM;AAAA,IACjB,QAAQ,MAAM;AAAA,IACd,SAAS,MAAM;AAAA,IACf,mBAAmB,MAAM;AAAA,EAC3B,CAAC;AACD,QAAM,YAAY,MAAM,MAAM,OAAO,cAAc,SAAS;AAE5D,SAAO;AAAA,IACL;AAAA,IACA,eAAe,MAAM,OAAO;AAAA,IAC5B;AAAA,EACF;AACF;AAEO,MAAM,kCACX;","names":[]}
@@ -9,8 +9,10 @@
9
9
  */
10
10
  import { type Account, type Address, type Hex, type TypedDataDomain, type TypedDataDefinition } from "viem";
11
11
  import { SERVER_REGISTRATION_TYPES, type DataPortabilityGatewayConfig, type ServerRegistrationMessage } from "./eip712";
12
- export declare const PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
13
- export declare const PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT: "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
12
+ import { getContractAddress } from "../generated/addresses";
13
+ type SupportedContractAddressChainId = Parameters<typeof getContractAddress>[0];
14
+ export declare const PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID: SupportedContractAddressChainId;
15
+ export declare const PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT: `0x${string}`;
14
16
  export type PersonalServerRegistrationTypedData = TypedDataDefinition<typeof SERVER_REGISTRATION_TYPES, "ServerRegistration"> & {
15
17
  message: ServerRegistrationMessage;
16
18
  };
@@ -60,3 +62,4 @@ export declare function personalServerRegistrationDomain(input?: PersonalServerR
60
62
  export declare function buildPersonalServerRegistrationTypedData(input: BuildPersonalServerRegistrationTypedDataInput): PersonalServerRegistrationTypedData;
61
63
  export declare function buildPersonalServerRegistrationSignature(input: BuildPersonalServerRegistrationSignatureInput): Promise<PersonalServerRegistrationSignature>;
62
64
  export declare const registerPersonalServerSignature: typeof buildPersonalServerRegistrationSignature;
65
+ export {};
@@ -5,8 +5,13 @@ import {
5
5
  SERVER_REGISTRATION_TYPES,
6
6
  serverRegistrationDomain
7
7
  } from "./eip712.js";
8
- const PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
9
- const PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
8
+ import { vanaMainnet } from "../chains/definitions.js";
9
+ import { getContractAddress } from "../generated/addresses.js";
10
+ const PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet.id;
11
+ const PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
12
+ PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
13
+ "DataPortabilityServers"
14
+ );
10
15
  function assertAddress(value, name) {
11
16
  if (!isAddress(value)) {
12
17
  throw new Error(`${name} must be a valid EVM address`);
@@ -21,6 +26,12 @@ function getAccountAddress(account) {
21
26
  function isPersonalServerRegistrationSigner(source) {
22
27
  return "address" in source && typeof source.signTypedData === "function";
23
28
  }
29
+ function getDefaultServerRegistrationContract(chainId) {
30
+ return getContractAddress(
31
+ chainId,
32
+ "DataPortabilityServers"
33
+ );
34
+ }
24
35
  function createViemPersonalServerRegistrationSigner(source, options = {}) {
25
36
  if (isPersonalServerRegistrationSigner(source)) {
26
37
  return source;
@@ -43,12 +54,13 @@ function personalServerRegistrationDomain(input = {}) {
43
54
  if (input.config) {
44
55
  return serverRegistrationDomain(input.config);
45
56
  }
46
- const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
57
+ const chainId = input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID;
58
+ const verifyingContract = input.verifyingContract ?? getDefaultServerRegistrationContract(chainId);
47
59
  assertAddress(verifyingContract, "verifyingContract");
48
60
  return {
49
61
  name: "Vana Data Portability",
50
62
  version: "1",
51
- chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
63
+ chainId,
52
64
  verifyingContract
53
65
  };
54
66
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/protocol/personal-server-registration.ts"],"sourcesContent":["/**\n * Personal Server registration typed-data and signing helpers.\n *\n * These helpers are protocol-owned and runtime-neutral. Apps can sign with\n * viem local accounts, wallet clients, Account products, or any equivalent\n * signer by adapting to {@link PersonalServerRegistrationSigner}.\n *\n * @category Protocol\n */\n\nimport {\n isAddress,\n type Account,\n type Address,\n type Hex,\n type TypedDataDomain,\n type TypedDataDefinition,\n} from \"viem\";\nimport {\n SERVER_REGISTRATION_TYPES,\n serverRegistrationDomain,\n type DataPortabilityGatewayConfig,\n type ServerRegistrationMessage,\n} from \"./eip712\";\n\nexport const PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;\nexport const PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT =\n \"0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c\" as const;\n\nexport type PersonalServerRegistrationTypedData = TypedDataDefinition<\n typeof SERVER_REGISTRATION_TYPES,\n \"ServerRegistration\"\n> & {\n message: ServerRegistrationMessage;\n};\n\nexport interface PersonalServerRegistrationSigner {\n address: Address;\n signTypedData(\n typedData: PersonalServerRegistrationTypedData,\n ): Promise<Hex> | Hex;\n}\n\nexport interface ViemPersonalServerRegistrationWalletClient {\n account?: Account | Address | null;\n signTypedData(\n typedData: PersonalServerRegistrationTypedData & {\n account?: Account | Address;\n },\n ): Promise<Hex>;\n}\n\nexport type ViemPersonalServerRegistrationSignerSource =\n | PersonalServerRegistrationSigner\n | ViemPersonalServerRegistrationWalletClient;\n\nexport interface BuildPersonalServerRegistrationTypedDataInput {\n ownerAddress: Address;\n serverAddress: Address;\n serverPublicKey: string;\n serverUrl: string;\n config?: DataPortabilityGatewayConfig;\n chainId?: number;\n verifyingContract?: Address;\n}\n\nexport interface BuildPersonalServerRegistrationSignatureInput {\n signer: PersonalServerRegistrationSigner;\n serverAddress: Address;\n serverPublicKey: string;\n serverUrl: string;\n config?: DataPortabilityGatewayConfig;\n chainId?: number;\n verifyingContract?: Address;\n}\n\nexport interface PersonalServerRegistrationSignature {\n signature: Hex;\n signerAddress: Address;\n typedData: PersonalServerRegistrationTypedData;\n}\n\nexport interface PersonalServerRegistrationDomainInput {\n config?: DataPortabilityGatewayConfig;\n chainId?: number;\n verifyingContract?: Address;\n}\n\nfunction assertAddress(value: Address, name: string): void {\n if (!isAddress(value)) {\n throw new Error(`${name} must be a valid EVM address`);\n }\n}\n\nfunction getAccountAddress(\n account: Account | Address | null | undefined,\n): Address | undefined {\n if (!account) {\n return undefined;\n }\n\n return typeof account === \"string\" ? account : account.address;\n}\n\nfunction isPersonalServerRegistrationSigner(\n source: ViemPersonalServerRegistrationSignerSource,\n): source is PersonalServerRegistrationSigner {\n return \"address\" in source && typeof source.signTypedData === \"function\";\n}\n\nexport function createViemPersonalServerRegistrationSigner(\n source: ViemPersonalServerRegistrationSignerSource,\n options: { account?: Account | Address } = {},\n): PersonalServerRegistrationSigner {\n if (isPersonalServerRegistrationSigner(source)) {\n return source;\n }\n\n const accountAddress =\n getAccountAddress(options.account) ?? getAccountAddress(source.account);\n\n if (accountAddress) {\n return {\n address: accountAddress,\n signTypedData: (typedData) =>\n source.signTypedData({\n ...typedData,\n account: options.account ?? source.account ?? accountAddress,\n }),\n };\n }\n\n throw new Error(\n \"Viem wallet client requires an account option or account property\",\n );\n}\n\nexport function personalServerRegistrationDomain(\n input: PersonalServerRegistrationDomainInput = {},\n): TypedDataDomain {\n if (input.config) {\n return serverRegistrationDomain(input.config);\n }\n\n const verifyingContract =\n input.verifyingContract ??\n PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;\n assertAddress(verifyingContract, \"verifyingContract\");\n\n return {\n name: \"Vana Data Portability\",\n version: \"1\",\n chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,\n verifyingContract,\n };\n}\n\nexport function buildPersonalServerRegistrationTypedData(\n input: BuildPersonalServerRegistrationTypedDataInput,\n): PersonalServerRegistrationTypedData {\n assertAddress(input.ownerAddress, \"ownerAddress\");\n assertAddress(input.serverAddress, \"serverAddress\");\n\n return {\n domain: personalServerRegistrationDomain(input),\n types: SERVER_REGISTRATION_TYPES,\n primaryType: \"ServerRegistration\",\n message: {\n ownerAddress: input.ownerAddress,\n serverAddress: input.serverAddress,\n publicKey: input.serverPublicKey,\n serverUrl: input.serverUrl,\n },\n };\n}\n\nexport async function buildPersonalServerRegistrationSignature(\n input: BuildPersonalServerRegistrationSignatureInput,\n): Promise<PersonalServerRegistrationSignature> {\n const typedData = buildPersonalServerRegistrationTypedData({\n ownerAddress: input.signer.address,\n serverAddress: input.serverAddress,\n serverPublicKey: input.serverPublicKey,\n serverUrl: input.serverUrl,\n config: input.config,\n chainId: input.chainId,\n verifyingContract: input.verifyingContract,\n });\n const signature = await input.signer.signTypedData(typedData);\n\n return {\n signature,\n signerAddress: input.signer.address,\n typedData,\n };\n}\n\nexport const registerPersonalServerSignature =\n buildPersonalServerRegistrationSignature;\n"],"mappings":"AAUA;AAAA,EACE;AAAA,OAMK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEA,MAAM,gDAAgD;AACtD,MAAM,0DACX;AA6DF,SAAS,cAAc,OAAgB,MAAoB;AACzD,MAAI,CAAC,UAAU,KAAK,GAAG;AACrB,UAAM,IAAI,MAAM,GAAG,IAAI,8BAA8B;AAAA,EACvD;AACF;AAEA,SAAS,kBACP,SACqB;AACrB,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,YAAY,WAAW,UAAU,QAAQ;AACzD;AAEA,SAAS,mCACP,QAC4C;AAC5C,SAAO,aAAa,UAAU,OAAO,OAAO,kBAAkB;AAChE;AAEO,SAAS,2CACd,QAC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AM,MAAM,OAAO,cAAc,SAAS;AAE5D,SAAO;AAAA,IACL;AAAA,IACA,eAAe,MAAM,OAAO;AAAA,IAC5B;AAAA,EACF;AACF;AAEO,MAAM,kCACX;","names":[]}
1
+ {"version":3,"sources":["../../src/protocol/personal-server-registration.ts"],"sourcesContent":["/**\n * Personal Server registration typed-data and signing helpers.\n *\n * These helpers are protocol-owned and runtime-neutral. Apps can sign with\n * viem local accounts, wallet clients, Account products, or any equivalent\n * signer by adapting to {@link PersonalServerRegistrationSigner}.\n *\n * @category Protocol\n */\n\nimport {\n isAddress,\n type Account,\n type Address,\n type Hex,\n type TypedDataDomain,\n type TypedDataDefinition,\n} from \"viem\";\nimport {\n SERVER_REGISTRATION_TYPES,\n serverRegistrationDomain,\n type DataPortabilityGatewayConfig,\n type ServerRegistrationMessage,\n} from \"./eip712\";\nimport { vanaMainnet } from \"../chains/definitions\";\nimport { getContractAddress } from \"../generated/addresses\";\n\ntype SupportedContractAddressChainId = Parameters<typeof getContractAddress>[0];\n\nexport const PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID =\n vanaMainnet.id as SupportedContractAddressChainId;\nexport const PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT =\n getContractAddress(\n PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,\n \"DataPortabilityServers\",\n );\n\nexport type PersonalServerRegistrationTypedData = TypedDataDefinition<\n typeof SERVER_REGISTRATION_TYPES,\n \"ServerRegistration\"\n> & {\n message: ServerRegistrationMessage;\n};\n\nexport interface PersonalServerRegistrationSigner {\n address: Address;\n signTypedData(\n typedData: PersonalServerRegistrationTypedData,\n ): Promise<Hex> | Hex;\n}\n\nexport interface ViemPersonalServerRegistrationWalletClient {\n account?: Account | Address | null;\n signTypedData(\n typedData: PersonalServerRegistrationTypedData & {\n account?: Account | Address;\n },\n ): Promise<Hex>;\n}\n\nexport type ViemPersonalServerRegistrationSignerSource =\n | PersonalServerRegistrationSigner\n | ViemPersonalServerRegistrationWalletClient;\n\nexport interface BuildPersonalServerRegistrationTypedDataInput {\n ownerAddress: Address;\n serverAddress: Address;\n serverPublicKey: string;\n serverUrl: string;\n config?: DataPortabilityGatewayConfig;\n chainId?: number;\n verifyingContract?: Address;\n}\n\nexport interface BuildPersonalServerRegistrationSignatureInput {\n signer: PersonalServerRegistrationSigner;\n serverAddress: Address;\n serverPublicKey: string;\n serverUrl: string;\n config?: DataPortabilityGatewayConfig;\n chainId?: number;\n verifyingContract?: Address;\n}\n\nexport interface PersonalServerRegistrationSignature {\n signature: Hex;\n signerAddress: Address;\n typedData: PersonalServerRegistrationTypedData;\n}\n\nexport interface PersonalServerRegistrationDomainInput {\n config?: DataPortabilityGatewayConfig;\n chainId?: number;\n verifyingContract?: Address;\n}\n\nfunction assertAddress(value: Address, name: string): void {\n if (!isAddress(value)) {\n throw new Error(`${name} must be a valid EVM address`);\n }\n}\n\nfunction getAccountAddress(\n account: Account | Address | null | undefined,\n): Address | undefined {\n if (!account) {\n return undefined;\n }\n\n return typeof account === \"string\" ? account : account.address;\n}\n\nfunction isPersonalServerRegistrationSigner(\n source: ViemPersonalServerRegistrationSignerSource,\n): source is PersonalServerRegistrationSigner {\n return \"address\" in source && typeof source.signTypedData === \"function\";\n}\n\nfunction getDefaultServerRegistrationContract(chainId: number): Address {\n return getContractAddress(\n chainId as SupportedContractAddressChainId,\n \"DataPortabilityServers\",\n );\n}\n\nexport function createViemPersonalServerRegistrationSigner(\n source: ViemPersonalServerRegistrationSignerSource,\n options: { account?: Account | Address } = {},\n): PersonalServerRegistrationSigner {\n if (isPersonalServerRegistrationSigner(source)) {\n return source;\n }\n\n const accountAddress =\n getAccountAddress(options.account) ?? getAccountAddress(source.account);\n\n if (accountAddress) {\n return {\n address: accountAddress,\n signTypedData: (typedData) =>\n source.signTypedData({\n ...typedData,\n account: options.account ?? source.account ?? accountAddress,\n }),\n };\n }\n\n throw new Error(\n \"Viem wallet client requires an account option or account property\",\n );\n}\n\nexport function personalServerRegistrationDomain(\n input: PersonalServerRegistrationDomainInput = {},\n): TypedDataDomain {\n if (input.config) {\n return serverRegistrationDomain(input.config);\n }\n\n const chainId =\n input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID;\n const verifyingContract =\n input.verifyingContract ?? getDefaultServerRegistrationContract(chainId);\n assertAddress(verifyingContract, \"verifyingContract\");\n\n return {\n name: \"Vana Data Portability\",\n version: \"1\",\n chainId,\n verifyingContract,\n };\n}\n\nexport function buildPersonalServerRegistrationTypedData(\n input: BuildPersonalServerRegistrationTypedDataInput,\n): PersonalServerRegistrationTypedData {\n assertAddress(input.ownerAddress, \"ownerAddress\");\n assertAddress(input.serverAddress, \"serverAddress\");\n\n return {\n domain: personalServerRegistrationDomain(input),\n types: SERVER_REGISTRATION_TYPES,\n primaryType: \"ServerRegistration\",\n message: {\n ownerAddress: input.ownerAddress,\n serverAddress: input.serverAddress,\n publicKey: input.serverPublicKey,\n serverUrl: input.serverUrl,\n },\n };\n}\n\nexport async function buildPersonalServerRegistrationSignature(\n input: BuildPersonalServerRegistrationSignatureInput,\n): Promise<PersonalServerRegistrationSignature> {\n const typedData = buildPersonalServerRegistrationTypedData({\n ownerAddress: input.signer.address,\n serverAddress: input.serverAddress,\n serverPublicKey: input.serverPublicKey,\n serverUrl: input.serverUrl,\n config: input.config,\n chainId: input.chainId,\n verifyingContract: input.verifyingContract,\n });\n const signature = await input.signer.signTypedData(typedData);\n\n return {\n signature,\n signerAddress: input.signer.address,\n typedData,\n };\n}\n\nexport const registerPersonalServerSignature =\n buildPersonalServerRegistrationSignature;\n"],"mappings":"AAUA;AAAA,EACE;AAAA,OAMK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AAI5B,MAAM,gDACX,YAAY;AACP,MAAM,0DACX;AAAA,EACE;AAAA,EACA;AACF;AA6DF,SAAS,cAAc,OAAgB,MAAoB;AACzD,MAAI,CAA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b,SAAS;AAAA,MACP,cAAc,MAAM;AAAA,MACpB,eAAe,MAAM;AAAA,MACrB,WAAW,MAAM;AAAA,MACjB,WAAW,MAAM;AAAA,IACnB;AAAA,EACF;AACF;AAEA,eAAsB,yCACpB,OAC8C;AAC9C,QAAM,YAAY,yCAAyC;AAAA,IACzD,cAAc,MAAM,OAAO;AAAA,IAC3B,eAAe,MAAM;AAAA,IACrB,iBAAiB,MAAM;AAAA,IACvB,WAAW,MAAM;AAAA,IACjB,QAAQ,MAAM;AAAA,IACd,SAAS,MAAM;AAAA,IACf,mBAAmB,MAAM;AAAA,EAC3B,CAAC;AACD,QAAM,YAAY,MAAM,MAAM,OAAO,cAAc,SAAS;AAE5D,SAAO;AAAA,IACL;AAAA,IACA,eAAe,MAAM,OAAO;AAAA,IAC5B;AAAA,EACF;AACF;AAEO,MAAM,kCACX;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendatalabs/vana-sdk",
3
- "version": "3.4.1",
3
+ "version": "3.5.0",
4
4
  "description": "A TypeScript library for interacting with Vana Network smart contracts.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/protocol/personal-server-lite-owner-binding.ts"],"sourcesContent":["/**\n * PS Lite owner-binding message and signing helpers.\n *\n * PS Lite uses this replayable personal-sign message as a wallet-owned input\n * for opening the user's local encrypted runtime. This is intentionally\n * separate from Personal Server registration, which is EIP-712 typed data.\n *\n * @category Protocol\n */\n\nimport {\n isAddress,\n type Account,\n type Address,\n type Hex,\n type SignableMessage,\n} from \"viem\";\n\nexport const PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = \"vana.account.v1\";\nexport const PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = \"ps-lite-owner\";\nexport const PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX =\n `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:` as const;\n\nexport type PersonalServerLiteOwnerBindingPurpose =\n typeof PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE;\n\nexport type PersonalServerLiteOwnerBindingMessage =\n `${typeof PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${Lowercase<Address>}`;\n\nexport interface PersonalServerLiteOwnerBindingSigner {\n address: Address;\n signMessage(input: {\n message: PersonalServerLiteOwnerBindingMessage;\n }): Promise<Hex> | Hex;\n}\n\nexport interface ViemPersonalServerLiteOwnerBindingWalletClient {\n account?: Account | Address | null;\n signMessage(input: {\n account?: Account | Address;\n message: SignableMessage;\n }): Promise<Hex>;\n}\n\nexport type ViemPersonalServerLiteOwnerBindingSignerSource =\n | PersonalServerLiteOwnerBindingSigner\n | ViemPersonalServerLiteOwnerBindingWalletClient;\n\nexport interface BuildPersonalServerLiteOwnerBindingSignatureInput {\n signer: PersonalServerLiteOwnerBindingSigner;\n}\n\nexport interface PersonalServerLiteOwnerBindingSignature {\n signature: Hex;\n signerAddress: Address;\n message: PersonalServerLiteOwnerBindingMessage;\n purpose: PersonalServerLiteOwnerBindingPurpose;\n}\n\nfunction assertAddress(value: Address, name: string): void {\n if (!isAddress(value)) {\n throw new Error(`${name} must be a valid EVM address`);\n }\n}\n\nfunction getAccountAddress(\n account: Account | Address | null | undefined,\n): Address | undefined {\n if (!account) {\n return undefined;\n }\n\n return typeof account === \"string\" ? account : account.address;\n}\n\nfunction isPersonalServerLiteOwnerBindingSigner(\n source: ViemPersonalServerLiteOwnerBindingSignerSource,\n): source is PersonalServerLiteOwnerBindingSigner {\n return \"address\" in source && typeof source.signMessage === \"function\";\n}\n\nexport function buildPersonalServerLiteOwnerBindingMessage(\n ownerAddress: Address,\n): PersonalServerLiteOwnerBindingMessage {\n assertAddress(ownerAddress, \"ownerAddress\");\n return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}` as PersonalServerLiteOwnerBindingMessage;\n}\n\nexport function createViemPersonalServerLiteOwnerBindingSigner(\n source: ViemPersonalServerLiteOwnerBindingSignerSource,\n options: { account?: Account | Address } = {},\n): PersonalServerLiteOwnerBindingSigner {\n if (isPersonalServerLiteOwnerBindingSigner(source)) {\n return source;\n }\n\n const accountAddress =\n getAccountAddress(options.account) ?? getAccountAddress(source.account);\n\n if (accountAddress) {\n return {\n address: accountAddress,\n signMessage: ({ message }) =>\n source.signMessage({\n account: options.account ?? source.account ?? accountAddress,\n message,\n }),\n };\n }\n\n throw new Error(\n \"Viem wallet client requires an account option or account property\",\n );\n}\n\nexport async function buildPersonalServerLiteOwnerBindingSignature(\n input: BuildPersonalServerLiteOwnerBindingSignatureInput,\n): Promise<PersonalServerLiteOwnerBindingSignature> {\n const message = buildPersonalServerLiteOwnerBindingMessage(\n input.signer.address,\n );\n const signature = await input.signer.signMessage({ message });\n\n return {\n signature,\n signerAddress: input.signer.address,\n message,\n purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,\n };\n}\n\nexport const signPersonalServerLiteOwnerBinding =\n buildPersonalServerLiteOwnerBindingSignature;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,kBAMO;AAEA,MAAM,6CAA6C;AACnD,MAAM,6CAA6C;AACnD,MAAM,4CACX,GAAG,0CAA0C,IAAI,0CAA0C;AAsC7F,SAAS,cAAc,OAAgB,MAAoB;AACzD,MAAI,KAAC,uBAAU,KAAK,GAAG;AACrB,UAAM,IAAI,MAAM,GAAG,IAAI,8BAA8B;AAAA,EACvD;AACF;AAEA,SAAS,kBACP,SACqB;AACrB,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,YAAY,WAAW,UAAU,QAAQ;AACzD;AAEA,SAAS,uCACP,QACgD;AAChD,SAAO,aAAa,UAAU,OAAO,OAAO,gBAAgB;AAC9D;AAEO,SAAS,2CACd,cACuC;AACvC,gBAAc,cAAc,cAAc;AAC1C,SAAO,GAAG,yCAAyC,GAAG,aAAa,YAAY,CAAC;AAClF;AAEO,SAAS,+CACd,QACA,UAA2C,CAAC,GACN;AACtC,MAAI,uCAAuC,MAAM,GAAG;AAClD,WAAO;AAAA,EACT;AAEA,QAAM,iBACJ,kBAAkB,QAAQ,OAAO,KAAK,kBAAkB,OAAO,OAAO;AAExE,MAAI,gBAAgB;AAClB,WAAO;AAAA,MACL,SAAS;AAAA,MACT,aAAa,CAAC,EAAE,QAAQ,MACtB,OAAO,YAAY;AAAA,QACjB,SAAS,QAAQ,WAAW,OAAO,WAAW;AAAA,QAC9C;AAAA,MACF,CAAC;AAAA,IACL;AAAA,EACF;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;AAEA,eAAsB,6CACpB,OACkD;AAClD,QAAM,UAAU;AAAA,IACd,MAAM,OAAO;AAAA,EACf;AACA,QAAM,YAAY,MAAM,MAAM,OAAO,YAAY,EAAE,QAAQ,CAAC;AAE5D,SAAO;AAAA,IACL;AAAA,IACA,eAAe,MAAM,OAAO;AAAA,IAC5B;AAAA,IACA,SAAS;AAAA,EACX;AACF;AAEO,MAAM,qCACX;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/protocol/personal-server-lite-owner-binding.ts"],"sourcesContent":["/**\n * PS Lite owner-binding message and signing helpers.\n *\n * PS Lite uses this replayable personal-sign message as a wallet-owned input\n * for opening the user's local encrypted runtime. This is intentionally\n * separate from Personal Server registration, which is EIP-712 typed data.\n *\n * @category Protocol\n */\n\nimport {\n isAddress,\n type Account,\n type Address,\n type Hex,\n type SignableMessage,\n} from \"viem\";\n\nexport const PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = \"vana.account.v1\";\nexport const PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = \"ps-lite-owner\";\nexport const PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX =\n `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:` as const;\n\nexport type PersonalServerLiteOwnerBindingPurpose =\n typeof PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE;\n\nexport type PersonalServerLiteOwnerBindingMessage =\n `${typeof PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${Lowercase<Address>}`;\n\nexport interface PersonalServerLiteOwnerBindingSigner {\n address: Address;\n signMessage(input: {\n message: PersonalServerLiteOwnerBindingMessage;\n }): Promise<Hex> | Hex;\n}\n\nexport interface ViemPersonalServerLiteOwnerBindingWalletClient {\n account?: Account | Address | null;\n signMessage(input: {\n account?: Account | Address;\n message: SignableMessage;\n }): Promise<Hex>;\n}\n\nexport type ViemPersonalServerLiteOwnerBindingSignerSource =\n | PersonalServerLiteOwnerBindingSigner\n | ViemPersonalServerLiteOwnerBindingWalletClient;\n\nexport interface BuildPersonalServerLiteOwnerBindingSignatureInput {\n signer: PersonalServerLiteOwnerBindingSigner;\n}\n\nexport interface PersonalServerLiteOwnerBindingSignature {\n signature: Hex;\n signerAddress: Address;\n message: PersonalServerLiteOwnerBindingMessage;\n purpose: PersonalServerLiteOwnerBindingPurpose;\n}\n\nfunction assertAddress(value: Address, name: string): void {\n if (!isAddress(value)) {\n throw new Error(`${name} must be a valid EVM address`);\n }\n}\n\nfunction getAccountAddress(\n account: Account | Address | null | undefined,\n): Address | undefined {\n if (!account) {\n return undefined;\n }\n\n return typeof account === \"string\" ? account : account.address;\n}\n\nfunction isPersonalServerLiteOwnerBindingSigner(\n source: ViemPersonalServerLiteOwnerBindingSignerSource,\n): source is PersonalServerLiteOwnerBindingSigner {\n return \"address\" in source && typeof source.signMessage === \"function\";\n}\n\nexport function buildPersonalServerLiteOwnerBindingMessage(\n ownerAddress: Address,\n): PersonalServerLiteOwnerBindingMessage {\n assertAddress(ownerAddress, \"ownerAddress\");\n return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}` as PersonalServerLiteOwnerBindingMessage;\n}\n\nexport function createViemPersonalServerLiteOwnerBindingSigner(\n source: ViemPersonalServerLiteOwnerBindingSignerSource,\n options: { account?: Account | Address } = {},\n): PersonalServerLiteOwnerBindingSigner {\n if (isPersonalServerLiteOwnerBindingSigner(source)) {\n return source;\n }\n\n const accountAddress =\n getAccountAddress(options.account) ?? getAccountAddress(source.account);\n\n if (accountAddress) {\n return {\n address: accountAddress,\n signMessage: ({ message }) =>\n source.signMessage({\n account: options.account ?? source.account ?? accountAddress,\n message,\n }),\n };\n }\n\n throw new Error(\n \"Viem wallet client requires an account option or account property\",\n );\n}\n\nexport async function buildPersonalServerLiteOwnerBindingSignature(\n input: BuildPersonalServerLiteOwnerBindingSignatureInput,\n): Promise<PersonalServerLiteOwnerBindingSignature> {\n const message = buildPersonalServerLiteOwnerBindingMessage(\n input.signer.address,\n );\n const signature = await input.signer.signMessage({ message });\n\n return {\n signature,\n signerAddress: input.signer.address,\n message,\n purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,\n };\n}\n\nexport const signPersonalServerLiteOwnerBinding =\n buildPersonalServerLiteOwnerBindingSignature;\n"],"mappings":"AAUA;AAAA,EACE;AAAA,OAKK;AAEA,MAAM,6CAA6C;AACnD,MAAM,6CAA6C;AACnD,MAAM,4CACX,GAAG,0CAA0C,IAAI,0CAA0C;AAsC7F,SAAS,cAAc,OAAgB,MAAoB;AACzD,MAAI,CAAC,UAAU,KAAK,GAAG;AACrB,UAAM,IAAI,MAAM,GAAG,IAAI,8BAA8B;AAAA,EACvD;AACF;AAEA,SAAS,kBACP,SACqB;AACrB,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,YAAY,WAAW,UAAU,QAAQ;AACzD;AAEA,SAAS,uCACP,QACgD;AAChD,SAAO,aAAa,UAAU,OAAO,OAAO,gBAAgB;AAC9D;AAEO,SAAS,2CACd,cACuC;AACvC,gBAAc,cAAc,c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