@opendatalabs/vana-sdk 3.0.0 → 3.0.1-pr.147.a4abdb1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/account/personal-server-lite-owner-binding.cjs +81 -0
  2. package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -0
  3. package/dist/account/personal-server-lite-owner-binding.d.ts +30 -0
  4. package/dist/account/personal-server-lite-owner-binding.js +59 -0
  5. package/dist/account/personal-server-lite-owner-binding.js.map +1 -0
  6. package/dist/account/personal-server-lite-owner-binding.test.d.ts +1 -0
  7. package/dist/account/personal-server-registration.cjs +196 -0
  8. package/dist/account/personal-server-registration.cjs.map +1 -0
  9. package/dist/account/personal-server-registration.d.ts +66 -0
  10. package/dist/account/personal-server-registration.js +172 -0
  11. package/dist/account/personal-server-registration.js.map +1 -0
  12. package/dist/account/personal-server-registration.test.d.ts +1 -0
  13. package/dist/auth/web3-signed.cjs +28 -3
  14. package/dist/auth/web3-signed.cjs.map +1 -1
  15. package/dist/auth/web3-signed.js +28 -3
  16. package/dist/auth/web3-signed.js.map +1 -1
  17. package/dist/index.browser.d.ts +5 -0
  18. package/dist/index.browser.js +562 -16
  19. package/dist/index.browser.js.map +4 -4
  20. package/dist/index.node.cjs +580 -16
  21. package/dist/index.node.cjs.map +4 -4
  22. package/dist/index.node.d.ts +5 -0
  23. package/dist/index.node.js +562 -16
  24. package/dist/index.node.js.map +4 -4
  25. package/dist/protocol/eip712.cjs.map +1 -1
  26. package/dist/protocol/eip712.d.ts +1 -1
  27. package/dist/protocol/eip712.js.map +1 -1
  28. package/dist/protocol/grants.cjs +146 -0
  29. package/dist/protocol/grants.cjs.map +1 -0
  30. package/dist/protocol/grants.d.ts +31 -0
  31. package/dist/protocol/grants.js +123 -0
  32. package/dist/protocol/grants.js.map +1 -0
  33. package/dist/protocol/grants.test.d.ts +1 -0
  34. package/dist/protocol/personal-server-lite-owner-binding.cjs +93 -0
  35. package/dist/protocol/personal-server-lite-owner-binding.cjs.map +1 -0
  36. package/dist/protocol/personal-server-lite-owner-binding.d.ts +44 -0
  37. package/dist/protocol/personal-server-lite-owner-binding.js +65 -0
  38. package/dist/protocol/personal-server-lite-owner-binding.js.map +1 -0
  39. package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +1 -0
  40. package/dist/protocol/personal-server-registration.cjs +122 -0
  41. package/dist/protocol/personal-server-registration.cjs.map +1 -0
  42. package/dist/protocol/personal-server-registration.d.ts +62 -0
  43. package/dist/protocol/personal-server-registration.js +97 -0
  44. package/dist/protocol/personal-server-registration.js.map +1 -0
  45. package/dist/protocol/personal-server-registration.test.d.ts +1 -0
  46. package/dist/storage/index.cjs.map +1 -1
  47. package/dist/storage/index.d.ts +1 -1
  48. package/dist/storage/index.js.map +1 -1
  49. package/dist/storage/providers/vana-storage.cjs +1 -1
  50. package/dist/storage/providers/vana-storage.cjs.map +1 -1
  51. package/dist/storage/providers/vana-storage.d.ts +2 -2
  52. package/dist/storage/providers/vana-storage.js +1 -1
  53. package/dist/storage/providers/vana-storage.js.map +1 -1
  54. package/dist/types/ps-errors.cjs +37 -12
  55. package/dist/types/ps-errors.cjs.map +1 -1
  56. package/dist/types/ps-errors.d.ts +7 -6
  57. package/dist/types/ps-errors.js +37 -12
  58. package/dist/types/ps-errors.js.map +1 -1
  59. package/package.json +1 -1
