@opendatalabs/vana-sdk 3.0.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/__tests__/interop-personal-server.test.d.ts +1 -0
- package/dist/account/personal-server-lite-owner-binding.cjs +81 -0
- package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -0
- package/dist/account/personal-server-lite-owner-binding.d.ts +30 -0
- package/dist/account/personal-server-lite-owner-binding.js +59 -0
- package/dist/account/personal-server-lite-owner-binding.js.map +1 -0
- package/dist/account/personal-server-lite-owner-binding.test.d.ts +1 -0
- package/dist/account/personal-server-registration.cjs +263 -0
- package/dist/account/personal-server-registration.cjs.map +1 -0
- package/dist/account/personal-server-registration.d.ts +66 -0
- package/dist/account/personal-server-registration.js +240 -0
- package/dist/account/personal-server-registration.js.map +1 -0
- package/dist/account/personal-server-registration.test.d.ts +1 -0
- package/dist/auth/errors.js +1 -1
- package/dist/auth/oauth-client.cjs +250 -0
- package/dist/auth/oauth-client.cjs.map +1 -0
- package/dist/auth/oauth-client.d.ts +90 -0
- package/dist/auth/oauth-client.js +228 -0
- package/dist/auth/oauth-client.js.map +1 -0
- package/dist/auth/oauth-client.test.d.ts +1 -0
- package/dist/auth/web3-signed-builder.js +1 -1
- package/dist/auth/web3-signed.js +3 -3
- package/dist/browser.js +1 -1
- package/dist/chains/definitions.js +1 -1
- package/dist/chains/index.js +1 -1
- package/dist/chains.browser.js +1 -1
- package/dist/chains.js +1 -1
- package/dist/chains.node.js +1 -1
- package/dist/contracts/contractController.js +4 -4
- package/dist/core/client.js +1 -1
- package/dist/crypto/ecies/base.js +3 -3
- package/dist/crypto/ecies/browser.js +1 -1
- package/dist/crypto/ecies/index.js +1 -1
- package/dist/crypto/ecies/interface.js +1 -1
- package/dist/crypto/ecies/node.js +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.js +1 -1
- package/dist/generated/abi/index.js +26 -26
- package/dist/index.browser.d.ts +5 -0
- package/dist/index.browser.js +671 -4
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +689 -6
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +5 -0
- package/dist/index.node.js +671 -4
- package/dist/index.node.js.map +4 -4
- package/dist/node.js +1 -1
- package/dist/platform/browser-only.js +1 -1
- package/dist/platform/browser-safe.js +1 -1
- package/dist/platform/browser.js +6 -6
- package/dist/platform/index.js +4 -4
- package/dist/platform/node.js +8 -8
- package/dist/platform/utils.js +2 -2
- package/dist/platform.browser.js +3 -3
- package/dist/platform.js +4 -4
- package/dist/platform.node.js +4 -4
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +1 -1
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/grants.js +1 -1
- package/dist/protocol/personal-server-lite-owner-binding.cjs +93 -0
- package/dist/protocol/personal-server-lite-owner-binding.cjs.map +1 -0
- package/dist/protocol/personal-server-lite-owner-binding.d.ts +44 -0
- package/dist/protocol/personal-server-lite-owner-binding.js +65 -0
- package/dist/protocol/personal-server-lite-owner-binding.js.map +1 -0
- package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +1 -0
- package/dist/protocol/personal-server-registration.cjs +122 -0
- package/dist/protocol/personal-server-registration.cjs.map +1 -0
- package/dist/protocol/personal-server-registration.d.ts +62 -0
- package/dist/protocol/personal-server-registration.js +97 -0
- package/dist/protocol/personal-server-registration.js.map +1 -0
- package/dist/protocol/personal-server-registration.test.d.ts +1 -0
- package/dist/storage/default.js +1 -1
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.js +10 -10
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/manager.js +1 -1
- package/dist/storage/providers/callback-storage.js +1 -1
- package/dist/storage/providers/dropbox.js +1 -1
- package/dist/storage/providers/google-drive.js +1 -1
- package/dist/storage/providers/ipfs.js +2 -2
- package/dist/storage/providers/pinata.js +1 -1
- package/dist/storage/providers/r2.js +1 -1
- package/dist/storage/providers/vana-storage.cjs +1 -1
- package/dist/storage/providers/vana-storage.cjs.map +1 -1
- package/dist/storage/providers/vana-storage.d.ts +2 -2
- package/dist/storage/providers/vana-storage.js +3 -3
- package/dist/storage/providers/vana-storage.js.map +1 -1
- package/dist/types/index.js +2 -2
- package/dist/types.js +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -26,7 +26,8 @@ encryption, storage providers, and a shared isomorphic platform layer.
|
|
|
26
26
|
- **ECIES crypto** — audited (HashCloak, 2025) ECIES implementation with
|
|
27
27
|
matched browser and Node providers, byte-identical across platforms and
|
|
28
28
|
with strict KDF/MAC validation.
|
|
29
|
-
- **Storage providers** — `
|
|
29
|
+
- **Storage providers** — `VanaStorage` (default, talks to `storage.vana.org`),
|
|
30
|
+
`R2Storage`, `StorageManager`, `IpfsStorage`, `PinataStorage`,
|
|
30
31
|
`GoogleDriveStorage`, `DropboxStorage`, `CallbackStorage`.
|
|
31
32
|
- **Platform adapters** — `NodePlatformAdapter` and `BrowserPlatformAdapter`
|
|
32
33
|
with a shared `VanaPlatformAdapter` interface, plus detection helpers
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
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_lite_owner_binding_exports = {};
|
|
20
|
+
__export(personal_server_lite_owner_binding_exports, {
|
|
21
|
+
AccountPersonalServerLiteOwnerBindingError: () => AccountPersonalServerLiteOwnerBindingError,
|
|
22
|
+
signPersonalServerLiteOwnerBindingWithAccountClient: () => signPersonalServerLiteOwnerBindingWithAccountClient
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(personal_server_lite_owner_binding_exports);
|
|
25
|
+
var import_personal_server_lite_owner_binding = require("../protocol/personal-server-lite-owner-binding");
|
|
26
|
+
class AccountPersonalServerLiteOwnerBindingError extends Error {
|
|
27
|
+
code;
|
|
28
|
+
details;
|
|
29
|
+
constructor(input) {
|
|
30
|
+
super(input.message);
|
|
31
|
+
this.name = "AccountPersonalServerLiteOwnerBindingError";
|
|
32
|
+
this.code = input.code;
|
|
33
|
+
this.details = input.details;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
|
|
37
|
+
let address;
|
|
38
|
+
try {
|
|
39
|
+
address = await config.client.getAddress();
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw accountOwnerBindingError(error);
|
|
42
|
+
}
|
|
43
|
+
if (!address) {
|
|
44
|
+
throw new AccountPersonalServerLiteOwnerBindingError({
|
|
45
|
+
message: "Account did not return a wallet address",
|
|
46
|
+
code: "account_address_required"
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const message = (0, import_personal_server_lite_owner_binding.buildPersonalServerLiteOwnerBindingMessage)(address);
|
|
50
|
+
let signature;
|
|
51
|
+
try {
|
|
52
|
+
signature = await config.client.signMessage({ message });
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw accountOwnerBindingError(error);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
signature,
|
|
58
|
+
signerAddress: address,
|
|
59
|
+
message,
|
|
60
|
+
purpose: import_personal_server_lite_owner_binding.PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function accountOwnerBindingError(error) {
|
|
64
|
+
if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
|
|
65
|
+
return error;
|
|
66
|
+
}
|
|
67
|
+
const rpcError = error;
|
|
68
|
+
const code = rpcError?.code;
|
|
69
|
+
const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
|
|
70
|
+
return new AccountPersonalServerLiteOwnerBindingError({
|
|
71
|
+
message,
|
|
72
|
+
code,
|
|
73
|
+
details: error
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
AccountPersonalServerLiteOwnerBindingError,
|
|
79
|
+
signPersonalServerLiteOwnerBindingWithAccountClient
|
|
80
|
+
});
|
|
81
|
+
//# sourceMappingURL=personal-server-lite-owner-binding.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/account/personal-server-lite-owner-binding.ts"],"sourcesContent":["/**\n * Optional first-party Account integration for PS Lite owner binding.\n *\n * The protocol helper lives in `protocol/personal-server-lite-owner-binding`.\n * This module adapts any Account-style client exposing `getAddress` and\n * `signMessage` to the SDK owner-binding signature shape.\n *\n * @category Account\n */\n\nimport type { Address, Hex } from \"viem\";\nimport {\n buildPersonalServerLiteOwnerBindingMessage,\n PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,\n type PersonalServerLiteOwnerBindingSignature,\n} from \"../protocol/personal-server-lite-owner-binding\";\n\nexport interface AccountPersonalServerLiteOwnerBindingClient {\n getAddress(): Promise<Address | null> | Address | null;\n signMessage(input: {\n message: ReturnType<typeof buildPersonalServerLiteOwnerBindingMessage>;\n }): Promise<Hex> | Hex;\n}\n\nexport interface SignPersonalServerLiteOwnerBindingWithAccountClientConfig {\n client: AccountPersonalServerLiteOwnerBindingClient;\n}\n\nexport class AccountPersonalServerLiteOwnerBindingError extends Error {\n code?: number | string;\n details?: unknown;\n\n constructor(input: {\n message: string;\n code?: number | string;\n details?: unknown;\n }) {\n super(input.message);\n this.name = \"AccountPersonalServerLiteOwnerBindingError\";\n this.code = input.code;\n this.details = input.details;\n }\n}\n\nexport async function signPersonalServerLiteOwnerBindingWithAccountClient(\n config: SignPersonalServerLiteOwnerBindingWithAccountClientConfig,\n): Promise<PersonalServerLiteOwnerBindingSignature> {\n let address: Address | null;\n try {\n address = await config.client.getAddress();\n } catch (error) {\n throw accountOwnerBindingError(error);\n }\n\n if (!address) {\n throw new AccountPersonalServerLiteOwnerBindingError({\n message: \"Account did not return a wallet address\",\n code: \"account_address_required\",\n });\n }\n\n const message = buildPersonalServerLiteOwnerBindingMessage(address);\n let signature: Hex;\n try {\n signature = await config.client.signMessage({ message });\n } catch (error) {\n throw accountOwnerBindingError(error);\n }\n\n return {\n signature,\n signerAddress: address,\n message,\n purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,\n };\n}\n\nfunction accountOwnerBindingError(\n error: unknown,\n): AccountPersonalServerLiteOwnerBindingError {\n if (error instanceof AccountPersonalServerLiteOwnerBindingError) {\n return error;\n }\n\n const rpcError = error as\n | { code?: number | string; message?: string }\n | undefined;\n const code = rpcError?.code;\n const message =\n typeof rpcError?.message === \"string\" && rpcError.message.length > 0\n ? rpcError.message\n : \"Account PS Lite owner-binding signature failed\";\n\n return new AccountPersonalServerLiteOwnerBindingError({\n message,\n code,\n details: error,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,gDAIO;AAaA,MAAM,mDAAmD,MAAM;AAAA,EACpE;AAAA,EACA;AAAA,EAEA,YAAY,OAIT;AACD,UAAM,MAAM,OAAO;AACnB,SAAK,OAAO;AACZ,SAAK,OAAO,MAAM;AAClB,SAAK,UAAU,MAAM;AAAA,EACvB;AACF;AAEA,eAAsB,oDACpB,QACkD;AAClD,MAAI;AACJ,MAAI;AACF,cAAU,MAAM,OAAO,OAAO,WAAW;AAAA,EAC3C,SAAS,OAAO;AACd,UAAM,yBAAyB,KAAK;AAAA,EACtC;AAEA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,2CAA2C;AAAA,MACnD,SAAS;AAAA,MACT,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AAEA,QAAM,cAAU,sFAA2C,OAAO;AAClE,MAAI;AACJ,MAAI;AACF,gBAAY,MAAM,OAAO,OAAO,YAAY,EAAE,QAAQ,CAAC;AAAA,EACzD,SAAS,OAAO;AACd,UAAM,yBAAyB,KAAK;AAAA,EACtC;AAEA,SAAO;AAAA,IACL;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA,SAAS;AAAA,EACX;AACF;AAEA,SAAS,yBACP,OAC4C;AAC5C,MAAI,iBAAiB,4CAA4C;AAC/D,WAAO;AAAA,EACT;AAEA,QAAM,WAAW;AAGjB,QAAM,OAAO,UAAU;AACvB,QAAM,UACJ,OAAO,UAAU,YAAY,YAAY,SAAS,QAAQ,SAAS,IAC/D,SAAS,UACT;AAEN,SAAO,IAAI,2CAA2C;AAAA,IACpD;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional first-party Account integration for PS Lite owner binding.
|
|
3
|
+
*
|
|
4
|
+
* The protocol helper lives in `protocol/personal-server-lite-owner-binding`.
|
|
5
|
+
* This module adapts any Account-style client exposing `getAddress` and
|
|
6
|
+
* `signMessage` to the SDK owner-binding signature shape.
|
|
7
|
+
*
|
|
8
|
+
* @category Account
|
|
9
|
+
*/
|
|
10
|
+
import type { Address, Hex } from "viem";
|
|
11
|
+
import { buildPersonalServerLiteOwnerBindingMessage, type PersonalServerLiteOwnerBindingSignature } from "../protocol/personal-server-lite-owner-binding";
|
|
12
|
+
export interface AccountPersonalServerLiteOwnerBindingClient {
|
|
13
|
+
getAddress(): Promise<Address | null> | Address | null;
|
|
14
|
+
signMessage(input: {
|
|
15
|
+
message: ReturnType<typeof buildPersonalServerLiteOwnerBindingMessage>;
|
|
16
|
+
}): Promise<Hex> | Hex;
|
|
17
|
+
}
|
|
18
|
+
export interface SignPersonalServerLiteOwnerBindingWithAccountClientConfig {
|
|
19
|
+
client: AccountPersonalServerLiteOwnerBindingClient;
|
|
20
|
+
}
|
|
21
|
+
export declare class AccountPersonalServerLiteOwnerBindingError extends Error {
|
|
22
|
+
code?: number | string;
|
|
23
|
+
details?: unknown;
|
|
24
|
+
constructor(input: {
|
|
25
|
+
message: string;
|
|
26
|
+
code?: number | string;
|
|
27
|
+
details?: unknown;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export declare function signPersonalServerLiteOwnerBindingWithAccountClient(config: SignPersonalServerLiteOwnerBindingWithAccountClientConfig): Promise<PersonalServerLiteOwnerBindingSignature>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildPersonalServerLiteOwnerBindingMessage,
|
|
3
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
4
|
+
} from "../protocol/personal-server-lite-owner-binding.js";
|
|
5
|
+
class AccountPersonalServerLiteOwnerBindingError extends Error {
|
|
6
|
+
code;
|
|
7
|
+
details;
|
|
8
|
+
constructor(input) {
|
|
9
|
+
super(input.message);
|
|
10
|
+
this.name = "AccountPersonalServerLiteOwnerBindingError";
|
|
11
|
+
this.code = input.code;
|
|
12
|
+
this.details = input.details;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
|
|
16
|
+
let address;
|
|
17
|
+
try {
|
|
18
|
+
address = await config.client.getAddress();
|
|
19
|
+
} catch (error) {
|
|
20
|
+
throw accountOwnerBindingError(error);
|
|
21
|
+
}
|
|
22
|
+
if (!address) {
|
|
23
|
+
throw new AccountPersonalServerLiteOwnerBindingError({
|
|
24
|
+
message: "Account did not return a wallet address",
|
|
25
|
+
code: "account_address_required"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(address);
|
|
29
|
+
let signature;
|
|
30
|
+
try {
|
|
31
|
+
signature = await config.client.signMessage({ message });
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw accountOwnerBindingError(error);
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
signature,
|
|
37
|
+
signerAddress: address,
|
|
38
|
+
message,
|
|
39
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function accountOwnerBindingError(error) {
|
|
43
|
+
if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
|
|
44
|
+
return error;
|
|
45
|
+
}
|
|
46
|
+
const rpcError = error;
|
|
47
|
+
const code = rpcError?.code;
|
|
48
|
+
const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
|
|
49
|
+
return new AccountPersonalServerLiteOwnerBindingError({
|
|
50
|
+
message,
|
|
51
|
+
code,
|
|
52
|
+
details: error
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
AccountPersonalServerLiteOwnerBindingError,
|
|
57
|
+
signPersonalServerLiteOwnerBindingWithAccountClient
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=personal-server-lite-owner-binding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/account/personal-server-lite-owner-binding.ts"],"sourcesContent":["/**\n * Optional first-party Account integration for PS Lite owner binding.\n *\n * The protocol helper lives in `protocol/personal-server-lite-owner-binding`.\n * This module adapts any Account-style client exposing `getAddress` and\n * `signMessage` to the SDK owner-binding signature shape.\n *\n * @category Account\n */\n\nimport type { Address, Hex } from \"viem\";\nimport {\n buildPersonalServerLiteOwnerBindingMessage,\n PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,\n type PersonalServerLiteOwnerBindingSignature,\n} from \"../protocol/personal-server-lite-owner-binding\";\n\nexport interface AccountPersonalServerLiteOwnerBindingClient {\n getAddress(): Promise<Address | null> | Address | null;\n signMessage(input: {\n message: ReturnType<typeof buildPersonalServerLiteOwnerBindingMessage>;\n }): Promise<Hex> | Hex;\n}\n\nexport interface SignPersonalServerLiteOwnerBindingWithAccountClientConfig {\n client: AccountPersonalServerLiteOwnerBindingClient;\n}\n\nexport class AccountPersonalServerLiteOwnerBindingError extends Error {\n code?: number | string;\n details?: unknown;\n\n constructor(input: {\n message: string;\n code?: number | string;\n details?: unknown;\n }) {\n super(input.message);\n this.name = \"AccountPersonalServerLiteOwnerBindingError\";\n this.code = input.code;\n this.details = input.details;\n }\n}\n\nexport async function signPersonalServerLiteOwnerBindingWithAccountClient(\n config: SignPersonalServerLiteOwnerBindingWithAccountClientConfig,\n): Promise<PersonalServerLiteOwnerBindingSignature> {\n let address: Address | null;\n try {\n address = await config.client.getAddress();\n } catch (error) {\n throw accountOwnerBindingError(error);\n }\n\n if (!address) {\n throw new AccountPersonalServerLiteOwnerBindingError({\n message: \"Account did not return a wallet address\",\n code: \"account_address_required\",\n });\n }\n\n const message = buildPersonalServerLiteOwnerBindingMessage(address);\n let signature: Hex;\n try {\n signature = await config.client.signMessage({ message });\n } catch (error) {\n throw accountOwnerBindingError(error);\n }\n\n return {\n signature,\n signerAddress: address,\n message,\n purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,\n };\n}\n\nfunction accountOwnerBindingError(\n error: unknown,\n): AccountPersonalServerLiteOwnerBindingError {\n if (error instanceof AccountPersonalServerLiteOwnerBindingError) {\n return error;\n }\n\n const rpcError = error as\n | { code?: number | string; message?: string }\n | undefined;\n const code = rpcError?.code;\n const message =\n typeof rpcError?.message === \"string\" && rpcError.message.length > 0\n ? rpcError.message\n : \"Account PS Lite owner-binding signature failed\";\n\n return new AccountPersonalServerLiteOwnerBindingError({\n message,\n code,\n details: error,\n });\n}\n"],"mappings":"AAWA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAaA,MAAM,mDAAmD,MAAM;AAAA,EACpE;AAAA,EACA;AAAA,EAEA,YAAY,OAIT;AACD,UAAM,MAAM,OAAO;AACnB,SAAK,OAAO;AACZ,SAAK,OAAO,MAAM;AAClB,SAAK,UAAU,MAAM;AAAA,EACvB;AACF;AAEA,eAAsB,oDACpB,QACkD;AAClD,MAAI;AACJ,MAAI;AACF,cAAU,MAAM,OAAO,OAAO,WAAW;AAAA,EAC3C,SAAS,OAAO;AACd,UAAM,yBAAyB,KAAK;AAAA,EACtC;AAEA,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,2CAA2C;AAAA,MACnD,SAAS;AAAA,MACT,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AAEA,QAAM,UAAU,2CAA2C,OAAO;AAClE,MAAI;AACJ,MAAI;AACF,gBAAY,MAAM,OAAO,OAAO,YAAY,EAAE,QAAQ,CAAC;AAAA,EACzD,SAAS,OAAO;AACd,UAAM,yBAAyB,KAAK;AAAA,EACtC;AAEA,SAAO;AAAA,IACL;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA,SAAS;AAAA,EACX;AACF;AAEA,SAAS,yBACP,OAC4C;AAC5C,MAAI,iBAAiB,4CAA4C;AAC/D,WAAO;AAAA,EACT;AAEA,QAAM,WAAW;AAGjB,QAAM,OAAO,UAAU;AACvB,QAAM,UACJ,OAAO,UAAU,YAAY,YAAY,SAAS,QAAQ,SAAS,IAC/D,SAAS,UACT;AAEN,SAAO,IAAI,2CAA2C;AAAA,IACpD;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,263 @@
|
|
|
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_registration_exports = {};
|
|
20
|
+
__export(personal_server_registration_exports, {
|
|
21
|
+
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT: () => ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
22
|
+
AccountPersonalServerRegistrationError: () => AccountPersonalServerRegistrationError,
|
|
23
|
+
signPersonalServerRegistrationWithAccount: () => signPersonalServerRegistrationWithAccount
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(personal_server_registration_exports);
|
|
26
|
+
var import_viem = require("viem");
|
|
27
|
+
var import_personal_server_registration = require("../protocol/personal-server-registration");
|
|
28
|
+
var import_eip712 = require("../protocol/eip712");
|
|
29
|
+
const ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
30
|
+
class AccountPersonalServerRegistrationError extends Error {
|
|
31
|
+
status;
|
|
32
|
+
code;
|
|
33
|
+
details;
|
|
34
|
+
constructor(input) {
|
|
35
|
+
super(input.message);
|
|
36
|
+
this.name = "AccountPersonalServerRegistrationError";
|
|
37
|
+
this.status = input.status;
|
|
38
|
+
this.code = input.code;
|
|
39
|
+
this.details = input.details;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
|
|
43
|
+
function trimTrailingSlash(value) {
|
|
44
|
+
return value.replace(/\/+$/, "");
|
|
45
|
+
}
|
|
46
|
+
function assertAddress(value, name) {
|
|
47
|
+
if (!(0, import_viem.isAddress)(value)) {
|
|
48
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function parseAccountResponse(response) {
|
|
52
|
+
const body = await response.json().catch(() => void 0);
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
throw new AccountPersonalServerRegistrationError({
|
|
55
|
+
status: response.status,
|
|
56
|
+
code: accountErrorCode(body),
|
|
57
|
+
message: accountErrorMessage(response.status, body),
|
|
58
|
+
details: body
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return body;
|
|
62
|
+
}
|
|
63
|
+
function accountErrorMessage(status, body) {
|
|
64
|
+
const nestedMessage = nestedAccountErrorField(body, "message");
|
|
65
|
+
if (nestedMessage) {
|
|
66
|
+
return nestedMessage;
|
|
67
|
+
}
|
|
68
|
+
if (isRecord(body) && typeof body.message === "string") {
|
|
69
|
+
return body.message;
|
|
70
|
+
}
|
|
71
|
+
const code = accountErrorCode(body);
|
|
72
|
+
if (code) {
|
|
73
|
+
return `Account PS registration signing failed: ${code}`;
|
|
74
|
+
}
|
|
75
|
+
return `Account PS registration signing failed: ${status}`;
|
|
76
|
+
}
|
|
77
|
+
function accountErrorCode(body) {
|
|
78
|
+
const nestedCode = nestedAccountErrorField(body, "code");
|
|
79
|
+
if (nestedCode) {
|
|
80
|
+
return nestedCode;
|
|
81
|
+
}
|
|
82
|
+
if (isRecord(body)) {
|
|
83
|
+
if (typeof body.code === "string") {
|
|
84
|
+
return body.code;
|
|
85
|
+
}
|
|
86
|
+
if (typeof body.error === "string") {
|
|
87
|
+
return body.error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
92
|
+
function nestedAccountErrorField(body, field) {
|
|
93
|
+
if (!isRecord(body) || !isRecord(body.error)) {
|
|
94
|
+
return void 0;
|
|
95
|
+
}
|
|
96
|
+
const value = body.error[field];
|
|
97
|
+
return typeof value === "string" ? value : void 0;
|
|
98
|
+
}
|
|
99
|
+
function isRecord(value) {
|
|
100
|
+
return typeof value === "object" && value !== null;
|
|
101
|
+
}
|
|
102
|
+
function normalizeAccountResponse(response) {
|
|
103
|
+
return {
|
|
104
|
+
...response,
|
|
105
|
+
status: response.status === "fallback_required" ? "confirmation_required" : response.status,
|
|
106
|
+
signerAddress: response.signerAddress ?? response.signer?.address,
|
|
107
|
+
typedData: response.typedData ?? response.typed_data
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function buildSignedResult(response, request) {
|
|
111
|
+
assertAddress(response.signerAddress, "signerAddress");
|
|
112
|
+
if (response.typedData) {
|
|
113
|
+
assertTypedDataMatchesRequest(
|
|
114
|
+
response.typedData,
|
|
115
|
+
request,
|
|
116
|
+
response.signerAddress
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
signature: response.signature,
|
|
121
|
+
signerAddress: response.signerAddress,
|
|
122
|
+
typedData: response.typedData ?? (0, import_personal_server_registration.buildPersonalServerRegistrationTypedData)({
|
|
123
|
+
ownerAddress: response.signerAddress,
|
|
124
|
+
...request
|
|
125
|
+
}),
|
|
126
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function assertTypedDataMatchesRequest(typedData, request, expectedSignerAddress) {
|
|
130
|
+
assertAddress(
|
|
131
|
+
typedData.message.ownerAddress,
|
|
132
|
+
"typedData.message.ownerAddress"
|
|
133
|
+
);
|
|
134
|
+
assertAddress(
|
|
135
|
+
typedData.message.serverAddress,
|
|
136
|
+
"typedData.message.serverAddress"
|
|
137
|
+
);
|
|
138
|
+
if (expectedSignerAddress && !sameAddress(typedData.message.ownerAddress, expectedSignerAddress)) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
"Account typedData ownerAddress must match the expected signer address"
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
if (!sameAddress(typedData.message.serverAddress, request.serverAddress)) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
"Account typedData serverAddress must match the requested serverAddress"
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
if (typedData.message.publicKey !== request.serverPublicKey) {
|
|
149
|
+
throw new Error(
|
|
150
|
+
"Account typedData publicKey must match the requested serverPublicKey"
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
if (typedData.message.serverUrl !== request.serverUrl) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
"Account typedData serverUrl must match the requested serverUrl"
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
if (typedData.primaryType !== "ServerRegistration") {
|
|
159
|
+
throw new Error("Account typedData primaryType must be ServerRegistration");
|
|
160
|
+
}
|
|
161
|
+
if (JSON.stringify(typedData.types) !== JSON.stringify(import_eip712.SERVER_REGISTRATION_TYPES)) {
|
|
162
|
+
throw new Error("Account typedData types must be ServerRegistration types");
|
|
163
|
+
}
|
|
164
|
+
const expectedDomain = (0, import_personal_server_registration.personalServerRegistrationDomain)({
|
|
165
|
+
config: request.config,
|
|
166
|
+
chainId: request.chainId,
|
|
167
|
+
verifyingContract: request.verifyingContract
|
|
168
|
+
});
|
|
169
|
+
if (!domainsEqual(typedData.domain, expectedDomain)) {
|
|
170
|
+
throw new Error("Account typedData domain must match the requested domain");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function sameAddress(a, b) {
|
|
174
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
175
|
+
}
|
|
176
|
+
function domainsEqual(a, b) {
|
|
177
|
+
if (!a || !b) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
return a.name === b.name && a.version === b.version && Number(a.chainId) === Number(b.chainId) && String(a.verifyingContract ?? "").toLowerCase() === String(b.verifyingContract ?? "").toLowerCase() && a.salt === b.salt;
|
|
181
|
+
}
|
|
182
|
+
async function signPersonalServerRegistrationWithAccount(config, request) {
|
|
183
|
+
assertAddress(request.serverAddress, "serverAddress");
|
|
184
|
+
const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
185
|
+
const endpoint = new URL(
|
|
186
|
+
config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
|
|
187
|
+
`${trimTrailingSlash(config.accountOrigin)}/`
|
|
188
|
+
);
|
|
189
|
+
const response = await fetchImpl(endpoint, {
|
|
190
|
+
method: "POST",
|
|
191
|
+
headers: { "content-type": "application/json" },
|
|
192
|
+
credentials: "include",
|
|
193
|
+
body: JSON.stringify({
|
|
194
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
195
|
+
serverAddress: request.serverAddress,
|
|
196
|
+
serverPublicKey: request.serverPublicKey,
|
|
197
|
+
serverUrl: request.serverUrl,
|
|
198
|
+
config: request.config,
|
|
199
|
+
chainId: request.chainId,
|
|
200
|
+
verifyingContract: request.verifyingContract
|
|
201
|
+
})
|
|
202
|
+
});
|
|
203
|
+
const body = normalizeAccountResponse(await parseAccountResponse(response));
|
|
204
|
+
if (body.status === "signed") {
|
|
205
|
+
if (!body.signature || !body.signerAddress) {
|
|
206
|
+
throw new Error(
|
|
207
|
+
"Account signed response must include signature and signerAddress"
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
status: "signed",
|
|
212
|
+
result: buildSignedResult(
|
|
213
|
+
{
|
|
214
|
+
signature: body.signature,
|
|
215
|
+
signerAddress: body.signerAddress,
|
|
216
|
+
typedData: body.typedData
|
|
217
|
+
},
|
|
218
|
+
request
|
|
219
|
+
)
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
if (body.status === "confirmation_required") {
|
|
223
|
+
if (!body.typedData) {
|
|
224
|
+
throw new Error(
|
|
225
|
+
"Account confirmation_required response must include typedData"
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
assertTypedDataMatchesRequest(body.typedData, request, body.signerAddress);
|
|
229
|
+
if (!config.fallbackSigner) {
|
|
230
|
+
return {
|
|
231
|
+
status: "confirmation_required",
|
|
232
|
+
typedData: body.typedData,
|
|
233
|
+
signerAddress: body.signerAddress
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
assertTypedDataMatchesRequest(
|
|
237
|
+
body.typedData,
|
|
238
|
+
request,
|
|
239
|
+
config.fallbackSigner.address
|
|
240
|
+
);
|
|
241
|
+
const signature = await config.fallbackSigner.signTypedData(body.typedData);
|
|
242
|
+
return {
|
|
243
|
+
status: "fallback_signed",
|
|
244
|
+
accountStatus: "confirmation_required",
|
|
245
|
+
result: {
|
|
246
|
+
signature,
|
|
247
|
+
signerAddress: config.fallbackSigner.address,
|
|
248
|
+
typedData: body.typedData,
|
|
249
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
throw new Error(
|
|
254
|
+
`Unsupported Account PS registration signing status: ${String(body.status)}`
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
258
|
+
0 && (module.exports = {
|
|
259
|
+
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
260
|
+
AccountPersonalServerRegistrationError,
|
|
261
|
+
signPersonalServerRegistrationWithAccount
|
|
262
|
+
});
|
|
263
|
+
//# sourceMappingURL=personal-server-registration.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/account/personal-server-registration.ts"],"sourcesContent":["/**\n * Optional first-party Account integration for Personal Server registration.\n *\n * The protocol helper lives in `protocol/personal-server-registration`.\n * This module is only for callers that want to use an Account deployment's\n * constrained silent-sign endpoint.\n *\n * @category Account\n */\n\nimport { isAddress, type Address, type Hex } from \"viem\";\nimport {\n buildPersonalServerRegistrationTypedData,\n type BuildPersonalServerRegistrationTypedDataInput,\n type PersonalServerRegistrationSignature,\n type PersonalServerRegistrationSigner,\n type PersonalServerRegistrationTypedData,\n personalServerRegistrationDomain,\n} from \"../protocol/personal-server-registration\";\nimport { SERVER_REGISTRATION_TYPES } from \"../protocol/eip712\";\n\nexport const ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT =\n \"personal_server.server_registration.v1\" as const;\n\nexport type AccountPersonalServerRegistrationIntent =\n typeof ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT;\n\nexport type AccountPersonalServerRegistrationStatus =\n | \"signed\"\n | \"confirmation_required\"\n | \"fallback_required\";\n\nexport interface AccountPersonalServerRegistrationRequest extends Omit<\n BuildPersonalServerRegistrationTypedDataInput,\n \"ownerAddress\"\n> {}\n\nexport interface AccountPersonalServerRegistrationConfig {\n /**\n * Origin for the Account deployment to call, e.g. an app-dev Account origin.\n * No production origin is assumed by the SDK.\n */\n accountOrigin: string;\n /**\n * Path for Account's constrained PS registration silent-sign endpoint.\n */\n endpointPath?: string;\n /**\n * Optional fetch implementation for tests and non-default runtimes.\n */\n fetchImpl?: typeof fetch;\n /**\n * Optional signer used when Account says user confirmation is required and\n * returns typed data for the caller to sign interactively.\n */\n fallbackSigner?: PersonalServerRegistrationSigner;\n}\n\nexport type AccountPersonalServerRegistrationSignature =\n PersonalServerRegistrationSignature & {\n intent: AccountPersonalServerRegistrationIntent;\n };\n\nexport interface AccountSignedPersonalServerRegistration {\n status: \"signed\";\n result: AccountPersonalServerRegistrationSignature;\n}\n\nexport interface AccountConfirmationRequiredPersonalServerRegistration {\n status: \"confirmation_required\";\n typedData: PersonalServerRegistrationTypedData;\n signerAddress?: Address;\n}\n\nexport interface AccountFallbackSignedPersonalServerRegistration {\n status: \"fallback_signed\";\n accountStatus: \"confirmation_required\";\n result: AccountPersonalServerRegistrationSignature;\n}\n\nexport type AccountPersonalServerRegistrationResult =\n | AccountSignedPersonalServerRegistration\n | AccountConfirmationRequiredPersonalServerRegistration\n | AccountFallbackSignedPersonalServerRegistration;\n\nexport class AccountPersonalServerRegistrationError extends Error {\n status: number;\n code?: string;\n details?: unknown;\n\n constructor(input: {\n status: number;\n message: string;\n code?: string;\n details?: unknown;\n }) {\n super(input.message);\n this.name = \"AccountPersonalServerRegistrationError\";\n this.status = input.status;\n this.code = input.code;\n this.details = input.details;\n }\n}\n\ninterface AccountSilentSignResponse {\n status: AccountPersonalServerRegistrationStatus;\n signature?: Hex;\n signerAddress?: Address;\n signer?: { address?: Address };\n typedData?: PersonalServerRegistrationTypedData;\n typed_data?: PersonalServerRegistrationTypedData;\n error?: unknown;\n}\n\n// Account-owned route policy. Protocol signing primitives deliberately do not\n// define Account intent names or API paths.\nconst DEFAULT_ACCOUNT_PS_REGISTRATION_PATH =\n \"/api/v1/intents/personal-server-registration/sign\";\n\nfunction trimTrailingSlash(value: string): string {\n return value.replace(/\\/+$/, \"\");\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\nasync function parseAccountResponse(\n response: Response,\n): Promise<AccountSilentSignResponse> {\n const body = (await response.json().catch(() => undefined)) as unknown;\n\n if (!response.ok) {\n throw new AccountPersonalServerRegistrationError({\n status: response.status,\n code: accountErrorCode(body),\n message: accountErrorMessage(response.status, body),\n details: body,\n });\n }\n\n return body as AccountSilentSignResponse;\n}\n\nfunction accountErrorMessage(status: number, body: unknown): string {\n const nestedMessage = nestedAccountErrorField(body, \"message\");\n if (nestedMessage) {\n return nestedMessage;\n }\n\n if (isRecord(body) && typeof body.message === \"string\") {\n return body.message;\n }\n\n const code = accountErrorCode(body);\n if (code) {\n return `Account PS registration signing failed: ${code}`;\n }\n\n return `Account PS registration signing failed: ${status}`;\n}\n\nfunction accountErrorCode(body: unknown): string | undefined {\n const nestedCode = nestedAccountErrorField(body, \"code\");\n if (nestedCode) {\n return nestedCode;\n }\n\n if (isRecord(body)) {\n if (typeof body.code === \"string\") {\n return body.code;\n }\n if (typeof body.error === \"string\") {\n return body.error;\n }\n }\n\n return undefined;\n}\n\nfunction nestedAccountErrorField(\n body: unknown,\n field: \"code\" | \"message\",\n): string | undefined {\n if (!isRecord(body) || !isRecord(body.error)) {\n return undefined;\n }\n\n const value = body.error[field];\n return typeof value === \"string\" ? value : undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction normalizeAccountResponse(\n response: AccountSilentSignResponse,\n): AccountSilentSignResponse {\n return {\n ...response,\n status:\n response.status === \"fallback_required\"\n ? \"confirmation_required\"\n : response.status,\n signerAddress: response.signerAddress ?? response.signer?.address,\n typedData: response.typedData ?? response.typed_data,\n };\n}\n\nfunction buildSignedResult(\n response: Required<\n Pick<AccountSilentSignResponse, \"signature\" | \"signerAddress\">\n > &\n Pick<AccountSilentSignResponse, \"typedData\">,\n request: AccountPersonalServerRegistrationRequest,\n): AccountPersonalServerRegistrationSignature {\n assertAddress(response.signerAddress, \"signerAddress\");\n if (response.typedData) {\n assertTypedDataMatchesRequest(\n response.typedData,\n request,\n response.signerAddress,\n );\n }\n\n return {\n signature: response.signature,\n signerAddress: response.signerAddress,\n typedData:\n response.typedData ??\n buildPersonalServerRegistrationTypedData({\n ownerAddress: response.signerAddress,\n ...request,\n }),\n intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,\n };\n}\n\nfunction assertTypedDataMatchesRequest(\n typedData: PersonalServerRegistrationTypedData,\n request: AccountPersonalServerRegistrationRequest,\n expectedSignerAddress?: Address,\n): void {\n assertAddress(\n typedData.message.ownerAddress,\n \"typedData.message.ownerAddress\",\n );\n assertAddress(\n typedData.message.serverAddress,\n \"typedData.message.serverAddress\",\n );\n\n if (\n expectedSignerAddress &&\n !sameAddress(typedData.message.ownerAddress, expectedSignerAddress)\n ) {\n throw new Error(\n \"Account typedData ownerAddress must match the expected signer address\",\n );\n }\n\n if (!sameAddress(typedData.message.serverAddress, request.serverAddress)) {\n throw new Error(\n \"Account typedData serverAddress must match the requested serverAddress\",\n );\n }\n\n if (typedData.message.publicKey !== request.serverPublicKey) {\n throw new Error(\n \"Account typedData publicKey must match the requested serverPublicKey\",\n );\n }\n\n if (typedData.message.serverUrl !== request.serverUrl) {\n throw new Error(\n \"Account typedData serverUrl must match the requested serverUrl\",\n );\n }\n\n if (typedData.primaryType !== \"ServerRegistration\") {\n throw new Error(\"Account typedData primaryType must be ServerRegistration\");\n }\n\n if (\n JSON.stringify(typedData.types) !==\n JSON.stringify(SERVER_REGISTRATION_TYPES)\n ) {\n throw new Error(\"Account typedData types must be ServerRegistration types\");\n }\n\n const expectedDomain = personalServerRegistrationDomain({\n config: request.config,\n chainId: request.chainId,\n verifyingContract: request.verifyingContract,\n });\n if (!domainsEqual(typedData.domain, expectedDomain)) {\n throw new Error(\"Account typedData domain must match the requested domain\");\n }\n}\n\nfunction sameAddress(a: Address, b: Address): boolean {\n return a.toLowerCase() === b.toLowerCase();\n}\n\nfunction domainsEqual(\n a: PersonalServerRegistrationTypedData[\"domain\"],\n b: PersonalServerRegistrationTypedData[\"domain\"],\n): boolean {\n if (!a || !b) {\n return false;\n }\n\n return (\n a.name === b.name &&\n a.version === b.version &&\n Number(a.chainId) === Number(b.chainId) &&\n String(a.verifyingContract ?? \"\").toLowerCase() ===\n String(b.verifyingContract ?? \"\").toLowerCase() &&\n a.salt === b.salt\n );\n}\n\nexport async function signPersonalServerRegistrationWithAccount(\n config: AccountPersonalServerRegistrationConfig,\n request: AccountPersonalServerRegistrationRequest,\n): Promise<AccountPersonalServerRegistrationResult> {\n assertAddress(request.serverAddress, \"serverAddress\");\n\n const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);\n const endpoint = new URL(\n config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,\n `${trimTrailingSlash(config.accountOrigin)}/`,\n );\n\n const response = await fetchImpl(endpoint, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n credentials: \"include\",\n body: JSON.stringify({\n intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,\n serverAddress: request.serverAddress,\n serverPublicKey: request.serverPublicKey,\n serverUrl: request.serverUrl,\n config: request.config,\n chainId: request.chainId,\n verifyingContract: request.verifyingContract,\n }),\n });\n const body = normalizeAccountResponse(await parseAccountResponse(response));\n\n if (body.status === \"signed\") {\n if (!body.signature || !body.signerAddress) {\n throw new Error(\n \"Account signed response must include signature and signerAddress\",\n );\n }\n\n return {\n status: \"signed\",\n result: buildSignedResult(\n {\n signature: body.signature,\n signerAddress: body.signerAddress,\n typedData: body.typedData,\n },\n request,\n ),\n };\n }\n\n if (body.status === \"confirmation_required\") {\n if (!body.typedData) {\n throw new Error(\n \"Account confirmation_required response must include typedData\",\n );\n }\n assertTypedDataMatchesRequest(body.typedData, request, body.signerAddress);\n\n if (!config.fallbackSigner) {\n return {\n status: \"confirmation_required\",\n typedData: body.typedData,\n signerAddress: body.signerAddress,\n };\n }\n\n assertTypedDataMatchesRequest(\n body.typedData,\n request,\n config.fallbackSigner.address,\n );\n const signature = await config.fallbackSigner.signTypedData(body.typedData);\n\n return {\n status: \"fallback_signed\",\n accountStatus: \"confirmation_required\",\n result: {\n signature,\n signerAddress: config.fallbackSigner.address,\n typedData: body.typedData,\n intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,\n },\n };\n }\n\n throw new Error(\n `Unsupported Account PS registration signing status: ${String(body.status)}`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,kBAAkD;AAClD,0CAOO;AACP,oBAA0C;AAEnC,MAAM,8CACX;AA+DK,MAAM,+CAA+C,MAAM;AAAA,EAChE;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,OAKT;AACD,UAAM,MAAM,OAAO;AACnB,SAAK,OAAO;AACZ,SAAK,SAAS,MAAM;AACpB,SAAK,OAAO,MAAM;AAClB,SAAK,UAAU,MAAM;AAAA,EACvB;AACF;AAcA,MAAM,uCACJ;AAEF,SAAS,kBAAkB,OAAuB;AAChD,SAAO,MAAM,QAAQ,QAAQ,EAAE;AACjC;AAEA,SAAS,cAAc,OAAgB,MAAoB;AACzD,MAAI,KAAC,uBAAU,KAAK,GAAG;AACrB,UAAM,IAAI,MAAM,GAAG,IAAI,8BAA8B;AAAA,EACvD;AACF;AAEA,eAAe,qBACb,UACoC;AACpC,QAAM,OAAQ,MAAM,SAAS,KAAK,EAAE,MAAM,MAAM,MAAS;AAEzD,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,IAAI,uCAAuC;AAAA,MAC/C,QAAQ,SAAS;AAAA,MACjB,MAAM,iBAAiB,IAAI;AAAA,MAC3B,SAAS,oBAAoB,SAAS,QAAQ,IAAI;AAAA,MAClD,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAEA,SAAS,oBAAoB,QAAgB,MAAuB;AAClE,QAAM,gBAAgB,wBAAwB,MAAM,SAAS;AAC7D,MAAI,eAAe;AACjB,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,IAAI,KAAK,OAAO,KAAK,YAAY,UAAU;AACtD,WAAO,KAAK;AAAA,EACd;AAEA,QAAM,OAAO,iBAAiB,IAAI;AAClC,MAAI,MAAM;AACR,WAAO,2CAA2C,IAAI;AAAA,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,QACR,WAAW,KAAK;AAAA,QAChB,eAAe,KAAK;AAAA,MACtB;AAAA,IACF;AAEA;AAAA,MACE,KAAK;AAAA,MACL;AAAA,MACA,OAAO,eAAe;AAAA,IACxB;AACA,UAAM,YAAY,MAAM,OAAO,eAAe,cAAc,KAAK,SAAS;AAE1E,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,eAAe;AAAA,MACf,QAAQ;AAAA,QACN;AAAA,QACA,eAAe,OAAO,eAAe;AAAA,QACrC,WAAW,KAAK;AAAA,QAChB,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AAEA,QAAM,IAAI;AAAA,IACR,uDAAuD,OAAO,KAAK,MAAM,CAAC;AAAA,EAC5E;AACF;","names":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional first-party Account integration for Personal Server registration.
|
|
3
|
+
*
|
|
4
|
+
* The protocol helper lives in `protocol/personal-server-registration`.
|
|
5
|
+
* This module is only for callers that want to use an Account deployment's
|
|
6
|
+
* constrained silent-sign endpoint.
|
|
7
|
+
*
|
|
8
|
+
* @category Account
|
|
9
|
+
*/
|
|
10
|
+
import { type Address } from "viem";
|
|
11
|
+
import { type BuildPersonalServerRegistrationTypedDataInput, type PersonalServerRegistrationSignature, type PersonalServerRegistrationSigner, type PersonalServerRegistrationTypedData } from "../protocol/personal-server-registration";
|
|
12
|
+
export declare const ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT: "personal_server.server_registration.v1";
|
|
13
|
+
export type AccountPersonalServerRegistrationIntent = typeof ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT;
|
|
14
|
+
export type AccountPersonalServerRegistrationStatus = "signed" | "confirmation_required" | "fallback_required";
|
|
15
|
+
export interface AccountPersonalServerRegistrationRequest extends Omit<BuildPersonalServerRegistrationTypedDataInput, "ownerAddress"> {
|
|
16
|
+
}
|
|
17
|
+
export interface AccountPersonalServerRegistrationConfig {
|
|
18
|
+
/**
|
|
19
|
+
* Origin for the Account deployment to call, e.g. an app-dev Account origin.
|
|
20
|
+
* No production origin is assumed by the SDK.
|
|
21
|
+
*/
|
|
22
|
+
accountOrigin: string;
|
|
23
|
+
/**
|
|
24
|
+
* Path for Account's constrained PS registration silent-sign endpoint.
|
|
25
|
+
*/
|
|
26
|
+
endpointPath?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Optional fetch implementation for tests and non-default runtimes.
|
|
29
|
+
*/
|
|
30
|
+
fetchImpl?: typeof fetch;
|
|
31
|
+
/**
|
|
32
|
+
* Optional signer used when Account says user confirmation is required and
|
|
33
|
+
* returns typed data for the caller to sign interactively.
|
|
34
|
+
*/
|
|
35
|
+
fallbackSigner?: PersonalServerRegistrationSigner;
|
|
36
|
+
}
|
|
37
|
+
export type AccountPersonalServerRegistrationSignature = PersonalServerRegistrationSignature & {
|
|
38
|
+
intent: AccountPersonalServerRegistrationIntent;
|
|
39
|
+
};
|
|
40
|
+
export interface AccountSignedPersonalServerRegistration {
|
|
41
|
+
status: "signed";
|
|
42
|
+
result: AccountPersonalServerRegistrationSignature;
|
|
43
|
+
}
|
|
44
|
+
export interface AccountConfirmationRequiredPersonalServerRegistration {
|
|
45
|
+
status: "confirmation_required";
|
|
46
|
+
typedData: PersonalServerRegistrationTypedData;
|
|
47
|
+
signerAddress?: Address;
|
|
48
|
+
}
|
|
49
|
+
export interface AccountFallbackSignedPersonalServerRegistration {
|
|
50
|
+
status: "fallback_signed";
|
|
51
|
+
accountStatus: "confirmation_required";
|
|
52
|
+
result: AccountPersonalServerRegistrationSignature;
|
|
53
|
+
}
|
|
54
|
+
export type AccountPersonalServerRegistrationResult = AccountSignedPersonalServerRegistration | AccountConfirmationRequiredPersonalServerRegistration | AccountFallbackSignedPersonalServerRegistration;
|
|
55
|
+
export declare class AccountPersonalServerRegistrationError extends Error {
|
|
56
|
+
status: number;
|
|
57
|
+
code?: string;
|
|
58
|
+
details?: unknown;
|
|
59
|
+
constructor(input: {
|
|
60
|
+
status: number;
|
|
61
|
+
message: string;
|
|
62
|
+
code?: string;
|
|
63
|
+
details?: unknown;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export declare function signPersonalServerRegistrationWithAccount(config: AccountPersonalServerRegistrationConfig, request: AccountPersonalServerRegistrationRequest): Promise<AccountPersonalServerRegistrationResult>;
|