@opendatalabs/vana-sdk 3.4.1 → 3.5.1-pr.159.12a6f39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -0
- package/dist/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/direct/access-request-client.cjs +104 -0
- package/dist/direct/access-request-client.cjs.map +1 -0
- package/dist/direct/access-request-client.d.ts +51 -0
- package/dist/direct/access-request-client.js +79 -0
- package/dist/direct/access-request-client.js.map +1 -0
- package/dist/direct/access-request-client.test.d.ts +1 -0
- package/dist/direct/connect-flow.cjs +152 -0
- package/dist/direct/connect-flow.cjs.map +1 -0
- package/dist/direct/connect-flow.d.ts +85 -0
- package/dist/direct/connect-flow.js +128 -0
- package/dist/direct/connect-flow.js.map +1 -0
- package/dist/direct/connect-flow.test.d.ts +1 -0
- package/dist/direct/controller.cjs +129 -0
- package/dist/direct/controller.cjs.map +1 -0
- package/dist/direct/controller.d.ts +152 -0
- package/dist/direct/controller.js +109 -0
- package/dist/direct/controller.js.map +1 -0
- package/dist/direct/controller.test.d.ts +1 -0
- package/dist/direct/endpoints.cjs +45 -0
- package/dist/direct/endpoints.cjs.map +1 -0
- package/dist/direct/endpoints.d.ts +22 -0
- package/dist/direct/endpoints.js +19 -0
- package/dist/direct/endpoints.js.map +1 -0
- package/dist/direct/errors.cjs +65 -0
- package/dist/direct/errors.cjs.map +1 -0
- package/dist/direct/errors.d.ts +44 -0
- package/dist/direct/errors.js +38 -0
- package/dist/direct/errors.js.map +1 -0
- package/dist/direct/escrow-payment.cjs +96 -0
- package/dist/direct/escrow-payment.cjs.map +1 -0
- package/dist/direct/escrow-payment.d.ts +81 -0
- package/dist/direct/escrow-payment.js +72 -0
- package/dist/direct/escrow-payment.js.map +1 -0
- package/dist/direct/escrow-payment.test.d.ts +1 -0
- package/dist/direct/personal-server-read.cjs +149 -0
- package/dist/direct/personal-server-read.cjs.map +1 -0
- package/dist/direct/personal-server-read.d.ts +103 -0
- package/dist/direct/personal-server-read.js +124 -0
- package/dist/direct/personal-server-read.js.map +1 -0
- package/dist/direct/personal-server-read.test.d.ts +1 -0
- package/dist/direct/types.cjs +35 -0
- package/dist/direct/types.cjs.map +1 -0
- package/dist/direct/types.d.ts +205 -0
- package/dist/direct/types.js +11 -0
- package/dist/direct/types.js.map +1 -0
- package/dist/direct/use-direct-vana-connect.cjs +68 -0
- package/dist/direct/use-direct-vana-connect.cjs.map +1 -0
- package/dist/direct/use-direct-vana-connect.d.ts +45 -0
- package/dist/direct/use-direct-vana-connect.js +46 -0
- package/dist/direct/use-direct-vana-connect.js.map +1 -0
- package/dist/index.browser.d.ts +9 -4
- package/dist/index.browser.js +644 -178
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +672 -183
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +9 -4
- package/dist/index.node.js +644 -178
- package/dist/index.node.js.map +4 -4
- package/dist/personal-server-lite/owner-binding.cjs +93 -0
- package/dist/personal-server-lite/owner-binding.cjs.map +1 -0
- package/dist/personal-server-lite/owner-binding.d.ts +44 -0
- package/dist/personal-server-lite/owner-binding.js +65 -0
- package/dist/personal-server-lite/owner-binding.js.map +1 -0
- package/dist/personal-server-lite/owner-binding.test.d.ts +1 -0
- package/dist/protocol/data-point-status.cjs +80 -0
- package/dist/protocol/data-point-status.cjs.map +1 -0
- package/dist/protocol/data-point-status.d.ts +34 -0
- package/dist/protocol/data-point-status.js +51 -0
- package/dist/protocol/data-point-status.js.map +1 -0
- package/dist/protocol/data-point-status.test.d.ts +1 -0
- package/dist/protocol/eip712.cjs +53 -31
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +98 -43
- package/dist/protocol/eip712.js +47 -27
- 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/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/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 +107 -37
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +223 -57
- package/dist/protocol/gateway.js +107 -37
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/grants.cjs +27 -64
- package/dist/protocol/grants.cjs.map +1 -1
- package/dist/protocol/grants.d.ts +6 -13
- package/dist/protocol/grants.js +27 -63
- package/dist/protocol/grants.js.map +1 -1
- package/dist/protocol/personal-server-data.cjs +71 -0
- package/dist/protocol/personal-server-data.cjs.map +1 -0
- package/dist/protocol/personal-server-data.d.ts +16 -0
- package/dist/protocol/personal-server-data.js +47 -0
- package/dist/protocol/personal-server-data.js.map +1 -0
- package/dist/protocol/personal-server-data.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/react.cjs +32 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.ts +33 -0
- package/dist/react.js +11 -0
- package/dist/react.js.map +1 -0
- package/dist/server.cjs +73 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.ts +32 -0
- package/dist/server.js +55 -0
- package/dist/server.js.map +1 -0
- 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 +20 -1
package/dist/protocol/grants.js
CHANGED
|
@@ -16,67 +16,34 @@ 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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return
|
|
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
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
27
|
+
if (big < 0n) return null;
|
|
28
|
+
return big;
|
|
65
29
|
} catch {
|
|
66
30
|
return null;
|
|
67
31
|
}
|
|
68
32
|
}
|
|
69
33
|
async function verifyGrantRegistration(input) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
valid: false,
|
|
74
|
-
error: "Grant must be JSON with scopes and expiresAt"
|
|
75
|
-
};
|
|
34
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
35
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
76
36
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
37
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
38
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
39
|
+
}
|
|
40
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
41
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
42
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
43
|
+
}
|
|
44
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
45
|
+
if (expiresAt === null) {
|
|
46
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
80
47
|
}
|
|
81
48
|
let valid;
|
|
82
49
|
try {
|
|
@@ -88,8 +55,9 @@ async function verifyGrantRegistration(input) {
|
|
|
88
55
|
message: {
|
|
89
56
|
grantorAddress: input.grantorAddress,
|
|
90
57
|
granteeId: input.granteeId,
|
|
91
|
-
|
|
92
|
-
|
|
58
|
+
scopes: input.scopes,
|
|
59
|
+
grantVersion,
|
|
60
|
+
expiresAt
|
|
93
61
|
},
|
|
94
62
|
signature: input.signature
|
|
95
63
|
});
|
|
@@ -100,24 +68,20 @@ async function verifyGrantRegistration(input) {
|
|
|
100
68
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
101
69
|
}
|
|
102
70
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
103
|
-
if (
|
|
71
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
104
72
|
return { valid: false, error: "Grant has expired" };
|
|
105
73
|
}
|
|
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
74
|
return {
|
|
110
75
|
valid: true,
|
|
111
76
|
grantorAddress: input.grantorAddress,
|
|
112
77
|
granteeId: input.granteeId,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
78
|
+
scopes: input.scopes,
|
|
79
|
+
grantVersion: grantVersion.toString(),
|
|
80
|
+
expiresAt: expiresAt.toString()
|
|
116
81
|
};
|
|
117
82
|
}
|
|
118
83
|
export {
|
|
119
84
|
isDataPortabilityGatewayConfig,
|
|
120
|
-
parseGrantRegistrationPayload,
|
|
121
85
|
verifyGrantRegistration
|
|
122
86
|
};
|
|
123
87
|
//# 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 // Reject `number` inputs outside the safe-integer range — `BigInt(2**53 + 1)`\n // doesn't throw, it just converts whatever rounded value JS already stored,\n // which would silently corrupt grantVersion/expiresAt for any uint256 large\n // enough to lose precision in a double. Callers that need values past\n // `MAX_SAFE_INTEGER` must pass a string or bigint.\n if (typeof value === \"number\" && !Number.isSafeInteger(value)) {\n return null;\n }\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,WAAW;AACpC,MACE,OAAO,OAAO,SAAS,MAAM,YAC7B,CAAC,OAAO,UAAU,OAAO,SAAS,CAAC,KACnC,OAAO,SAAS,KAAK,KACrB,cAAc,QACd,OAAO,cAAc,YACrB,MAAM,QAAQ,SAAS,GACvB;AACA,WAAO;AAAA,EACT;AACA,QAAM,IAAI;AACV,SACE,YAAY,EAAE,cAAc,CAAC,KAC7B,YAAY,EAAE,4BAA4B,CAAC,KAC3C,YAAY,EAAE,uBAAuB,CAAC,KACtC,YAAY,EAAE,yBAAyB,CAAC,KACxC,YAAY,EAAE,uBAAuB,CAAC,KACtC,YAAY,EAAE,aAAa,CAAC;AAEhC;AAEA,SAAS,UAAU,OAAgD;AACjE,MAAI;AAMF,QAAI,OAAO,UAAU,YAAY,CAAC,OAAO,cAAc,KAAK,GAAG;AAC7D,aAAO;AAAA,IACT;AACA,UAAM,MAAM,OAAO,UAAU,WAAW,QAAQ,OAAO,KAAK;AAC5D,QAAI,MAAM,GAAI,QAAO;AACrB,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,eAAsB,wBACpB,OACwC;AACxC,MAAI,CAAC,MAAM,QAAQ,MAAM,MAAM,KAAK,MAAM,OAAO,WAAW,GAAG;AAC7D,WAAO,EAAE,OAAO,OAAO,OAAO,mCAAmC;AAAA,EACnE;AACA,MAAI,CAAC,MAAM,OAAO,MAAM,CAAC,UAAU,OAAO,UAAU,QAAQ,GAAG;AAC7D,WAAO,EAAE,OAAO,OAAO,OAAO,mCAAmC;AAAA,EACnE;AAEA,QAAM,eAAe,UAAU,MAAM,YAAY;AACjD,MAAI,iBAAiB,QAAQ,eAAe,IAAI;AAC9C,WAAO,EAAE,OAAO,OAAO,OAAO,sCAAsC;AAAA,EACtE;AAEA,QAAM,YAAY,UAAU,MAAM,SAAS;AAC3C,MAAI,cAAc,MAAM;AACtB,WAAO,EAAE,OAAO,OAAO,OAAO,2CAA2C;AAAA,EAC3E;AAEA,MAAI;AACJ,MAAI;AACF,YAAQ,MAAM,gBAAgB;AAAA,MAC5B,SAAS,MAAM;AAAA,MACf,QAAQ,wBAAwB,MAAM,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":[]}
|
|
@@ -0,0 +1,71 @@
|
|
|
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 personal_server_data_exports = {};
|
|
20
|
+
__export(personal_server_data_exports, {
|
|
21
|
+
buildPersonalServerDataReadRequest: () => buildPersonalServerDataReadRequest,
|
|
22
|
+
personalServerDataReadPath: () => personalServerDataReadPath,
|
|
23
|
+
readPersonalServerData: () => readPersonalServerData
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(personal_server_data_exports);
|
|
26
|
+
var import_web3_signed_builder = require("../auth/web3-signed-builder");
|
|
27
|
+
var import_data_file = require("./data-file");
|
|
28
|
+
function personalServerDataReadPath(scope) {
|
|
29
|
+
return `/v1/data/${encodeURIComponent(scope)}`;
|
|
30
|
+
}
|
|
31
|
+
async function buildPersonalServerDataReadRequest(params) {
|
|
32
|
+
const path = personalServerDataReadPath(params.scope);
|
|
33
|
+
const baseUrl = params.personalServerUrl.replace(/\/+$/, "");
|
|
34
|
+
const audience = params.audience ?? baseUrl;
|
|
35
|
+
const headers = new Headers(params.headers);
|
|
36
|
+
headers.set(
|
|
37
|
+
"Authorization",
|
|
38
|
+
await (0, import_web3_signed_builder.buildWeb3SignedHeader)({
|
|
39
|
+
aud: audience,
|
|
40
|
+
grantId: params.grantId,
|
|
41
|
+
method: "GET",
|
|
42
|
+
signMessage: params.signMessage,
|
|
43
|
+
uri: path
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
return new Request(`${baseUrl}${path}`, {
|
|
47
|
+
headers,
|
|
48
|
+
method: "GET"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async function readPersonalServerData(params) {
|
|
52
|
+
const fetchFn = params.fetch ?? globalThis.fetch;
|
|
53
|
+
if (fetchFn === void 0) {
|
|
54
|
+
throw new Error("No fetch implementation available");
|
|
55
|
+
}
|
|
56
|
+
const request = await buildPersonalServerDataReadRequest(params);
|
|
57
|
+
const response = await fetchFn(request);
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Personal Server data read failed: ${response.status} ${response.statusText}`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return import_data_file.DataFileEnvelopeSchema.parse(await response.json());
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
buildPersonalServerDataReadRequest,
|
|
68
|
+
personalServerDataReadPath,
|
|
69
|
+
readPersonalServerData
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=personal-server-data.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/protocol/personal-server-data.ts"],"sourcesContent":["import {\n buildWeb3SignedHeader,\n type Web3SignedSignFn,\n} from \"../auth/web3-signed-builder\";\nimport { DataFileEnvelopeSchema, type DataFileEnvelope } from \"./data-file\";\n\nexport interface BuildPersonalServerDataReadRequestParams {\n personalServerUrl: string;\n scope: string;\n grantId: string;\n signMessage: Web3SignedSignFn;\n audience?: string;\n headers?: HeadersInit;\n}\n\nexport interface ReadPersonalServerDataParams extends BuildPersonalServerDataReadRequestParams {\n fetch?: typeof fetch;\n}\n\nexport function personalServerDataReadPath(scope: string): string {\n return `/v1/data/${encodeURIComponent(scope)}`;\n}\n\nexport async function buildPersonalServerDataReadRequest(\n params: BuildPersonalServerDataReadRequestParams,\n): Promise<Request> {\n const path = personalServerDataReadPath(params.scope);\n const baseUrl = params.personalServerUrl.replace(/\\/+$/, \"\");\n const audience = params.audience ?? baseUrl;\n const headers = new Headers(params.headers);\n\n headers.set(\n \"Authorization\",\n await buildWeb3SignedHeader({\n aud: audience,\n grantId: params.grantId,\n method: \"GET\",\n signMessage: params.signMessage,\n uri: path,\n }),\n );\n\n return new Request(`${baseUrl}${path}`, {\n headers,\n method: \"GET\",\n });\n}\n\nexport async function readPersonalServerData(\n params: ReadPersonalServerDataParams,\n): Promise<DataFileEnvelope> {\n const fetchFn = params.fetch ?? globalThis.fetch;\n if (fetchFn === undefined) {\n throw new Error(\"No fetch implementation available\");\n }\n\n const request = await buildPersonalServerDataReadRequest(params);\n const response = await fetchFn(request);\n\n if (!response.ok) {\n throw new Error(\n `Personal Server data read failed: ${response.status} ${response.statusText}`,\n );\n }\n\n return DataFileEnvelopeSchema.parse(await response.json());\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAGO;AACP,uBAA8D;AAevD,SAAS,2BAA2B,OAAuB;AAChE,SAAO,YAAY,mBAAmB,KAAK,CAAC;AAC9C;AAEA,eAAsB,mCACpB,QACkB;AAClB,QAAM,OAAO,2BAA2B,OAAO,KAAK;AACpD,QAAM,UAAU,OAAO,kBAAkB,QAAQ,QAAQ,EAAE;AAC3D,QAAM,WAAW,OAAO,YAAY;AACpC,QAAM,UAAU,IAAI,QAAQ,OAAO,OAAO;AAE1C,UAAQ;AAAA,IACN;AAAA,IACA,UAAM,kDAAsB;AAAA,MAC1B,KAAK;AAAA,MACL,SAAS,OAAO;AAAA,MAChB,QAAQ;AAAA,MACR,aAAa,OAAO;AAAA,MACpB,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AAEA,SAAO,IAAI,QAAQ,GAAG,OAAO,GAAG,IAAI,IAAI;AAAA,IACtC;AAAA,IACA,QAAQ;AAAA,EACV,CAAC;AACH;AAEA,eAAsB,uBACpB,QAC2B;AAC3B,QAAM,UAAU,OAAO,SAAS,WAAW;AAC3C,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AAEA,QAAM,UAAU,MAAM,mCAAmC,MAAM;AAC/D,QAAM,WAAW,MAAM,QAAQ,OAAO;AAEtC,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,IAAI;AAAA,MACR,qCAAqC,SAAS,MAAM,IAAI,SAAS,UAAU;AAAA,IAC7E;AAAA,EACF;AAEA,SAAO,wCAAuB,MAAM,MAAM,SAAS,KAAK,CAAC;AAC3D;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Web3SignedSignFn } from "../auth/web3-signed-builder";
|
|
2
|
+
import { type DataFileEnvelope } from "./data-file";
|
|
3
|
+
export interface BuildPersonalServerDataReadRequestParams {
|
|
4
|
+
personalServerUrl: string;
|
|
5
|
+
scope: string;
|
|
6
|
+
grantId: string;
|
|
7
|
+
signMessage: Web3SignedSignFn;
|
|
8
|
+
audience?: string;
|
|
9
|
+
headers?: HeadersInit;
|
|
10
|
+
}
|
|
11
|
+
export interface ReadPersonalServerDataParams extends BuildPersonalServerDataReadRequestParams {
|
|
12
|
+
fetch?: typeof fetch;
|
|
13
|
+
}
|
|
14
|
+
export declare function personalServerDataReadPath(scope: string): string;
|
|
15
|
+
export declare function buildPersonalServerDataReadRequest(params: BuildPersonalServerDataReadRequestParams): Promise<Request>;
|
|
16
|
+
export declare function readPersonalServerData(params: ReadPersonalServerDataParams): Promise<DataFileEnvelope>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildWeb3SignedHeader
|
|
3
|
+
} from "../auth/web3-signed-builder.js";
|
|
4
|
+
import { DataFileEnvelopeSchema } from "./data-file.js";
|
|
5
|
+
function personalServerDataReadPath(scope) {
|
|
6
|
+
return `/v1/data/${encodeURIComponent(scope)}`;
|
|
7
|
+
}
|
|
8
|
+
async function buildPersonalServerDataReadRequest(params) {
|
|
9
|
+
const path = personalServerDataReadPath(params.scope);
|
|
10
|
+
const baseUrl = params.personalServerUrl.replace(/\/+$/, "");
|
|
11
|
+
const audience = params.audience ?? baseUrl;
|
|
12
|
+
const headers = new Headers(params.headers);
|
|
13
|
+
headers.set(
|
|
14
|
+
"Authorization",
|
|
15
|
+
await buildWeb3SignedHeader({
|
|
16
|
+
aud: audience,
|
|
17
|
+
grantId: params.grantId,
|
|
18
|
+
method: "GET",
|
|
19
|
+
signMessage: params.signMessage,
|
|
20
|
+
uri: path
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
return new Request(`${baseUrl}${path}`, {
|
|
24
|
+
headers,
|
|
25
|
+
method: "GET"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async function readPersonalServerData(params) {
|
|
29
|
+
const fetchFn = params.fetch ?? globalThis.fetch;
|
|
30
|
+
if (fetchFn === void 0) {
|
|
31
|
+
throw new Error("No fetch implementation available");
|
|
32
|
+
}
|
|
33
|
+
const request = await buildPersonalServerDataReadRequest(params);
|
|
34
|
+
const response = await fetchFn(request);
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Personal Server data read failed: ${response.status} ${response.statusText}`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return DataFileEnvelopeSchema.parse(await response.json());
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
buildPersonalServerDataReadRequest,
|
|
44
|
+
personalServerDataReadPath,
|
|
45
|
+
readPersonalServerData
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=personal-server-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/protocol/personal-server-data.ts"],"sourcesContent":["import {\n buildWeb3SignedHeader,\n type Web3SignedSignFn,\n} from \"../auth/web3-signed-builder\";\nimport { DataFileEnvelopeSchema, type DataFileEnvelope } from \"./data-file\";\n\nexport interface BuildPersonalServerDataReadRequestParams {\n personalServerUrl: string;\n scope: string;\n grantId: string;\n signMessage: Web3SignedSignFn;\n audience?: string;\n headers?: HeadersInit;\n}\n\nexport interface ReadPersonalServerDataParams extends BuildPersonalServerDataReadRequestParams {\n fetch?: typeof fetch;\n}\n\nexport function personalServerDataReadPath(scope: string): string {\n return `/v1/data/${encodeURIComponent(scope)}`;\n}\n\nexport async function buildPersonalServerDataReadRequest(\n params: BuildPersonalServerDataReadRequestParams,\n): Promise<Request> {\n const path = personalServerDataReadPath(params.scope);\n const baseUrl = params.personalServerUrl.replace(/\\/+$/, \"\");\n const audience = params.audience ?? baseUrl;\n const headers = new Headers(params.headers);\n\n headers.set(\n \"Authorization\",\n await buildWeb3SignedHeader({\n aud: audience,\n grantId: params.grantId,\n method: \"GET\",\n signMessage: params.signMessage,\n uri: path,\n }),\n );\n\n return new Request(`${baseUrl}${path}`, {\n headers,\n method: \"GET\",\n });\n}\n\nexport async function readPersonalServerData(\n params: ReadPersonalServerDataParams,\n): Promise<DataFileEnvelope> {\n const fetchFn = params.fetch ?? globalThis.fetch;\n if (fetchFn === undefined) {\n throw new Error(\"No fetch implementation available\");\n }\n\n const request = await buildPersonalServerDataReadRequest(params);\n const response = await fetchFn(request);\n\n if (!response.ok) {\n throw new Error(\n `Personal Server data read failed: ${response.status} ${response.statusText}`,\n );\n }\n\n return DataFileEnvelopeSchema.parse(await response.json());\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,OAEK;AACP,SAAS,8BAAqD;AAevD,SAAS,2BAA2B,OAAuB;AAChE,SAAO,YAAY,mBAAmB,KAAK,CAAC;AAC9C;AAEA,eAAsB,mCACpB,QACkB;AAClB,QAAM,OAAO,2BAA2B,OAAO,KAAK;AACpD,QAAM,UAAU,OAAO,kBAAkB,QAAQ,QAAQ,EAAE;AAC3D,QAAM,WAAW,OAAO,YAAY;AACpC,QAAM,UAAU,IAAI,QAAQ,OAAO,OAAO;AAE1C,UAAQ;AAAA,IACN;AAAA,IACA,MAAM,sBAAsB;AAAA,MAC1B,KAAK;AAAA,MACL,SAAS,OAAO;AAAA,MAChB,QAAQ;AAAA,MACR,aAAa,OAAO;AAAA,MACpB,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AAEA,SAAO,IAAI,QAAQ,GAAG,OAAO,GAAG,IAAI,IAAI;AAAA,IACtC;AAAA,IACA,QAAQ;AAAA,EACV,CAAC;AACH;AAEA,eAAsB,uBACpB,QAC2B;AAC3B,QAAM,UAAU,OAAO,SAAS,WAAW;AAC3C,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AAEA,QAAM,UAAU,MAAM,mCAAmC,MAAM;AAC/D,QAAM,WAAW,MAAM,QAAQ,OAAO;AAEtC,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,IAAI;AAAA,MACR,qCAAqC,SAAS,MAAM,IAAI,SAAS,UAAU;AAAA,IAC7E;AAAA,EACF;AAEA,SAAO,uBAAuB,MAAM,MAAM,SAAS,KAAK,CAAC;AAC3D;","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
|
-
|
|
33
|
-
|
|
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
|
|
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
|
|
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
|
|
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;AACzD;AAEA,SAAS,mCACP,QAC4C;AAC5C,SAAO,aAAa,UAAU,OAAO,OAAO,kBAAkB;AAChE;AAEA,SAAS,qCAAqC,SAA0B;AACtE,aAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;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,UACJ,MAAM,WAAW;AACnB,QAAM,oBACJ,MAAM,qBAAqB,qCAAqC,OAAO;AACzE,gBAAc,mBAAmB,mBAAmB;AAEpD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IACA;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":[]}
|
|
@@ -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
|
-
|
|
13
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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
|
|
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
|
|
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
|
|
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,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;AAEA,SAAS,qCAAqC,SAA0B;AACtE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;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,WAAO,yBAAyB,MAAM,MAAM;AAAA,EAC9C;AAEA,QAAM,UACJ,MAAM,WAAW;AACnB,QAAM,oBACJ,MAAM,qBAAqB,qCAAqC,OAAO;AACzE,gBAAc,mBAAmB,mBAAmB;AAEpD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IACA;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":[]}
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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 react_exports = {};
|
|
20
|
+
__export(react_exports, {
|
|
21
|
+
createDirectConnectFlow: () => import_connect_flow.createDirectConnectFlow,
|
|
22
|
+
useDirectVanaConnect: () => import_use_direct_vana_connect.useDirectVanaConnect
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(react_exports);
|
|
25
|
+
var import_use_direct_vana_connect = require("./direct/use-direct-vana-connect");
|
|
26
|
+
var import_connect_flow = require("./direct/connect-flow");
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
createDirectConnectFlow,
|
|
30
|
+
useDirectVanaConnect
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=react.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.ts"],"sourcesContent":["/**\n * React entry point for the Vana SDK direct Data Portability flow.\n *\n * @remarks\n * Exposes {@link useDirectVanaConnect} (and the underlying framework-agnostic\n * connect-flow store) for browser apps. This entry point is browser-safe and\n * imports nothing Node-only. `react` is a peer dependency.\n *\n * @example\n * ```tsx\n * \"use client\";\n * import { useDirectVanaConnect } from \"@opendatalabs/vana-sdk/react\";\n *\n * export function ConnectNotesButton() {\n * const connect = useDirectVanaConnect({\n * createRequest: () => fetch(\"/api/vana/request\", { method: \"POST\" }).then((r) => r.json()),\n * getStatus: (id) => fetch(`/api/vana/status?requestId=${id}`).then((r) => r.json()),\n * readResult: (id) => fetch(`/api/vana/data?requestId=${id}`).then((r) => r.json()),\n * });\n * return (\n * <button disabled={connect.state.type !== \"idle\"} onClick={connect.start} type=\"button\">\n * {connect.state.type === \"idle\" ? \"Connect Apple Notes\" : \"Connecting...\"}\n * </button>\n * );\n * }\n * ```\n *\n * @category Direct\n * @module react\n */\n\nexport {\n useDirectVanaConnect,\n type UseDirectVanaConnectOptions,\n type UseDirectVanaConnectResult,\n} from \"./direct/use-direct-vana-connect\";\n\n// Framework-agnostic store (usable without React).\nexport {\n createDirectConnectFlow,\n type DirectConnectFlow,\n type DirectConnectState,\n type DirectConnectOptions,\n type DirectConnectTransports,\n} from \"./direct/connect-flow\";\n\n// Shared types useful when typing the transports.\nexport type {\n AccessRequest,\n AccessRequestStatus,\n AccessRequestStatusValue,\n ApprovedDataResult,\n} from \"./direct/types\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BA,qCAIO;AAGP,0BAMO;","names":[]}
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React entry point for the Vana SDK direct Data Portability flow.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Exposes {@link useDirectVanaConnect} (and the underlying framework-agnostic
|
|
6
|
+
* connect-flow store) for browser apps. This entry point is browser-safe and
|
|
7
|
+
* imports nothing Node-only. `react` is a peer dependency.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* "use client";
|
|
12
|
+
* import { useDirectVanaConnect } from "@opendatalabs/vana-sdk/react";
|
|
13
|
+
*
|
|
14
|
+
* export function ConnectNotesButton() {
|
|
15
|
+
* const connect = useDirectVanaConnect({
|
|
16
|
+
* createRequest: () => fetch("/api/vana/request", { method: "POST" }).then((r) => r.json()),
|
|
17
|
+
* getStatus: (id) => fetch(`/api/vana/status?requestId=${id}`).then((r) => r.json()),
|
|
18
|
+
* readResult: (id) => fetch(`/api/vana/data?requestId=${id}`).then((r) => r.json()),
|
|
19
|
+
* });
|
|
20
|
+
* return (
|
|
21
|
+
* <button disabled={connect.state.type !== "idle"} onClick={connect.start} type="button">
|
|
22
|
+
* {connect.state.type === "idle" ? "Connect Apple Notes" : "Connecting..."}
|
|
23
|
+
* </button>
|
|
24
|
+
* );
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @category Direct
|
|
29
|
+
* @module react
|
|
30
|
+
*/
|
|
31
|
+
export { useDirectVanaConnect, type UseDirectVanaConnectOptions, type UseDirectVanaConnectResult, } from "./direct/use-direct-vana-connect";
|
|
32
|
+
export { createDirectConnectFlow, type DirectConnectFlow, type DirectConnectState, type DirectConnectOptions, type DirectConnectTransports, } from "./direct/connect-flow";
|
|
33
|
+
export type { AccessRequest, AccessRequestStatus, AccessRequestStatusValue, ApprovedDataResult, } from "./direct/types";
|
package/dist/react.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.ts"],"sourcesContent":["/**\n * React entry point for the Vana SDK direct Data Portability flow.\n *\n * @remarks\n * Exposes {@link useDirectVanaConnect} (and the underlying framework-agnostic\n * connect-flow store) for browser apps. This entry point is browser-safe and\n * imports nothing Node-only. `react` is a peer dependency.\n *\n * @example\n * ```tsx\n * \"use client\";\n * import { useDirectVanaConnect } from \"@opendatalabs/vana-sdk/react\";\n *\n * export function ConnectNotesButton() {\n * const connect = useDirectVanaConnect({\n * createRequest: () => fetch(\"/api/vana/request\", { method: \"POST\" }).then((r) => r.json()),\n * getStatus: (id) => fetch(`/api/vana/status?requestId=${id}`).then((r) => r.json()),\n * readResult: (id) => fetch(`/api/vana/data?requestId=${id}`).then((r) => r.json()),\n * });\n * return (\n * <button disabled={connect.state.type !== \"idle\"} onClick={connect.start} type=\"button\">\n * {connect.state.type === \"idle\" ? \"Connect Apple Notes\" : \"Connecting...\"}\n * </button>\n * );\n * }\n * ```\n *\n * @category Direct\n * @module react\n */\n\nexport {\n useDirectVanaConnect,\n type UseDirectVanaConnectOptions,\n type UseDirectVanaConnectResult,\n} from \"./direct/use-direct-vana-connect\";\n\n// Framework-agnostic store (usable without React).\nexport {\n createDirectConnectFlow,\n type DirectConnectFlow,\n type DirectConnectState,\n type DirectConnectOptions,\n type DirectConnectTransports,\n} from \"./direct/connect-flow\";\n\n// Shared types useful when typing the transports.\nexport type {\n AccessRequest,\n AccessRequestStatus,\n AccessRequestStatusValue,\n ApprovedDataResult,\n} from \"./direct/types\";\n"],"mappings":"AA+BA;AAAA,EACE;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,OAKK;","names":[]}
|