@@ -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";
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,196 @@
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
+ const ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
29
+ class AccountPersonalServerRegistrationError extends Error {
30
+ status;
31
+ code;
32
+ details;
33
+ constructor(input) {
34
+ super(input.message);
35
+ this.name = "AccountPersonalServerRegistrationError";
36
+ this.status = input.status;
37
+ this.code = input.code;
38
+ this.details = input.details;
39
+ }
40
+ }
41
+ const DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
42
+ function trimTrailingSlash(value) {
43
+ return value.replace(/\/+$/, "");
44
+ }
45
+ function assertAddress(value, name) {
46
+ if (!(0, import_viem.isAddress)(value)) {
47
+ throw new Error(`${name} must be a valid EVM address`);
48
+ }
49
+ }
50
+ async function parseAccountResponse(response) {
51
+ const body = await response.json().catch(() => void 0);
52
+ if (!response.ok) {
53
+ throw new AccountPersonalServerRegistrationError({
54
+ status: response.status,
55
+ code: accountErrorCode(body),
56
+ message: accountErrorMessage(response.status, body),
57
+ details: body
58
+ });
59
+ }
60
+ return body;
61
+ }
62
+ function accountErrorMessage(status, body) {
63
+ const nestedMessage = nestedAccountErrorField(body, "message");
64
+ if (nestedMessage) {
65
+ return nestedMessage;
66
+ }
67
+ if (isRecord(body) && typeof body.message === "string") {
68
+ return body.message;
69
+ }
70
+ const code = accountErrorCode(body);
71
+ if (code) {
72
+ return `Account PS registration signing failed: ${code}`;
73
+ }
74
+ return `Account PS registration signing failed: ${status}`;
75
+ }
76
+ function accountErrorCode(body) {
77
+ const nestedCode = nestedAccountErrorField(body, "code");
78
+ if (nestedCode) {
79
+ return nestedCode;
80
+ }
81
+ if (isRecord(body)) {
82
+ if (typeof body.code === "string") {
83
+ return body.code;
84
+ }
85
+ if (typeof body.error === "string") {
86
+ return body.error;
87
+ }
88
+ }
89
+ return void 0;
90
+ }
91
+ function nestedAccountErrorField(body, field) {
92
+ if (!isRecord(body) || !isRecord(body.error)) {
93
+ return void 0;
94
+ }
95
+ const value = body.error[field];
96
+ return typeof value === "string" ? value : void 0;
97
+ }
98
+ function isRecord(value) {
99
+ return typeof value === "object" && value !== null;
100
+ }
101
+ function normalizeAccountResponse(response) {
102
+ return {
103
+ ...response,
104
+ status: response.status === "fallback_required" ? "confirmation_required" : response.status,
105
+ signerAddress: response.signerAddress ?? response.signer?.address,
106
+ typedData: response.typedData ?? response.typed_data
107
+ };
108
+ }
109
+ function buildSignedResult(response, request) {
110
+ assertAddress(response.signerAddress, "signerAddress");
111
+ return {
112
+ signature: response.signature,
113
+ signerAddress: response.signerAddress,
114
+ typedData: response.typedData ?? (0, import_personal_server_registration.buildPersonalServerRegistrationTypedData)({
115
+ ownerAddress: response.signerAddress,
116
+ ...request
117
+ }),
118
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
119
+ };
120
+ }
121
+ async function signPersonalServerRegistrationWithAccount(config, request) {
122
+ assertAddress(request.serverAddress, "serverAddress");
123
+ const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
124
+ const endpoint = new URL(
125
+ config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
126
+ `${trimTrailingSlash(config.accountOrigin)}/`
127
+ );
128
+ const response = await fetchImpl(endpoint, {
129
+ method: "POST",
130
+ headers: { "content-type": "application/json" },
131
+ credentials: "include",
132
+ body: JSON.stringify({
133
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
134
+ serverAddress: request.serverAddress,
135
+ serverPublicKey: request.serverPublicKey,
136
+ serverUrl: request.serverUrl,
137
+ config: request.config,
138
+ chainId: request.chainId,
139
+ verifyingContract: request.verifyingContract
140
+ })
141
+ });
142
+ const body = normalizeAccountResponse(await parseAccountResponse(response));
143
+ if (body.status === "signed") {
144
+ if (!body.signature || !body.signerAddress) {
145
+ throw new Error(
146
+ "Account signed response must include signature and signerAddress"
147
+ );
148
+ }
149
+ return {
150
+ status: "signed",
151
+ result: buildSignedResult(
152
+ {
153
+ signature: body.signature,
154
+ signerAddress: body.signerAddress,
155
+ typedData: body.typedData
156
+ },
157
+ request
158
+ )
159
+ };
160
+ }
161
+ if (body.status === "confirmation_required") {
162
+ if (!body.typedData) {
163
+ throw new Error(
164
+ "Account confirmation_required response must include typedData"
165
+ );
166
+ }
167
+ if (!config.fallbackSigner) {
168
+ return {
169
+ status: "confirmation_required",
170
+ typedData: body.typedData,
171
+ signerAddress: body.signerAddress
172
+ };
173
+ }
174
+ const signature = await config.fallbackSigner.signTypedData(body.typedData);
175
+ return {
176
+ status: "fallback_signed",
177
+ accountStatus: "confirmation_required",
178
+ result: {
179
+ signature,
180
+ signerAddress: config.fallbackSigner.address,
181
+ typedData: body.typedData,
182
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
183
+ }
184
+ };
185
+ }
186
+ throw new Error(
187
+ `Unsupported Account PS registration signing status: ${String(body.status)}`
188
+ );
189
+ }
190
+ // Annotate the CommonJS export names for ESM import in node:
191
+ 0 && (module.exports = {
192
+ ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
193
+ AccountPersonalServerRegistrationError,
194
+ signPersonalServerRegistrationWithAccount
195
+ });
196
+ //# 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} from \"../protocol/personal-server-registration\";\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\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\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\n if (!config.fallbackSigner) {\n return {\n status: \"confirmation_required\",\n typedData: body.typedData,\n signerAddress: body.signerAddress,\n };\n }\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":"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","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>;
@@ -0,0 +1,172 @@
1
+ import { isAddress } from "viem";
2
+ import {
3
+ buildPersonalServerRegistrationTypedData
4
+ } from "../protocol/personal-server-registration";
5
+ const ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
6
+ class AccountPersonalServerRegistrationError extends Error {
7
+ status;
8
+ code;
9
+ details;
10
+ constructor(input) {
11
+ super(input.message);
12
+ this.name = "AccountPersonalServerRegistrationError";
13
+ this.status = input.status;
14
+ this.code = input.code;
15
+ this.details = input.details;
16
+ }
17
+ }
18
+ const DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
19
+ function trimTrailingSlash(value) {
20
+ return value.replace(/\/+$/, "");
21
+ }
22
+ function assertAddress(value, name) {
23
+ if (!isAddress(value)) {
24
+ throw new Error(`${name} must be a valid EVM address`);
25
+ }
26
+ }
27
+ async function parseAccountResponse(response) {
28
+ const body = await response.json().catch(() => void 0);
29
+ if (!response.ok) {
30
+ throw new AccountPersonalServerRegistrationError({
31
+ status: response.status,
32
+ code: accountErrorCode(body),
33
+ message: accountErrorMessage(response.status, body),
34
+ details: body
35
+ });
36
+ }
37
+ return body;
38
+ }
39
+ function accountErrorMessage(status, body) {
40
+ const nestedMessage = nestedAccountErrorField(body, "message");
41
+ if (nestedMessage) {
42
+ return nestedMessage;
43
+ }
44
+ if (isRecord(body) && typeof body.message === "string") {
45
+ return body.message;
46
+ }
47
+ const code = accountErrorCode(body);
48
+ if (code) {
49
+ return `Account PS registration signing failed: ${code}`;
50
+ }
51
+ return `Account PS registration signing failed: ${status}`;
52
+ }
53
+ function accountErrorCode(body) {
54
+ const nestedCode = nestedAccountErrorField(body, "code");
55
+ if (nestedCode) {
56
+ return nestedCode;
57
+ }
58
+ if (isRecord(body)) {
59
+ if (typeof body.code === "string") {
60
+ return body.code;
61
+ }
62
+ if (typeof body.error === "string") {
63
+ return body.error;
64
+ }
65
+ }
66
+ return void 0;
67
+ }
68
+ function nestedAccountErrorField(body, field) {
69
+ if (!isRecord(body) || !isRecord(body.error)) {
70
+ return void 0;
71
+ }
72
+ const value = body.error[field];
73
+ return typeof value === "string" ? value : void 0;
74
+ }
75
+ function isRecord(value) {
76
+ return typeof value === "object" && value !== null;
77
+ }
78
+ function normalizeAccountResponse(response) {
79
+ return {
80
+ ...response,
81
+ status: response.status === "fallback_required" ? "confirmation_required" : response.status,
82
+ signerAddress: response.signerAddress ?? response.signer?.address,
83
+ typedData: response.typedData ?? response.typed_data
84
+ };
85
+ }
86
+ function buildSignedResult(response, request) {
87
+ assertAddress(response.signerAddress, "signerAddress");
88
+ return {
89
+ signature: response.signature,
90
+ signerAddress: response.signerAddress,
91
+ typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
92
+ ownerAddress: response.signerAddress,
93
+ ...request
94
+ }),
95
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
96
+ };
97
+ }
98
+ async function signPersonalServerRegistrationWithAccount(config, request) {
99
+ assertAddress(request.serverAddress, "serverAddress");
100
+ const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
101
+ const endpoint = new URL(
102
+ config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
103
+ `${trimTrailingSlash(config.accountOrigin)}/`
104
+ );
105
+ const response = await fetchImpl(endpoint, {
106
+ method: "POST",
107
+ headers: { "content-type": "application/json" },
108
+ credentials: "include",
109
+ body: JSON.stringify({
110
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
111
+ serverAddress: request.serverAddress,
112
+ serverPublicKey: request.serverPublicKey,
113
+ serverUrl: request.serverUrl,
114
+ config: request.config,
115
+ chainId: request.chainId,
116
+ verifyingContract: request.verifyingContract
117
+ })
118
+ });
119
+ const body = normalizeAccountResponse(await parseAccountResponse(response));
120
+ if (body.status === "signed") {
121
+ if (!body.signature || !body.signerAddress) {
122
+ throw new Error(
123
+ "Account signed response must include signature and signerAddress"
124
+ );
125
+ }
126
+ return {
127
+ status: "signed",
128
+ result: buildSignedResult(
129
+ {
130
+ signature: body.signature,
131
+ signerAddress: body.signerAddress,
132
+ typedData: body.typedData
133
+ },
134
+ request
135
+ )
136
+ };
137
+ }
138
+ if (body.status === "confirmation_required") {
139
+ if (!body.typedData) {
140
+ throw new Error(
141
+ "Account confirmation_required response must include typedData"
142
+ );
143
+ }
144
+ if (!config.fallbackSigner) {
145
+ return {
146
+ status: "confirmation_required",
147
+ typedData: body.typedData,
148
+ signerAddress: body.signerAddress
149
+ };
150
+ }
151
+ const signature = await config.fallbackSigner.signTypedData(body.typedData);
152
+ return {
153
+ status: "fallback_signed",
154
+ accountStatus: "confirmation_required",
155
+ result: {
156
+ signature,
157
+ signerAddress: config.fallbackSigner.address,
158
+ typedData: body.typedData,
159
+ intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
160
+ }
161
+ };
162
+ }
163
+ throw new Error(
164
+ `Unsupported Account PS registration signing status: ${String(body.status)}`
165
+ );
166
+ }
167
+ export {
168
+ ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
169
+ AccountPersonalServerRegistrationError,
170
+ signPersonalServerRegistrationWithAccount
171
+ };
172
+ //# sourceMappingURL=personal-server-registration.js.map