@opendatalabs/vana-sdk 3.4.1 → 3.5.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/dist/account/personal-server-lite-owner-binding.cjs +3 -3
- package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -1
- package/dist/account/personal-server-lite-owner-binding.d.ts +2 -2
- package/dist/account/personal-server-lite-owner-binding.js +1 -1
- package/dist/account/personal-server-lite-owner-binding.js.map +1 -1
- package/dist/index.browser.d.ts +2 -1
- package/dist/index.browser.js +208 -23
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +213 -23
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +2 -1
- package/dist/index.node.js +208 -23
- package/dist/index.node.js.map +4 -4
- package/dist/{protocol/personal-server-lite-owner-binding.cjs → personal-server-lite/owner-binding.cjs} +5 -5
- package/dist/personal-server-lite/owner-binding.cjs.map +1 -0
- package/dist/{protocol/personal-server-lite-owner-binding.d.ts → personal-server-lite/owner-binding.d.ts} +3 -3
- package/dist/{protocol/personal-server-lite-owner-binding.js → personal-server-lite/owner-binding.js} +2 -2
- package/dist/personal-server-lite/owner-binding.js.map +1 -0
- package/dist/protocol/escrow.cjs +146 -0
- package/dist/protocol/escrow.cjs.map +1 -0
- package/dist/protocol/escrow.d.ts +336 -0
- package/dist/protocol/escrow.js +118 -0
- package/dist/protocol/escrow.js.map +1 -0
- package/dist/protocol/escrow.test.d.ts +1 -0
- package/dist/protocol/personal-server-registration.cjs +16 -4
- package/dist/protocol/personal-server-registration.cjs.map +1 -1
- package/dist/protocol/personal-server-registration.d.ts +5 -2
- package/dist/protocol/personal-server-registration.js +16 -4
- package/dist/protocol/personal-server-registration.js.map +1 -1
- package/dist/storage/providers/vana-storage.cjs +75 -17
- package/dist/storage/providers/vana-storage.cjs.map +1 -1
- package/dist/storage/providers/vana-storage.js +75 -17
- package/dist/storage/providers/vana-storage.js.map +1 -1
- package/package.json +1 -1
- package/dist/protocol/personal-server-lite-owner-binding.cjs.map +0 -1
- package/dist/protocol/personal-server-lite-owner-binding.js.map +0 -1
- /package/dist/{protocol/personal-server-lite-owner-binding.test.d.ts → personal-server-lite/owner-binding.test.d.ts} +0 -0
|
@@ -16,8 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var owner_binding_exports = {};
|
|
20
|
+
__export(owner_binding_exports, {
|
|
21
21
|
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
22
22
|
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
23
23
|
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION: () => PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
@@ -26,9 +26,9 @@ __export(personal_server_lite_owner_binding_exports, {
|
|
|
26
26
|
createViemPersonalServerLiteOwnerBindingSigner: () => createViemPersonalServerLiteOwnerBindingSigner,
|
|
27
27
|
signPersonalServerLiteOwnerBinding: () => signPersonalServerLiteOwnerBinding
|
|
28
28
|
});
|
|
29
|
-
module.exports = __toCommonJS(
|
|
29
|
+
module.exports = __toCommonJS(owner_binding_exports);
|
|
30
30
|
var import_viem = require("viem");
|
|
31
|
-
const PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.
|
|
31
|
+
const PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
|
|
32
32
|
const PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
33
33
|
const PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
34
34
|
function assertAddress(value, name) {
|
|
@@ -90,4 +90,4 @@ const signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSi
|
|
|
90
90
|
createViemPersonalServerLiteOwnerBindingSigner,
|
|
91
91
|
signPersonalServerLiteOwnerBinding
|
|
92
92
|
});
|
|
93
|
-
//# sourceMappingURL=
|
|
93
|
+
//# sourceMappingURL=owner-binding.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/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 Personal Server Lite\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 =\n \"vana.ps-lite.owner-binding.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,6CACX;AACK,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":[]}
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* for opening the user's local encrypted runtime. This is intentionally
|
|
6
6
|
* separate from Personal Server registration, which is EIP-712 typed data.
|
|
7
7
|
*
|
|
8
|
-
* @category
|
|
8
|
+
* @category Personal Server Lite
|
|
9
9
|
*/
|
|
10
10
|
import { type Account, type Address, type Hex, type SignableMessage } from "viem";
|
|
11
|
-
export declare const PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.
|
|
11
|
+
export declare const PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
|
|
12
12
|
export declare const PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
13
|
-
export declare const PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX: "vana.
|
|
13
|
+
export declare const PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX: "vana.ps-lite.owner-binding.v1:ps-lite-owner:";
|
|
14
14
|
export type PersonalServerLiteOwnerBindingPurpose = typeof PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE;
|
|
15
15
|
export type PersonalServerLiteOwnerBindingMessage = `${typeof PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${Lowercase<Address>}`;
|
|
16
16
|
export interface PersonalServerLiteOwnerBindingSigner {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isAddress
|
|
3
3
|
} from "viem";
|
|
4
|
-
const PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.
|
|
4
|
+
const PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
|
|
5
5
|
const PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
6
6
|
const PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
7
7
|
function assertAddress(value, name) {
|
|
@@ -62,4 +62,4 @@ export {
|
|
|
62
62
|
createViemPersonalServerLiteOwnerBindingSigner,
|
|
63
63
|
signPersonalServerLiteOwnerBinding
|
|
64
64
|
};
|
|
65
|
-
//# sourceMappingURL=
|
|
65
|
+
//# sourceMappingURL=owner-binding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/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 Personal Server Lite\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 =\n \"vana.ps-lite.owner-binding.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,6CACX;AACK,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,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":[]}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var escrow_exports = {};
|
|
20
|
+
__export(escrow_exports, {
|
|
21
|
+
ESCROW_DEPOSIT_ABI: () => ESCROW_DEPOSIT_ABI,
|
|
22
|
+
GENERIC_PAYMENT_TYPES: () => GENERIC_PAYMENT_TYPES,
|
|
23
|
+
NATIVE_ASSET_ADDRESS: () => NATIVE_ASSET_ADDRESS,
|
|
24
|
+
createEscrowGatewayClient: () => createEscrowGatewayClient,
|
|
25
|
+
genericPaymentDomain: () => genericPaymentDomain
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(escrow_exports);
|
|
28
|
+
const GENERIC_PAYMENT_TYPES = {
|
|
29
|
+
GenericPayment: [
|
|
30
|
+
{ name: "payerAddress", type: "address" },
|
|
31
|
+
{ name: "opType", type: "string" },
|
|
32
|
+
{ name: "opId", type: "bytes32" },
|
|
33
|
+
{ name: "asset", type: "address" },
|
|
34
|
+
{ name: "amount", type: "uint256" },
|
|
35
|
+
{ name: "paymentNonce", type: "uint256" }
|
|
36
|
+
]
|
|
37
|
+
};
|
|
38
|
+
function genericPaymentDomain(chainId, escrowContract) {
|
|
39
|
+
return {
|
|
40
|
+
name: "Vana Data Portability",
|
|
41
|
+
version: "1",
|
|
42
|
+
chainId,
|
|
43
|
+
verifyingContract: escrowContract
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const ESCROW_DEPOSIT_ABI = [
|
|
47
|
+
{
|
|
48
|
+
type: "function",
|
|
49
|
+
name: "depositNative",
|
|
50
|
+
stateMutability: "payable",
|
|
51
|
+
inputs: [{ name: "account", type: "address" }],
|
|
52
|
+
outputs: []
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: "function",
|
|
56
|
+
name: "depositToken",
|
|
57
|
+
stateMutability: "nonpayable",
|
|
58
|
+
inputs: [
|
|
59
|
+
{ name: "account", type: "address" },
|
|
60
|
+
{ name: "token", type: "address" },
|
|
61
|
+
{ name: "amount", type: "uint256" }
|
|
62
|
+
],
|
|
63
|
+
outputs: []
|
|
64
|
+
}
|
|
65
|
+
];
|
|
66
|
+
const NATIVE_ASSET_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
67
|
+
function createEscrowGatewayClient(baseUrl) {
|
|
68
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
69
|
+
async function throwOnError(res, context) {
|
|
70
|
+
if (!res.ok) {
|
|
71
|
+
let detail = "";
|
|
72
|
+
try {
|
|
73
|
+
const body = await res.json();
|
|
74
|
+
if (body.error) detail = `: ${body.error}`;
|
|
75
|
+
} catch {
|
|
76
|
+
}
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Escrow gateway error (${context}): ${res.status} ${res.statusText}${detail}`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
async submitDeposit({ txHash }) {
|
|
84
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
85
|
+
method: "POST",
|
|
86
|
+
headers: { "Content-Type": "application/json" },
|
|
87
|
+
body: JSON.stringify({ txHash })
|
|
88
|
+
});
|
|
89
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
90
|
+
await throwOnError(res, "POST /v1/escrow/deposit");
|
|
91
|
+
}
|
|
92
|
+
return res.json();
|
|
93
|
+
},
|
|
94
|
+
async getEscrowBalance(account) {
|
|
95
|
+
const res = await fetch(
|
|
96
|
+
`${base}/v1/escrow/balance?account=${encodeURIComponent(account)}`
|
|
97
|
+
);
|
|
98
|
+
await throwOnError(res, "GET /v1/escrow/balance");
|
|
99
|
+
return res.json();
|
|
100
|
+
},
|
|
101
|
+
async syncEscrowBalance(account) {
|
|
102
|
+
const res = await fetch(
|
|
103
|
+
`${base}/v1/escrow/balance/sync?account=${encodeURIComponent(account)}`,
|
|
104
|
+
{ method: "POST" }
|
|
105
|
+
);
|
|
106
|
+
await throwOnError(res, "POST /v1/escrow/balance/sync");
|
|
107
|
+
return res.json();
|
|
108
|
+
},
|
|
109
|
+
async payForOp({
|
|
110
|
+
payerAddress,
|
|
111
|
+
opType,
|
|
112
|
+
opId,
|
|
113
|
+
asset,
|
|
114
|
+
amount,
|
|
115
|
+
paymentNonce,
|
|
116
|
+
signature
|
|
117
|
+
}) {
|
|
118
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
119
|
+
method: "POST",
|
|
120
|
+
headers: {
|
|
121
|
+
"Content-Type": "application/json",
|
|
122
|
+
Authorization: `Web3Signed ${signature}`
|
|
123
|
+
},
|
|
124
|
+
body: JSON.stringify({
|
|
125
|
+
payerAddress,
|
|
126
|
+
opType,
|
|
127
|
+
opId,
|
|
128
|
+
asset,
|
|
129
|
+
amount,
|
|
130
|
+
paymentNonce
|
|
131
|
+
})
|
|
132
|
+
});
|
|
133
|
+
await throwOnError(res, "POST /v1/escrow/pay");
|
|
134
|
+
return res.json();
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
139
|
+
0 && (module.exports = {
|
|
140
|
+
ESCROW_DEPOSIT_ABI,
|
|
141
|
+
GENERIC_PAYMENT_TYPES,
|
|
142
|
+
NATIVE_ASSET_ADDRESS,
|
|
143
|
+
createEscrowGatewayClient,
|
|
144
|
+
genericPaymentDomain
|
|
145
|
+
});
|
|
146
|
+
//# sourceMappingURL=escrow.cjs.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":"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","names":[]}
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DPv2 escrow payment helpers.
|
|
3
|
+
*
|
|
4
|
+
* Covers the three-phase flow used by builders to pay for data access:
|
|
5
|
+
*
|
|
6
|
+
* 1. **Deposit** — call `depositNative` or `depositToken` on the
|
|
7
|
+
* DataPortabilityEscrow contract, then notify the gateway.
|
|
8
|
+
* 2. **Balance** — read or force-sync the gateway's off-chain credit view.
|
|
9
|
+
* 3. **Pay** — sign a `GenericPayment` EIP-712 message and POST it to the
|
|
10
|
+
* gateway's `/v1/escrow/pay` endpoint.
|
|
11
|
+
*
|
|
12
|
+
* The gateway is the authority on balances; the on-chain contract is the
|
|
13
|
+
* authority on what has been settled. Nothing in this module touches the
|
|
14
|
+
* chain directly — signing is done by the caller's wallet.
|
|
15
|
+
*
|
|
16
|
+
* @category Protocol
|
|
17
|
+
* @module escrow
|
|
18
|
+
*/
|
|
19
|
+
import type { TypedDataDomain } from "viem";
|
|
20
|
+
/**
|
|
21
|
+
* EIP-712 typed-data types for a generic op payment.
|
|
22
|
+
*
|
|
23
|
+
* The gateway verifies that the recovered signer == `payerAddress` and that
|
|
24
|
+
* the (payer, paymentNonce) pair has not been seen before. Use a
|
|
25
|
+
* monotonically-increasing nonce; the first payment for any payer should
|
|
26
|
+
* start at 1.
|
|
27
|
+
*/
|
|
28
|
+
export declare const GENERIC_PAYMENT_TYPES: {
|
|
29
|
+
readonly GenericPayment: readonly [{
|
|
30
|
+
readonly name: "payerAddress";
|
|
31
|
+
readonly type: "address";
|
|
32
|
+
}, {
|
|
33
|
+
readonly name: "opType";
|
|
34
|
+
readonly type: "string";
|
|
35
|
+
}, {
|
|
36
|
+
readonly name: "opId";
|
|
37
|
+
readonly type: "bytes32";
|
|
38
|
+
}, {
|
|
39
|
+
readonly name: "asset";
|
|
40
|
+
readonly type: "address";
|
|
41
|
+
}, {
|
|
42
|
+
readonly name: "amount";
|
|
43
|
+
readonly type: "uint256";
|
|
44
|
+
}, {
|
|
45
|
+
readonly name: "paymentNonce";
|
|
46
|
+
readonly type: "uint256";
|
|
47
|
+
}];
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* EIP-712 message payload for a generic op payment.
|
|
51
|
+
*
|
|
52
|
+
* - `opType` is currently `"grant"`. Additional types (file, builder, schema)
|
|
53
|
+
* may be added in future protocol versions.
|
|
54
|
+
* - `opId` is the bytes32 id of the operation being paid for (e.g. `grantId`).
|
|
55
|
+
* - `asset` is the ERC-20 token address, or the zero address for native VANA.
|
|
56
|
+
* - `amount` is the total amount in base units (wei for VANA). Must match the
|
|
57
|
+
* sum the gateway expects for the current lifecycle of the op.
|
|
58
|
+
* - `paymentNonce` must be a positive integer unique per `payerAddress`. Use 1
|
|
59
|
+
* for the first payment; increment by at least 1 for each subsequent call.
|
|
60
|
+
*/
|
|
61
|
+
export interface GenericPaymentMessage {
|
|
62
|
+
payerAddress: `0x${string}`;
|
|
63
|
+
opType: string;
|
|
64
|
+
opId: `0x${string}`;
|
|
65
|
+
asset: `0x${string}`;
|
|
66
|
+
amount: bigint;
|
|
67
|
+
paymentNonce: bigint;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns the EIP-712 domain for signing a `GenericPayment` message.
|
|
71
|
+
*
|
|
72
|
+
* The verifying contract is the `DataPortabilityEscrow` contract; all gateway
|
|
73
|
+
* deployments share the same domain name and version.
|
|
74
|
+
*
|
|
75
|
+
* @param chainId - Chain ID of the Vana network (e.g. 1480 mainnet, 14800 testnet).
|
|
76
|
+
* @param escrowContract - Deployed address of DataPortabilityEscrow.
|
|
77
|
+
*/
|
|
78
|
+
export declare function genericPaymentDomain(chainId: number, escrowContract: `0x${string}`): TypedDataDomain;
|
|
79
|
+
/**
|
|
80
|
+
* Minimal ABI for the two deposit entry points on `DataPortabilityEscrow`.
|
|
81
|
+
*
|
|
82
|
+
* - `depositNative(address account)` payable — credits native VANA.
|
|
83
|
+
* - `depositToken(address account, address token, uint256 amount)` — credits
|
|
84
|
+
* an ERC-20 token (caller must have pre-approved the escrow contract).
|
|
85
|
+
*
|
|
86
|
+
* Pass this to viem's `writeContract` or encode it manually.
|
|
87
|
+
*/
|
|
88
|
+
export declare const ESCROW_DEPOSIT_ABI: readonly [{
|
|
89
|
+
readonly type: "function";
|
|
90
|
+
readonly name: "depositNative";
|
|
91
|
+
readonly stateMutability: "payable";
|
|
92
|
+
readonly inputs: readonly [{
|
|
93
|
+
readonly name: "account";
|
|
94
|
+
readonly type: "address";
|
|
95
|
+
}];
|
|
96
|
+
readonly outputs: readonly [];
|
|
97
|
+
}, {
|
|
98
|
+
readonly type: "function";
|
|
99
|
+
readonly name: "depositToken";
|
|
100
|
+
readonly stateMutability: "nonpayable";
|
|
101
|
+
readonly inputs: readonly [{
|
|
102
|
+
readonly name: "account";
|
|
103
|
+
readonly type: "address";
|
|
104
|
+
}, {
|
|
105
|
+
readonly name: "token";
|
|
106
|
+
readonly type: "address";
|
|
107
|
+
}, {
|
|
108
|
+
readonly name: "amount";
|
|
109
|
+
readonly type: "uint256";
|
|
110
|
+
}];
|
|
111
|
+
readonly outputs: readonly [];
|
|
112
|
+
}];
|
|
113
|
+
/**
|
|
114
|
+
* The zero address used by the DataPortabilityEscrow contract to represent
|
|
115
|
+
* native VANA in `asset` fields of events and balance responses.
|
|
116
|
+
*/
|
|
117
|
+
export declare const NATIVE_ASSET_ADDRESS: "0x0000000000000000000000000000000000000000";
|
|
118
|
+
/**
|
|
119
|
+
* Per-asset balance entry returned by the gateway's escrow balance endpoints.
|
|
120
|
+
*
|
|
121
|
+
* - `balance` — gross finalized credit (deposits credited so far).
|
|
122
|
+
* - `pendingAmount` — sum of submitted deposits not yet confirmed.
|
|
123
|
+
* - `authorizedAmount` — sum of all in-flight payments authorized by
|
|
124
|
+
* `/v1/escrow/pay` (soft-lock). May include payments not yet settled
|
|
125
|
+
* on-chain.
|
|
126
|
+
* - `availableAmount` — `max(balance − authorizedAmount, 0)`. This is what
|
|
127
|
+
* the payer can authorize before the gateway rejects with 402.
|
|
128
|
+
*/
|
|
129
|
+
export interface EscrowBalanceEntry {
|
|
130
|
+
asset: string;
|
|
131
|
+
balance: string;
|
|
132
|
+
pendingAmount: string;
|
|
133
|
+
authorizedAmount: string;
|
|
134
|
+
availableAmount: string;
|
|
135
|
+
updatedAt: string | null;
|
|
136
|
+
}
|
|
137
|
+
export interface SubmittedDepositEntry {
|
|
138
|
+
txHash: string;
|
|
139
|
+
submittedAt: string;
|
|
140
|
+
claimedAsset: string;
|
|
141
|
+
claimedAmount: string;
|
|
142
|
+
}
|
|
143
|
+
export interface FinalizedDepositEntry {
|
|
144
|
+
txHash: string;
|
|
145
|
+
finalizedAt: string | null;
|
|
146
|
+
blockNumber: string | null;
|
|
147
|
+
claimedAsset: string;
|
|
148
|
+
claimedAmount: string;
|
|
149
|
+
}
|
|
150
|
+
export interface FailedDepositEntry {
|
|
151
|
+
txHash: string;
|
|
152
|
+
submittedAt: string;
|
|
153
|
+
claimedAsset: string;
|
|
154
|
+
claimedAmount: string;
|
|
155
|
+
lastError: string | null;
|
|
156
|
+
}
|
|
157
|
+
/** Full balance read response from `GET /v1/escrow/balance`. */
|
|
158
|
+
export interface EscrowBalanceResult {
|
|
159
|
+
account: string;
|
|
160
|
+
balances: EscrowBalanceEntry[];
|
|
161
|
+
deposits: {
|
|
162
|
+
submitted: SubmittedDepositEntry[];
|
|
163
|
+
finalized: FinalizedDepositEntry[];
|
|
164
|
+
failed: FailedDepositEntry[];
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Response from `POST /v1/escrow/balance/sync`.
|
|
169
|
+
*
|
|
170
|
+
* Extends {@link EscrowBalanceResult} with a `sync` summary of what the
|
|
171
|
+
* lazy-confirmation pass did.
|
|
172
|
+
*/
|
|
173
|
+
export interface EscrowBalanceSyncResult extends EscrowBalanceResult {
|
|
174
|
+
sync: {
|
|
175
|
+
scanned: number;
|
|
176
|
+
finalized: number;
|
|
177
|
+
stillPending: number;
|
|
178
|
+
failed: number;
|
|
179
|
+
} | {
|
|
180
|
+
skipped: true;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** Response from `POST /v1/escrow/deposit`. */
|
|
184
|
+
export interface DepositSubmissionResult {
|
|
185
|
+
success: true;
|
|
186
|
+
txHash: string;
|
|
187
|
+
account: string;
|
|
188
|
+
status: "submitted" | "finalized" | "failed";
|
|
189
|
+
blockNumber?: string | null;
|
|
190
|
+
submittedAt: string;
|
|
191
|
+
finalizedAt?: string | null;
|
|
192
|
+
lastError?: string | null;
|
|
193
|
+
}
|
|
194
|
+
/** Breakdown returned by a successful `POST /v1/escrow/pay`. */
|
|
195
|
+
export interface PaymentBreakdown {
|
|
196
|
+
registrationFee: string;
|
|
197
|
+
dataAccessFee: string;
|
|
198
|
+
/** True when this call settled the registration fee for the op. */
|
|
199
|
+
registrationPaid: boolean;
|
|
200
|
+
}
|
|
201
|
+
/** Response from `POST /v1/escrow/pay`. */
|
|
202
|
+
export interface EscrowPayResult {
|
|
203
|
+
success: true;
|
|
204
|
+
opType: string;
|
|
205
|
+
opId: string;
|
|
206
|
+
payerAddress: string;
|
|
207
|
+
asset: string;
|
|
208
|
+
amount: string;
|
|
209
|
+
breakdown: PaymentBreakdown;
|
|
210
|
+
paymentNonce: string;
|
|
211
|
+
paidAt: string;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Parameters for submitting a deposit tx hash to the gateway.
|
|
215
|
+
*
|
|
216
|
+
* The gateway will decode the `account` from the tx's calldata and
|
|
217
|
+
* credit the identified account once the tx reaches the configured
|
|
218
|
+
* confirmation depth.
|
|
219
|
+
*/
|
|
220
|
+
export interface SubmitDepositParams {
|
|
221
|
+
/** 0x-prefixed 32-byte transaction hash. */
|
|
222
|
+
txHash: `0x${string}`;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Parameters for the generic op payment endpoint (`POST /v1/escrow/pay`).
|
|
226
|
+
*
|
|
227
|
+
* The `signature` is an EIP-712 signature over a `GenericPayment` message
|
|
228
|
+
* (see {@link GENERIC_PAYMENT_TYPES} and {@link genericPaymentDomain}).
|
|
229
|
+
* Build and sign the typed data with your wallet before calling
|
|
230
|
+
* {@link EscrowGatewayClient.payForOp}.
|
|
231
|
+
*/
|
|
232
|
+
export interface PayForOpParams {
|
|
233
|
+
payerAddress: `0x${string}`;
|
|
234
|
+
opType: string;
|
|
235
|
+
opId: `0x${string}`;
|
|
236
|
+
asset: `0x${string}`;
|
|
237
|
+
/** Decimal string representation of the uint256 amount. */
|
|
238
|
+
amount: string;
|
|
239
|
+
/** Decimal string representation of the uint256 nonce. */
|
|
240
|
+
paymentNonce: string;
|
|
241
|
+
/** 0x-prefixed 65-byte EIP-712 signature hex string. */
|
|
242
|
+
signature: `0x${string}`;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Minimal client for the gateway's escrow endpoints.
|
|
246
|
+
*
|
|
247
|
+
* Construct with {@link createEscrowGatewayClient}.
|
|
248
|
+
*/
|
|
249
|
+
export interface EscrowGatewayClient {
|
|
250
|
+
/**
|
|
251
|
+
* Notify the gateway of a submitted deposit transaction.
|
|
252
|
+
*
|
|
253
|
+
* The gateway decodes the credited account from the on-chain tx calldata
|
|
254
|
+
* and starts tracking the deposit. Call this immediately after your
|
|
255
|
+
* `depositNative` or `depositToken` tx is broadcast (it accepts pending
|
|
256
|
+
* mempool txs). Returns `202` while the tx awaits confirmation.
|
|
257
|
+
*/
|
|
258
|
+
submitDeposit(params: SubmitDepositParams): Promise<DepositSubmissionResult>;
|
|
259
|
+
/**
|
|
260
|
+
* Read the current escrow balance for an account.
|
|
261
|
+
*
|
|
262
|
+
* Pure read — no chain calls. To force a reconciliation pass first,
|
|
263
|
+
* use {@link syncEscrowBalance}.
|
|
264
|
+
*/
|
|
265
|
+
getEscrowBalance(account: `0x${string}`): Promise<EscrowBalanceResult>;
|
|
266
|
+
/**
|
|
267
|
+
* Force a reconciliation pass then return the updated balance.
|
|
268
|
+
*
|
|
269
|
+
* Triggers the gateway's lazy-confirmation worker for the account — any
|
|
270
|
+
* submitted deposits that have reached the configured confirmation level
|
|
271
|
+
* are credited before the balance is returned. Prefer this over
|
|
272
|
+
* {@link getEscrowBalance} when you need a fresh view after a deposit.
|
|
273
|
+
*/
|
|
274
|
+
syncEscrowBalance(account: `0x${string}`): Promise<EscrowBalanceSyncResult>;
|
|
275
|
+
/**
|
|
276
|
+
* Authorize a payment against the payer's escrow balance.
|
|
277
|
+
*
|
|
278
|
+
* The caller must:
|
|
279
|
+
* 1. Assemble a {@link GenericPaymentMessage}.
|
|
280
|
+
* 2. Sign it with `signTypedData` using {@link GENERIC_PAYMENT_TYPES} and
|
|
281
|
+
* the domain from {@link genericPaymentDomain}.
|
|
282
|
+
* 3. Pass the message fields + signature here.
|
|
283
|
+
*
|
|
284
|
+
* The gateway verifies the signature, checks the soft-lock balance, and
|
|
285
|
+
* records the payment. Returns 402 if the payer has insufficient balance.
|
|
286
|
+
*/
|
|
287
|
+
payForOp(params: PayForOpParams): Promise<EscrowPayResult>;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Creates a client for the gateway escrow endpoints.
|
|
291
|
+
*
|
|
292
|
+
* @param baseUrl - Base URL of the DP RPC gateway
|
|
293
|
+
* (e.g. `"https://dp.vana.org"`). Trailing slashes are trimmed.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* import {
|
|
298
|
+
* createEscrowGatewayClient,
|
|
299
|
+
* genericPaymentDomain,
|
|
300
|
+
* GENERIC_PAYMENT_TYPES,
|
|
301
|
+
* } from "@opendatalabs/vana-sdk/node";
|
|
302
|
+
*
|
|
303
|
+
* const escrow = createEscrowGatewayClient("https://dp.vana.org");
|
|
304
|
+
*
|
|
305
|
+
* // 1. Submit your deposit tx hash after broadcasting depositNative on-chain
|
|
306
|
+
* const deposit = await escrow.submitDeposit({ txHash: "0xabc…" });
|
|
307
|
+
*
|
|
308
|
+
* // 2. Force-sync and read the updated balance
|
|
309
|
+
* const { balances } = await escrow.syncEscrowBalance("0xpayerAddress");
|
|
310
|
+
*
|
|
311
|
+
* // 3. Sign and authorize a grant payment
|
|
312
|
+
* const sig = await walletClient.signTypedData({
|
|
313
|
+
* domain: genericPaymentDomain(1480, "0xEscrowContract"),
|
|
314
|
+
* types: GENERIC_PAYMENT_TYPES,
|
|
315
|
+
* primaryType: "GenericPayment",
|
|
316
|
+
* message: {
|
|
317
|
+
* payerAddress: "0xpayerAddress",
|
|
318
|
+
* opType: "grant",
|
|
319
|
+
* opId: "0xgrantId",
|
|
320
|
+
* asset: "0x0000000000000000000000000000000000000000",
|
|
321
|
+
* amount: 1000000000000000000n,
|
|
322
|
+
* paymentNonce: 1n,
|
|
323
|
+
* },
|
|
324
|
+
* });
|
|
325
|
+
* const result = await escrow.payForOp({
|
|
326
|
+
* payerAddress: "0xpayerAddress",
|
|
327
|
+
* opType: "grant",
|
|
328
|
+
* opId: "0xgrantId",
|
|
329
|
+
* asset: "0x0000000000000000000000000000000000000000",
|
|
330
|
+
* amount: "1000000000000000000",
|
|
331
|
+
* paymentNonce: "1",
|
|
332
|
+
* signature: sig,
|
|
333
|
+
* });
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
export declare function createEscrowGatewayClient(baseUrl: string): EscrowGatewayClient;
|