@opendatalabs/vana-sdk 3.4.0 → 3.4.1-canary.ba2cfd7
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/index.browser.d.ts +5 -3
- package/dist/index.browser.js +353 -73
- package/dist/index.browser.js.map +3 -3
- package/dist/index.node.cjs +369 -74
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +5 -3
- package/dist/index.node.js +353 -73
- package/dist/index.node.js.map +3 -3
- package/dist/protocol/eip712.cjs +58 -3
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +98 -6
- package/dist/protocol/eip712.js +52 -3
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/escrow-deposit.cjs +89 -0
- package/dist/protocol/escrow-deposit.cjs.map +1 -0
- package/dist/protocol/escrow-deposit.d.ts +47 -0
- package/dist/protocol/escrow-deposit.js +60 -0
- package/dist/protocol/escrow-deposit.js.map +1 -0
- package/dist/protocol/escrow-deposit.test.d.ts +1 -0
- package/dist/protocol/escrow-flow.test.d.ts +21 -0
- package/dist/protocol/fee-registry.cjs +116 -0
- package/dist/protocol/fee-registry.cjs.map +1 -0
- package/dist/protocol/fee-registry.d.ts +151 -0
- package/dist/protocol/fee-registry.js +89 -0
- package/dist/protocol/fee-registry.js.map +1 -0
- package/dist/protocol/fee-registry.test.d.ts +1 -0
- package/dist/protocol/gateway.cjs +130 -7
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +213 -16
- package/dist/protocol/gateway.js +130 -7
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/grants.cjs +24 -64
- package/dist/protocol/grants.cjs.map +1 -1
- package/dist/protocol/grants.d.ts +6 -13
- package/dist/protocol/grants.js +24 -63
- package/dist/protocol/grants.js.map +1 -1
- package/package.json +3 -2
package/dist/protocol/grants.js
CHANGED
|
@@ -16,67 +16,31 @@ function isDataPortabilityGatewayConfig(value) {
|
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
18
|
const c = contracts;
|
|
19
|
-
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
|
|
19
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
let parsed;
|
|
21
|
+
function toUint256(value) {
|
|
23
22
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
const value = parsed;
|
|
32
|
-
if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
if (!value["scopes"].every((scope) => typeof scope === "string")) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
if (value["user"] !== void 0 && !isHexString(value["user"])) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
user: value["user"],
|
|
52
|
-
builder: value["builder"],
|
|
53
|
-
scopes: value["scopes"],
|
|
54
|
-
expiresAt: value["expiresAt"],
|
|
55
|
-
nonce: value["nonce"]
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function parseFileIds(fileIds) {
|
|
59
|
-
try {
|
|
60
|
-
const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
|
|
61
|
-
return {
|
|
62
|
-
values,
|
|
63
|
-
display: values.map((fileId) => fileId.toString())
|
|
64
|
-
};
|
|
23
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
24
|
+
if (big < 0n) return null;
|
|
25
|
+
return big;
|
|
65
26
|
} catch {
|
|
66
27
|
return null;
|
|
67
28
|
}
|
|
68
29
|
}
|
|
69
30
|
async function verifyGrantRegistration(input) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
valid: false,
|
|
74
|
-
error: "Grant must be JSON with scopes and expiresAt"
|
|
75
|
-
};
|
|
31
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
32
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
76
33
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
34
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
35
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
36
|
+
}
|
|
37
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
38
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
39
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
40
|
+
}
|
|
41
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
42
|
+
if (expiresAt === null) {
|
|
43
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
80
44
|
}
|
|
81
45
|
let valid;
|
|
82
46
|
try {
|
|
@@ -88,8 +52,9 @@ async function verifyGrantRegistration(input) {
|
|
|
88
52
|
message: {
|
|
89
53
|
grantorAddress: input.grantorAddress,
|
|
90
54
|
granteeId: input.granteeId,
|
|
91
|
-
|
|
92
|
-
|
|
55
|
+
scopes: input.scopes,
|
|
56
|
+
grantVersion,
|
|
57
|
+
expiresAt
|
|
93
58
|
},
|
|
94
59
|
signature: input.signature
|
|
95
60
|
});
|
|
@@ -100,24 +65,20 @@ async function verifyGrantRegistration(input) {
|
|
|
100
65
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
101
66
|
}
|
|
102
67
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
103
|
-
if (
|
|
68
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
104
69
|
return { valid: false, error: "Grant has expired" };
|
|
105
70
|
}
|
|
106
|
-
if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
|
|
107
|
-
return { valid: false, error: "Grant user does not match grantorAddress" };
|
|
108
|
-
}
|
|
109
71
|
return {
|
|
110
72
|
valid: true,
|
|
111
73
|
grantorAddress: input.grantorAddress,
|
|
112
74
|
granteeId: input.granteeId,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
75
|
+
scopes: input.scopes,
|
|
76
|
+
grantVersion: grantVersion.toString(),
|
|
77
|
+
expiresAt: expiresAt.toString()
|
|
116
78
|
};
|
|
117
79
|
}
|
|
118
80
|
export {
|
|
119
81
|
isDataPortabilityGatewayConfig,
|
|
120
|
-
parseGrantRegistrationPayload,
|
|
121
82
|
verifyGrantRegistration
|
|
122
83
|
};
|
|
123
84
|
//# sourceMappingURL=grants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/protocol/grants.ts"],"sourcesContent":["import { verifyTypedData } from \"viem\";\nimport {\n GRANT_REGISTRATION_TYPES,\n grantRegistrationDomain,\n type DataPortabilityGatewayConfig,\n} from \"./eip712\";\n\nexport interface
|
|
1
|
+
{"version":3,"sources":["../../src/protocol/grants.ts"],"sourcesContent":["import { verifyTypedData } from \"viem\";\nimport {\n GRANT_REGISTRATION_TYPES,\n grantRegistrationDomain,\n type DataPortabilityGatewayConfig,\n} from \"./eip712\";\n\nexport interface VerifyGrantRegistrationInput {\n gatewayConfig: DataPortabilityGatewayConfig;\n grantorAddress: `0x${string}`;\n granteeId: `0x${string}`;\n scopes: string[];\n // Decimal-string uint256 is the wire format; bigint/number are accepted\n // for ergonomics. Must be >= 1 (first registration uses 1; each override\n // strictly increases it — see GRANT_REGISTRATION_TYPES).\n grantVersion: bigint | number | string;\n // Unix seconds. 0 = no expiry. Anything > 0 is enforced against nowSeconds.\n expiresAt: bigint | number | string;\n signature: `0x${string}`;\n nowSeconds?: number;\n}\n\nexport type VerifyGrantRegistrationResult =\n | {\n valid: true;\n grantorAddress: `0x${string}`;\n granteeId: `0x${string}`;\n scopes: string[];\n grantVersion: string;\n expiresAt: string;\n }\n | {\n valid: false;\n error: string;\n };\n\nfunction isHexString(value: unknown): value is `0x${string}` {\n return typeof value === \"string\" && value.startsWith(\"0x\");\n}\n\nexport function isDataPortabilityGatewayConfig(\n value: unknown,\n): value is DataPortabilityGatewayConfig {\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n return false;\n }\n const config = value as Record<string, unknown>;\n const contracts = config[\"contracts\"];\n if (\n typeof config[\"chainId\"] !== \"number\" ||\n !Number.isInteger(config[\"chainId\"]) ||\n config[\"chainId\"] <= 0 ||\n contracts === null ||\n typeof contracts !== \"object\" ||\n Array.isArray(contracts)\n ) {\n return false;\n }\n const c = contracts as Record<string, unknown>;\n return (\n isHexString(c[\"dataRegistry\"]) &&\n isHexString(c[\"dataPortabilityPermissions\"]) &&\n isHexString(c[\"dataPortabilityServer\"]) &&\n isHexString(c[\"dataPortabilityGrantees\"]) &&\n isHexString(c[\"dataPortabilityEscrow\"]) &&\n isHexString(c[\"feeRegistry\"])\n );\n}\n\nfunction toUint256(value: bigint | number | string): bigint | null {\n try {\n const big = typeof value === \"bigint\" ? value : BigInt(value);\n if (big < 0n) return null;\n return big;\n } catch {\n return null;\n }\n}\n\nexport async function verifyGrantRegistration(\n input: VerifyGrantRegistrationInput,\n): Promise<VerifyGrantRegistrationResult> {\n if (!Array.isArray(input.scopes) || input.scopes.length === 0) {\n return { valid: false, error: \"scopes must be a non-empty array\" };\n }\n if (!input.scopes.every((scope) => typeof scope === \"string\")) {\n return { valid: false, error: \"scopes must contain only strings\" };\n }\n\n const grantVersion = toUint256(input.grantVersion);\n if (grantVersion === null || grantVersion < 1n) {\n return { valid: false, error: \"grantVersion must be a uint256 >= 1\" };\n }\n\n const expiresAt = toUint256(input.expiresAt);\n if (expiresAt === null) {\n return { valid: false, error: \"expiresAt must be a non-negative uint256\" };\n }\n\n let valid: boolean;\n try {\n valid = await verifyTypedData({\n address: input.grantorAddress,\n domain: grantRegistrationDomain(input.gatewayConfig),\n types: GRANT_REGISTRATION_TYPES,\n primaryType: \"GrantRegistration\",\n message: {\n grantorAddress: input.grantorAddress,\n granteeId: input.granteeId,\n scopes: input.scopes,\n grantVersion,\n expiresAt,\n },\n signature: input.signature,\n });\n } catch {\n return { valid: false, error: \"EIP-712 signature verification failed\" };\n }\n\n if (!valid) {\n return { valid: false, error: \"Grant signature does not match grantor\" };\n }\n\n // 0 is the \"no expiry\" sentinel — only enforce when expiresAt > 0.\n const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1000);\n if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {\n return { valid: false, error: \"Grant has expired\" };\n }\n\n return {\n valid: true,\n grantorAddress: input.grantorAddress,\n granteeId: input.granteeId,\n scopes: input.scopes,\n grantVersion: grantVersion.toString(),\n expiresAt: expiresAt.toString(),\n };\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AA+BP,SAAS,YAAY,OAAwC;AAC3D,SAAO,OAAO,UAAU,YAAY,MAAM,WAAW,IAAI;AAC3D;AAEO,SAAS,+BACd,OACuC;AACvC,MAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;AACvE,WAAO;AAAA,EACT;AACA,QAAM,SAAS;AACf,QAAM,YAAY,OAAO,WA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AM,aAAa;AAAA,MACnD,OAAO;AAAA,MACP,aAAa;AAAA,MACb,SAAS;AAAA,QACP,gBAAgB,MAAM;AAAA,QACtB,WAAW,MAAM;AAAA,QACjB,QAAQ,MAAM;AAAA,QACd;AAAA,QACA;AAAA,MACF;AAAA,MACA,WAAW,MAAM;AAAA,IACnB,CAAC;AAAA,EACH,QAAQ;AACN,WAAO,EAAE,OAAO,OAAO,OAAO,wCAAwC;AAAA,EACxE;AAEA,MAAI,CAAC,OAAO;AACV,WAAO,EAAE,OAAO,OAAO,OAAO,yCAAyC;AAAA,EACzE;AAGA,QAAM,aAAa,MAAM,cAAc,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AACnE,MAAI,YAAY,MAAM,YAAY,OAAO,UAAU,GAAG;AACpD,WAAO,EAAE,OAAO,OAAO,OAAO,oBAAoB;AAAA,EACpD;AAEA,SAAO;AAAA,IACL,OAAO;AAAA,IACP,gBAAgB,MAAM;AAAA,IACtB,WAAW,MAAM;AAAA,IACjB,QAAQ,MAAM;AAAA,IACd,cAAc,aAAa,SAAS;AAAA,IACpC,WAAW,UAAU,SAAS;AAAA,EAChC;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opendatalabs/vana-sdk",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.1-canary.ba2cfd7",
|
|
4
4
|
"description": "A TypeScript library for interacting with Vana Network smart contracts.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -101,7 +101,8 @@
|
|
|
101
101
|
"test:coverage:verbose": "vitest run --coverage --reporter=verbose --coverage.reporter=text",
|
|
102
102
|
"discover-addresses": "tsx scripts/discover-addresses.ts",
|
|
103
103
|
"fetch-abis": "tsx scripts/fetch-abis.ts",
|
|
104
|
-
"generate": "npm run discover-addresses && npm run fetch-abis"
|
|
104
|
+
"generate": "npm run discover-addresses && npm run fetch-abis",
|
|
105
|
+
"e2e:deposit": "tsx scripts/e2e-escrow-deposit.ts"
|
|
105
106
|
},
|
|
106
107
|
"keywords": [
|
|
107
108
|
"vana",
|