@polyester/sdk 0.12.0 → 0.13.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.
Files changed (139) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/core-client.d.ts +3 -3
  3. package/dist/core-client.d.ts.map +1 -1
  4. package/dist/core-client.js +35 -50
  5. package/dist/core-client.js.map +1 -1
  6. package/dist/services/accounts/accounts.d.ts +2 -2
  7. package/dist/services/accounts/accounts.d.ts.map +1 -1
  8. package/dist/services/accounts/accounts.js +2 -2
  9. package/dist/services/accounts/accounts.js.map +1 -1
  10. package/dist/services/address-book/address-book.d.ts +2 -2
  11. package/dist/services/address-book/address-book.d.ts.map +1 -1
  12. package/dist/services/address-book/address-book.js +2 -2
  13. package/dist/services/address-book/address-book.js.map +1 -1
  14. package/dist/services/api-keys/api-keys.d.ts +2 -2
  15. package/dist/services/api-keys/api-keys.d.ts.map +1 -1
  16. package/dist/services/api-keys/api-keys.js +3 -3
  17. package/dist/services/api-keys/api-keys.js.map +1 -1
  18. package/dist/services/auth/account-signer-auth.d.ts +3 -2
  19. package/dist/services/auth/account-signer-auth.d.ts.map +1 -1
  20. package/dist/services/auth/account-signer-auth.js.map +1 -1
  21. package/dist/services/auth/auth.d.ts +3 -7
  22. package/dist/services/auth/auth.d.ts.map +1 -1
  23. package/dist/services/auth/auth.js +1 -1
  24. package/dist/services/auth/auth.js.map +1 -1
  25. package/dist/services/auth/profile/profile.d.ts +2 -2
  26. package/dist/services/auth/profile/profile.d.ts.map +1 -1
  27. package/dist/services/auth/profile/profile.js +2 -2
  28. package/dist/services/auth/profile/profile.js.map +1 -1
  29. package/dist/services/balances/balances.d.ts +2 -2
  30. package/dist/services/balances/balances.d.ts.map +1 -1
  31. package/dist/services/balances/balances.js +2 -2
  32. package/dist/services/balances/balances.js.map +1 -1
  33. package/dist/services/candles/candles.d.ts +2 -2
  34. package/dist/services/candles/candles.d.ts.map +1 -1
  35. package/dist/services/candles/candles.js +2 -2
  36. package/dist/services/candles/candles.js.map +1 -1
  37. package/dist/services/chain-analytics/chain-analytics.d.ts +2 -2
  38. package/dist/services/chain-analytics/chain-analytics.d.ts.map +1 -1
  39. package/dist/services/chain-analytics/chain-analytics.js +2 -2
  40. package/dist/services/chain-analytics/chain-analytics.js.map +1 -1
  41. package/dist/services/deposit/deposit.d.ts +2 -2
  42. package/dist/services/deposit/deposit.d.ts.map +1 -1
  43. package/dist/services/deposit/deposit.js +2 -2
  44. package/dist/services/deposit/deposit.js.map +1 -1
  45. package/dist/services/fees/fees.d.ts +2 -2
  46. package/dist/services/fees/fees.d.ts.map +1 -1
  47. package/dist/services/fees/fees.js +2 -2
  48. package/dist/services/fees/fees.js.map +1 -1
  49. package/dist/services/guard-signer/guard-signer.d.ts +2 -2
  50. package/dist/services/guard-signer/guard-signer.d.ts.map +1 -1
  51. package/dist/services/guard-signer/guard-signer.js +2 -2
  52. package/dist/services/guard-signer/guard-signer.js.map +1 -1
  53. package/dist/services/heatmap/heatmap.d.ts +2 -2
  54. package/dist/services/heatmap/heatmap.d.ts.map +1 -1
  55. package/dist/services/heatmap/heatmap.js +2 -2
  56. package/dist/services/heatmap/heatmap.js.map +1 -1
  57. package/dist/services/internal-transfers/internal-transfers.d.ts +2 -2
  58. package/dist/services/internal-transfers/internal-transfers.d.ts.map +1 -1
  59. package/dist/services/internal-transfers/internal-transfers.js +2 -2
  60. package/dist/services/internal-transfers/internal-transfers.js.map +1 -1
  61. package/dist/services/lifecycle/lifecycle.d.ts +2 -2
  62. package/dist/services/lifecycle/lifecycle.d.ts.map +1 -1
  63. package/dist/services/lifecycle/lifecycle.js +2 -2
  64. package/dist/services/lifecycle/lifecycle.js.map +1 -1
  65. package/dist/services/lifecycle/lifecycle.schemas.d.ts +42 -42
  66. package/dist/services/market-data/market-data.d.ts +2 -2
  67. package/dist/services/market-data/market-data.d.ts.map +1 -1
  68. package/dist/services/market-data/market-data.js +2 -2
  69. package/dist/services/market-data/market-data.js.map +1 -1
  70. package/dist/services/market-overview/market-overview.d.ts +2 -2
  71. package/dist/services/market-overview/market-overview.d.ts.map +1 -1
  72. package/dist/services/market-overview/market-overview.js +2 -2
  73. package/dist/services/market-overview/market-overview.js.map +1 -1
  74. package/dist/services/mfa/mfa.d.ts +2 -2
  75. package/dist/services/mfa/mfa.d.ts.map +1 -1
  76. package/dist/services/mfa/mfa.js +2 -2
  77. package/dist/services/mfa/mfa.js.map +1 -1
  78. package/dist/services/orderbook/orderbook.d.ts +2 -2
  79. package/dist/services/orderbook/orderbook.d.ts.map +1 -1
  80. package/dist/services/orderbook/orderbook.js +2 -2
  81. package/dist/services/orderbook/orderbook.js.map +1 -1
  82. package/dist/services/orders/orders-input.schemas.d.ts +1 -1
  83. package/dist/services/orders/orders-output.schemas.d.ts +6 -6
  84. package/dist/services/orders/orders.d.ts +2 -2
  85. package/dist/services/orders/orders.d.ts.map +1 -1
  86. package/dist/services/orders/orders.js +3 -3
  87. package/dist/services/orders/orders.js.map +1 -1
  88. package/dist/services/policies/api-key-policies/api-key-policies.d.ts +2 -2
  89. package/dist/services/policies/api-key-policies/api-key-policies.d.ts.map +1 -1
  90. package/dist/services/policies/api-key-policies/api-key-policies.js +2 -2
  91. package/dist/services/policies/api-key-policies/api-key-policies.js.map +1 -1
  92. package/dist/services/policies/subaccount-policies/subaccount-policies.d.ts +2 -2
  93. package/dist/services/policies/subaccount-policies/subaccount-policies.d.ts.map +1 -1
  94. package/dist/services/policies/subaccount-policies/subaccount-policies.js +2 -2
  95. package/dist/services/policies/subaccount-policies/subaccount-policies.js.map +1 -1
  96. package/dist/services/rate-limits/rate-limits.d.ts +2 -2
  97. package/dist/services/rate-limits/rate-limits.d.ts.map +1 -1
  98. package/dist/services/rate-limits/rate-limits.js.map +1 -1
  99. package/dist/services/social-verification/social-verification.d.ts +2 -2
  100. package/dist/services/social-verification/social-verification.d.ts.map +1 -1
  101. package/dist/services/social-verification/social-verification.js +2 -2
  102. package/dist/services/social-verification/social-verification.js.map +1 -1
  103. package/dist/services/subaccounts/subaccounts.d.ts +3 -3
  104. package/dist/services/subaccounts/subaccounts.d.ts.map +1 -1
  105. package/dist/services/subaccounts/subaccounts.js +11 -9
  106. package/dist/services/subaccounts/subaccounts.js.map +1 -1
  107. package/dist/services/subaccounts/subaccounts.schemas.d.ts +4 -4
  108. package/dist/services/trades/trades.d.ts +2 -2
  109. package/dist/services/trades/trades.d.ts.map +1 -1
  110. package/dist/services/trades/trades.js +2 -2
  111. package/dist/services/trades/trades.js.map +1 -1
  112. package/dist/services/trading-withdraws/trading-withdraws.d.ts +2 -2
  113. package/dist/services/trading-withdraws/trading-withdraws.d.ts.map +1 -1
  114. package/dist/services/trading-withdraws/trading-withdraws.js +2 -2
  115. package/dist/services/trading-withdraws/trading-withdraws.js.map +1 -1
  116. package/dist/services/transfers/transfers.d.ts +2 -2
  117. package/dist/services/transfers/transfers.d.ts.map +1 -1
  118. package/dist/services/transfers/transfers.js +2 -2
  119. package/dist/services/transfers/transfers.js.map +1 -1
  120. package/dist/services/triggers/trigger-input.schemas.d.ts +1 -1
  121. package/dist/services/triggers/triggers-output.schemas.d.ts +15 -15
  122. package/dist/services/triggers/triggers.d.ts +2 -2
  123. package/dist/services/triggers/triggers.d.ts.map +1 -1
  124. package/dist/services/triggers/triggers.js +2 -2
  125. package/dist/services/triggers/triggers.js.map +1 -1
  126. package/dist/services/vip/vip.d.ts +2 -2
  127. package/dist/services/vip/vip.js.map +1 -1
  128. package/dist/services/whiteboard/whiteboard.d.ts +2 -2
  129. package/dist/services/whiteboard/whiteboard.d.ts.map +1 -1
  130. package/dist/services/whiteboard/whiteboard.js +2 -2
  131. package/dist/services/whiteboard/whiteboard.js.map +1 -1
  132. package/dist/services/zipper/zipper.d.ts +2 -2
  133. package/dist/services/zipper/zipper.d.ts.map +1 -1
  134. package/dist/services/zipper/zipper.js +2 -2
  135. package/dist/services/zipper/zipper.js.map +1 -1
  136. package/dist/shared/transports.d.ts +7 -1
  137. package/dist/shared/transports.d.ts.map +1 -1
  138. package/dist/shared/transports.js.map +1 -1
  139. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"api-keys.js","names":["#client","Proto.ApiKeyService","#realtime","#resolver","ApiKeySchema","Proto.ApiKeySchema"],"sources":["../../../src/services/api-keys/api-keys.ts"],"sourcesContent":["import { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport * as Proto from \"../../gen/auth/v1/api_keys_pb.js\";\nimport type * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport { removeUndefined } from \"../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport { bytesToHex } from \"@noble/hashes/utils.js\";\nimport { keygenAsync } from \"@noble/ed25519\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport { ApiKeyPoliciesService } from \"../policies/api-key-policies/index.js\";\nimport {\n ApiKeyIdInputSchema,\n ApiKeysListInputSchema,\n ApiKeysCreateInputSchema,\n ApiKeysUpdateInputSchema,\n ApiKeySchema,\n ApiKeysSchema,\n type ApiKey,\n} from \"./api-keys.schemas.js\";\n\ninterface SubscribeApiKeysInput extends BaseSubscribeInput<ApiKey> {\n accountId: string;\n}\n\n/**\n * Manages API key metadata, client-generated Ed25519 keypairs, policies, and realtime API key updates.\n */\nexport class ApiKeysService {\n readonly policies: ApiKeyPoliciesService;\n\n #client: Client<typeof Proto.ApiKeyService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n\n constructor(transport: Transport, realtime: PolyesterRealtime, resolver?: SubaccountResolver) {\n this.policies = new ApiKeyPoliciesService(transport);\n this.#client = createClient(Proto.ApiKeyService, transport);\n this.#realtime = realtime;\n this.#resolver = resolver;\n }\n\n /**\n * Returns non-revoked API keys owned by the caller, newest first, optionally scoped through an explicit or resolver-provided subaccount ID.\n */\n async list(\n params: v.InferInput<typeof ApiKeysListInputSchema> = {},\n options?: PolyesterRequestOptions,\n ): Promise<ApiKey[]> {\n const resolved = resolveAccountScopedInput(params, this.#resolver);\n const validatedParams = parse(ApiKeysListInputSchema, resolved);\n const res = await this.#client.listApiKeys(\n removeUndefined(validatedParams),\n toConnectCallOptions(options),\n );\n\n return parse(ApiKeysSchema, res.apiKeys);\n }\n\n /**\n * Fetches one caller-owned API key by ak_... key ID and returns null when no matching key is returned.\n */\n async get(\n input: v.InferInput<typeof ApiKeyIdInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<ApiKey | null> {\n const validatedInput = parse(ApiKeyIdInputSchema, input);\n const res = await this.#client.getApiKey(validatedInput, toConnectCallOptions(options));\n return res.apiKey ? parse(ApiKeySchema, res.apiKey) : null;\n }\n\n /**\n * Creates API key metadata using a client-generated Ed25519 public key; security settings may require MFA fresh step-up and retrying with stepUpToken.\n */\n async create(\n payload: v.InferInput<typeof ApiKeysCreateInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<ApiKey | null> {\n const resolved = resolveAccountScopedInput(payload, this.#resolver);\n const validatedPayload = parse(ApiKeysCreateInputSchema, resolved);\n const res = await this.#client.createApiKey(\n removeUndefined(validatedPayload),\n toConnectCallOptions(options),\n );\n return res.apiKey ? parse(ApiKeySchema, res.apiKey) : null;\n }\n\n /**\n * Permanently revokes the specified API key; revoked keys cannot authenticate again.\n */\n async delete(\n input: v.InferInput<typeof ApiKeyIdInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<void> {\n const validatedInput = parse(ApiKeyIdInputSchema, input);\n await this.#client.deleteApiKey(validatedInput, toConnectCallOptions(options));\n }\n\n /**\n * Updates mutable key metadata, ACTIVE/DISABLED status, IP whitelist replacement/clearing, and optional expiry; revocation must use delete.\n */\n async update(\n payload: v.InferInput<typeof ApiKeysUpdateInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<ApiKey | null> {\n const validatedPayload = parse(ApiKeysUpdateInputSchema, payload);\n const res = await this.#client.updateApiKey(\n removeUndefined(validatedPayload),\n toConnectCallOptions(options),\n );\n return res.apiKey ? parse(ApiKeySchema, res.apiKey) : null;\n }\n\n /**\n * Generates an Ed25519 keypair locally and returns public and secret key material as both hex strings and byte arrays; only the public key should be sent to the API.\n */\n async generateKeypair(): Promise<{\n publicKey: { hex: string; bytes: Uint8Array };\n secretKey: { hex: string; bytes: Uint8Array };\n }> {\n const { secretKey, publicKey } = await keygenAsync();\n return {\n publicKey: {\n hex: bytesToHex(publicKey),\n bytes: publicKey,\n },\n secretKey: {\n hex: bytesToHex(secretKey),\n bytes: secretKey,\n },\n };\n }\n\n /**\n * Subscribes to private API key updates for an account and emits normalized API key metadata from realtime protobuf publications.\n */\n subscribe(input: SubscribeApiKeysInput) {\n const channel = `private:auth:api-keys:${input.accountId}:proto`;\n\n return this.#realtime.connectProtoChannel({\n channel,\n schema: Proto.ApiKeySchema,\n onPublication: (data) => {\n const apiKey = parse(ApiKeySchema, data);\n input.onEvent(apiKey);\n },\n onConnected: () => input.onOpen?.(),\n onDisconnected: () => input.onClose?.(),\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAiCA,IAAa,iBAAb,MAA4B;CACxB;CAEA;CACA;CACA;CAEA,YAAY,WAAsB,UAA6B,UAA+B;EAC1F,KAAK,WAAW,IAAI,sBAAsB,SAAS;EACnD,KAAKA,UAAU,aAAaC,eAAqB,SAAS;EAC1D,KAAKC,YAAY;EACjB,KAAKC,YAAY;CACrB;;;;CAKA,MAAM,KACF,SAAsD,CAAC,GACvD,SACiB;EACjB,MAAM,WAAW,0BAA0B,QAAQ,KAAKA,SAAS;EACjE,MAAM,kBAAkB,MAAM,wBAAwB,QAAQ;EAC9D,MAAM,MAAM,MAAM,KAAKH,QAAQ,YAC3B,gBAAgB,eAAe,GAC/B,qBAAqB,OAAO,CAChC;EAEA,OAAO,MAAM,eAA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AAM,QAAQ,MAAM;GACxB;GACA,mBAAmB,MAAM,SAAS;GAClC,sBAAsB,MAAM,UAAU;GACtC,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
1
+ {"version":3,"file":"api-keys.js","names":["#client","Proto.ApiKeyService","#realtime","#resolver","ApiKeySchema","Proto.ApiKeySchema"],"sources":["../../../src/services/api-keys/api-keys.ts"],"sourcesContent":["import { createClient, type Client } from \"@connectrpc/connect\";\nimport * as Proto from \"../../gen/auth/v1/api_keys_pb.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport type * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport { removeUndefined } from \"../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport { bytesToHex } from \"@noble/hashes/utils.js\";\nimport { keygenAsync } from \"@noble/ed25519\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport { ApiKeyPoliciesService } from \"../policies/api-key-policies/index.js\";\nimport {\n ApiKeyIdInputSchema,\n ApiKeysListInputSchema,\n ApiKeysCreateInputSchema,\n ApiKeysUpdateInputSchema,\n ApiKeySchema,\n ApiKeysSchema,\n type ApiKey,\n} from \"./api-keys.schemas.js\";\n\ninterface SubscribeApiKeysInput extends BaseSubscribeInput<ApiKey> {\n accountId: string;\n}\n\n/**\n * Manages API key metadata, client-generated Ed25519 keypairs, policies, and realtime API key updates.\n */\nexport class ApiKeysService {\n readonly policies: ApiKeyPoliciesService;\n\n #client: Client<typeof Proto.ApiKeyService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n\n constructor(\n transports: AuthApiTransports,\n realtime: PolyesterRealtime,\n resolver?: SubaccountResolver,\n ) {\n this.policies = new ApiKeyPoliciesService(transports);\n this.#client = createClient(Proto.ApiKeyService, transports.authApi);\n this.#realtime = realtime;\n this.#resolver = resolver;\n }\n\n /**\n * Returns non-revoked API keys owned by the caller, newest first, optionally scoped through an explicit or resolver-provided subaccount ID.\n */\n async list(\n params: v.InferInput<typeof ApiKeysListInputSchema> = {},\n options?: PolyesterRequestOptions,\n ): Promise<ApiKey[]> {\n const resolved = resolveAccountScopedInput(params, this.#resolver);\n const validatedParams = parse(ApiKeysListInputSchema, resolved);\n const res = await this.#client.listApiKeys(\n removeUndefined(validatedParams),\n toConnectCallOptions(options),\n );\n\n return parse(ApiKeysSchema, res.apiKeys);\n }\n\n /**\n * Fetches one caller-owned API key by ak_... key ID and returns null when no matching key is returned.\n */\n async get(\n input: v.InferInput<typeof ApiKeyIdInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<ApiKey | null> {\n const validatedInput = parse(ApiKeyIdInputSchema, input);\n const res = await this.#client.getApiKey(validatedInput, toConnectCallOptions(options));\n return res.apiKey ? parse(ApiKeySchema, res.apiKey) : null;\n }\n\n /**\n * Creates API key metadata using a client-generated Ed25519 public key; security settings may require MFA fresh step-up and retrying with stepUpToken.\n */\n async create(\n payload: v.InferInput<typeof ApiKeysCreateInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<ApiKey | null> {\n const resolved = resolveAccountScopedInput(payload, this.#resolver);\n const validatedPayload = parse(ApiKeysCreateInputSchema, resolved);\n const res = await this.#client.createApiKey(\n removeUndefined(validatedPayload),\n toConnectCallOptions(options),\n );\n return res.apiKey ? parse(ApiKeySchema, res.apiKey) : null;\n }\n\n /**\n * Permanently revokes the specified API key; revoked keys cannot authenticate again.\n */\n async delete(\n input: v.InferInput<typeof ApiKeyIdInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<void> {\n const validatedInput = parse(ApiKeyIdInputSchema, input);\n await this.#client.deleteApiKey(validatedInput, toConnectCallOptions(options));\n }\n\n /**\n * Updates mutable key metadata, ACTIVE/DISABLED status, IP whitelist replacement/clearing, and optional expiry; revocation must use delete.\n */\n async update(\n payload: v.InferInput<typeof ApiKeysUpdateInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<ApiKey | null> {\n const validatedPayload = parse(ApiKeysUpdateInputSchema, payload);\n const res = await this.#client.updateApiKey(\n removeUndefined(validatedPayload),\n toConnectCallOptions(options),\n );\n return res.apiKey ? parse(ApiKeySchema, res.apiKey) : null;\n }\n\n /**\n * Generates an Ed25519 keypair locally and returns public and secret key material as both hex strings and byte arrays; only the public key should be sent to the API.\n */\n async generateKeypair(): Promise<{\n publicKey: { hex: string; bytes: Uint8Array };\n secretKey: { hex: string; bytes: Uint8Array };\n }> {\n const { secretKey, publicKey } = await keygenAsync();\n return {\n publicKey: {\n hex: bytesToHex(publicKey),\n bytes: publicKey,\n },\n secretKey: {\n hex: bytesToHex(secretKey),\n bytes: secretKey,\n },\n };\n }\n\n /**\n * Subscribes to private API key updates for an account and emits normalized API key metadata from realtime protobuf publications.\n */\n subscribe(input: SubscribeApiKeysInput) {\n const channel = `private:auth:api-keys:${input.accountId}:proto`;\n\n return this.#realtime.connectProtoChannel({\n channel,\n schema: Proto.ApiKeySchema,\n onPublication: (data) => {\n const apiKey = parse(ApiKeySchema, data);\n input.onEvent(apiKey);\n },\n onConnected: () => input.onOpen?.(),\n onDisconnected: () => input.onClose?.(),\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAkCA,IAAa,iBAAb,MAA4B;CACxB;CAEA;CACA;CACA;CAEA,YACI,YACA,UACA,UACF;EACE,KAAK,WAAW,IAAI,sBAAsB,UAAU;EACpD,KAAKA,UAAU,aAAaC,eAAqB,WAAW,OAAO;EACnE,KAAKC,YAAY;EACjB,KAAKC,YAAY;CACrB;;;;CAKA,MAAM,KACF,SAAsD,CAAC,GACvD,SACiB;EACjB,MAAM,WAAW,0BAA0B,QAAQ,KAAKA,SAAS;EACjE,MAAM,kBAAkB,MAAM,wBAAwB,QAAQ;EAC9D,MAAM,MAAM,MAAM,K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;GACtC;GACA,QAAQG;GACR,gBAAgB,SAAS;IACrB,MAAM,SAAS,MAAMD,gBAAc,IAAI;IACvC,MAAM,QAAQ,MAAM;GACxB;GACA,mBAAmB,MAAM,SAAS;GAClC,sBAAsB,MAAM,UAAU;GACtC,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
@@ -1,8 +1,9 @@
1
1
  import { AccountSigner, AccountSignerConfig } from "../../account-signer/types.js";
2
2
  import { PolyesterEnvironment } from "../../environment.js";
3
+ import { AuthAndPublicApiTransports } from "../../shared/transports.js";
3
4
  import { PolyesterRealtime } from "../../realtime/types.js";
4
5
  import "../../realtime/index.js";
5
- import { AuthService, AuthServiceTransports } from "./auth.js";
6
+ import { AuthService } from "./auth.js";
6
7
  import { SubaccountsService } from "../subaccounts/subaccounts.js";
7
8
  import "../subaccounts/index.js";
8
9
  import { AuthTokenStorage } from "./token-storage.js";
@@ -55,7 +56,7 @@ declare class AccountSignerAuthService extends AuthService {
55
56
  #private;
56
57
  readonly events: EventEmitter<AccountSignerAuthEvents>;
57
58
  constructor({ transports, accountSignerConfig, environment, subaccounts, realtime, tokenStorage, sessionStore }: {
58
- transports: AuthServiceTransports;
59
+ transports: AuthAndPublicApiTransports;
59
60
  accountSignerConfig?: AccountSignerConfig;
60
61
  environment: PolyesterEnvironment;
61
62
  subaccounts: SubaccountsService;
@@ -1 +1 @@
1
- {"version":3,"file":"account-signer-auth.d.ts","names":[],"sources":["../../../src/services/auth/account-signer-auth.ts"],"mappings":";;;;;;;;;;;;UAuBiB;EACb;IAAiB;IAAmB;;EACpC;EACA;IAAS;IAAc;;EACvB;EACA,aAAa;;UAGA;EACb;EACA;EACA,WAAW;;UAGE;;;;EAIb;EACA,cAAc;;UAGD;;EAEb,eAAe;;EAEf;;EAEA;;UAGa;EACb;EACA;EACA;;;;;cAWS,iCAAiC;;WACjC,QAAM,aAAA;EAgBH,cACR,YACA,qBACA,aACA,aACA,UACA,cACA;IAEA,YAAY;IACZ,sBAAsB;IACtB,aAAa;IACb,aAAa;IACb,UAAU;IACV,cAAc;IACd,eAAe;;;;;EAmBnB,sBAAsB,aAAa;;;;EAOnC,iBAAiB,eAAe;;;;EAUhC,oBAAoB;;;;EAOd,MAAM,SAAS,eAAe,QAAQ;;;;EA2F5C,iBAAiB,OAAO;;;;EAwBlB,kBAAkB;IAAU;IAAmB;;;;;EA6D/C,UAAU;;;;EAkChB;;;;EASM,eAAe;IACjB;IACA,cAAc;MACd,QAAQ;;;;EAkBZ,cACI,mBACA;IAAY;IAA8B;;IACzC;IAAmB;;;EAuBxB,oBAAoB;;;;EASd,iBAAiB,QAAQ,yBAAyB,QAAQ;;;;EA+ChE,YAAY"}
1
+ {"version":3,"file":"account-signer-auth.d.ts","names":[],"sources":["../../../src/services/auth/account-signer-auth.ts"],"mappings":";;;;;;;;;;;;;UAwBiB;EACb;IAAiB;IAAmB;;EACpC;EACA;IAAS;IAAc;;EACvB;EACA,aAAa;;UAGA;EACb;EACA;EACA,WAAW;;UAGE;;;;EAIb;EACA,cAAc;;UAGD;;EAEb,eAAe;;EAEf;;EAEA;;UAGa;EACb;EACA;EACA;;;;;cAWS,iCAAiC;;WACjC,QAAM,aAAA;EAgBH,cACR,YACA,qBACA,aACA,aACA,UACA,cACA;IAEA,YAAY;IACZ,sBAAsB;IACtB,aAAa;IACb,aAAa;IACb,UAAU;IACV,cAAc;IACd,eAAe;;;;;EAmBnB,sBAAsB,aAAa;;;;EAOnC,iBAAiB,eAAe;;;;EAUhC,oBAAoB;;;;EAOd,MAAM,SAAS,eAAe,QAAQ;;;;EA2F5C,iBAAiB,OAAO;;;;EAwBlB,kBAAkB;IAAU;IAAmB;;;;;EA6D/C,UAAU;;;;EAkChB;;;;EASM,eAAe;IACjB;IACA,cAAc;MACd,QAAQ;;;;EAkBZ,cACI,mBACA;IAAY;IAA8B;;IACzC;IAAmB;;;EAuBxB,oBAAoB;;;;EASd,iBAAiB,QAAQ,yBAAyB,QAAQ;;;;EA+ChE,YAAY"}
@@ -1 +1 @@
1
- {"version":3,"file":"account-signer-auth.js","names":["#accountSignerConfig","#environmentFingerprint","#subaccounts","#tokenStorage","#realtime","#sessionStore","#assertAccountSignerEnvironment","#accountSigner","#accountIdentity","#identityFromSigner","#notifyStateChange","#login","#resolveAccountSigner","#getEnvironmentSession","#loginMethod","#isAuthenticated","#mainAccountId","#activeAccountId","#walletProvider","#getEnvironmentBoundToken","#clearExpiredSessionState","#getCurrentTokenStorageOptions","#resolveRefreshProvider"],"sources":["../../../src/services/auth/account-signer-auth.ts"],"sourcesContent":["import { AuthService, type AuthServiceTransports } from \"./auth.js\";\nimport { AuthenticationError, ConfigurationError } from \"../../shared/errors.js\";\nimport { AuthSessionStore } from \"./session.js\";\nimport type { AccountSigner, AccountSignerConfig, HexAddress } from \"../../account-signer/types.js\";\nimport { assertAccountSigner, resolveAccountSigner } from \"../../account-signer/types.js\";\nimport { EventEmitter } from \"../../utils/event-emitter.js\";\nimport { isJwtValid, getJwtTimeToExpiry } from \"../../utils/jwt.js\";\nimport type { SubaccountsService } from \"../subaccounts/index.js\";\nimport type {\n AuthState,\n AuthHydrationData,\n AuthLoginMethod,\n SessionData,\n ActiveAccountInfo,\n} from \"./session.types.js\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport type { PolyesterEnvironment } from \"../../environment.js\";\nimport {\n createAuthTokenStorageSetOptions,\n type AuthTokenStorage,\n type AuthTokenStorageSetOptions,\n} from \"./token-storage.js\";\n\nexport interface AccountSignerAuthEvents {\n authenticated: { accountId: string; username: string };\n loggedOut: void;\n error: { code: string; message: string };\n servicesReady: void;\n stateChange: AuthState;\n}\n\nexport interface LoginResult {\n accountId: string;\n username: string;\n expiresAt: Date;\n}\n\nexport interface LoginOptions {\n /**\n * The wallet provider to use for login.\n */\n provider: \"metamask\" | \"turnkey\" | \"other\";\n loginMethod?: AuthLoginMethod | null;\n}\n\nexport interface CreateSubaccountParams {\n /** The account signer for the new subaccount (caller derives this, e.g. via Turnkey saltNonce) */\n accountSigner: AccountSigner;\n /** Optional human-readable label for this subaccount */\n label?: string;\n /** Wallet provider hint (e.g. \"turnkey\", \"metamask\"). Defaults to \"wallet\" */\n walletProvider?: string;\n}\n\nexport interface CreateSubaccountResult {\n subaccountId: string;\n smartAccountSaltNonce: number;\n revision: string;\n}\n\ninterface AccountIdentity {\n accountAddress: HexAddress;\n ownerAddress?: HexAddress;\n}\n\n/**\n * Coordinates wallet/account-signer authentication, session storage, subaccount selection, and session refresh.\n */\nexport class AccountSignerAuthService extends AuthService {\n readonly events = new EventEmitter<AccountSignerAuthEvents>();\n\n #accountSignerConfig: AccountSignerConfig | undefined;\n #accountSigner: AccountSigner | null = null;\n #accountIdentity: AccountIdentity | null = null;\n #isAuthenticated = false;\n #mainAccountId: string | null = null;\n #activeAccountId: string | null = null;\n #subaccounts: SubaccountsService;\n #walletProvider: \"metamask\" | \"turnkey\" | \"other\" | undefined = undefined;\n #loginMethod: AuthLoginMethod | null = null;\n #environmentFingerprint: string;\n #tokenStorage: AuthTokenStorage;\n #sessionStore: AuthSessionStore;\n #realtime: PolyesterRealtime;\n\n constructor({\n transports,\n accountSignerConfig,\n environment,\n subaccounts,\n realtime,\n tokenStorage,\n sessionStore,\n }: {\n transports: AuthServiceTransports;\n accountSignerConfig?: AccountSignerConfig;\n environment: PolyesterEnvironment;\n subaccounts: SubaccountsService;\n realtime: PolyesterRealtime;\n tokenStorage: AuthTokenStorage;\n sessionStore?: AuthSessionStore;\n }) {\n super(transports, realtime);\n\n this.#accountSignerConfig = accountSignerConfig;\n this.#environmentFingerprint = environment.fingerprint;\n this.#subaccounts = subaccounts;\n this.#tokenStorage = tokenStorage;\n this.#realtime = realtime;\n this.#sessionStore =\n sessionStore ??\n new AuthSessionStore({\n environmentFingerprint: environment.fingerprint,\n });\n }\n\n /**\n * Attaches the subaccounts service used when creating a subaccount during authenticated flows.\n */\n setSubaccountsService(subaccounts: SubaccountsService): void {\n this.#subaccounts = subaccounts;\n }\n\n /**\n * Sets the account signer used to sign login and account-switch challenges.\n */\n setAccountSigner(accountSigner: AccountSigner | null): void {\n if (accountSigner) this.#assertAccountSignerEnvironment(accountSigner);\n this.#accountSigner = accountSigner;\n this.#accountIdentity = accountSigner ? this.#identityFromSigner(accountSigner) : null;\n this.#notifyStateChange();\n }\n\n /**\n * Returns the active account signer, throwing if one has not been configured.\n */\n getAccountSigner(): AccountSigner | null {\n return this.#accountSigner;\n }\n\n /**\n * Signs a short-lived login nonce with the configured account signer, exchanges it for a session token, and stores the hydrated account/subaccount session state.\n */\n async login(options: LoginOptions): Promise<LoginResult> {\n return this.#login(options);\n }\n\n async #login(\n options: LoginOptions,\n previousActiveAccount?: ActiveAccountInfo,\n ): Promise<LoginResult> {\n const { provider, loginMethod } = options;\n\n const accountSigner = await this.#resolveAccountSigner();\n\n if (!accountSigner) {\n throw new ConfigurationError(\n \"No account signer configured. Call setAccountSigner() or pass accountSigner in config.\",\n );\n }\n\n const smartAccountAddress = accountSigner.accountAddress;\n const ownerAddress = accountSigner.ownerAddress ?? accountSigner.accountAddress;\n\n const { nonce } = await this.requestLoginNonce(smartAccountAddress);\n\n const message = `Polyester Login\\n\\nNonce: ${nonce}`;\n const signature = await accountSigner.signMessage(message);\n\n const response = await this.loginWithWallet({\n smartAccountAddress,\n nonce,\n signature,\n primaryWalletAddress: ownerAddress,\n walletProvider: provider,\n });\n\n const environmentSession = this.#getEnvironmentSession();\n const resolvedLoginMethod =\n loginMethod ??\n this.#loginMethod ??\n environmentSession?.loginMethod ??\n (provider === \"metamask\" ? \"metamask\" : null);\n\n const tokenOptions = createAuthTokenStorageSetOptions(response.accessToken);\n const activeAccount =\n previousActiveAccount?.mainAccountId === response.accountId\n ? previousActiveAccount\n : undefined;\n this.#sessionStore.commitLogin(\n {\n accessToken: response.accessToken,\n tokenOptions,\n provider,\n loginMethod: resolvedLoginMethod,\n primaryWallet: ownerAddress,\n smartAccount: smartAccountAddress,\n accountId: response.accountId,\n activeAccount,\n username: response.username ?? undefined,\n },\n this.#tokenStorage,\n );\n this.#isAuthenticated = true;\n this.#mainAccountId = response.accountId;\n this.#activeAccountId = activeAccount?.accountId ?? response.accountId;\n this.#walletProvider = provider;\n this.#loginMethod = resolvedLoginMethod;\n this.#accountIdentity = this.#identityFromSigner(accountSigner);\n\n this.#notifyStateChange();\n\n this.events.emit(\"authenticated\", {\n accountId: response.accountId,\n username: response.username,\n });\n\n const expiresAt = response.expiresAt\n ? new Date(\n Number(response.expiresAt.seconds) * 1000 +\n (response.expiresAt.nanos ?? 0) / 1_000_000,\n )\n : new Date();\n\n return {\n accountId: response.accountId,\n username: response.username,\n expiresAt,\n };\n }\n\n /**\n * Builds auth state from a session token and optional active account override.\n */\n hydrateAuthState(state: AuthHydrationData): void {\n const existingToken = this.#getEnvironmentBoundToken();\n if (!existingToken || !isJwtValid(existingToken)) return;\n\n const existingSession = this.#getEnvironmentSession();\n this.#walletProvider = existingSession?.provider ?? this.#walletProvider;\n this.#loginMethod = existingSession?.loginMethod ?? this.#loginMethod;\n\n this.#isAuthenticated = true;\n this.#mainAccountId = state.mainAccountId;\n this.#activeAccountId = state.activeAccountId ?? state.mainAccountId;\n this.#accountIdentity = state.smartAccountAddress\n ? {\n accountAddress: state.smartAccountAddress,\n ownerAddress: state.ownerAddress,\n }\n : null;\n\n this.#notifyStateChange();\n }\n\n /**\n * Loads the stored token, validates that it still belongs to this environment, and restores auth state when possible.\n */\n async restoreSession(): Promise<{ accountId: string; username: string } | null> {\n const existingToken = this.#getEnvironmentBoundToken();\n\n if (!existingToken || !isJwtValid(existingToken)) {\n this.#clearExpiredSessionState();\n return null;\n }\n\n try {\n const me = await this.me();\n this.#isAuthenticated = true;\n this.#mainAccountId = me.accountId;\n\n // preserve active account if already set (e.g. via hydration), otherwise use main\n const existingSession = this.#getEnvironmentSession();\n this.#walletProvider = existingSession?.provider ?? this.#walletProvider;\n this.#loginMethod = existingSession?.loginMethod ?? this.#loginMethod;\n if (!this.#activeAccountId) {\n this.#activeAccountId = existingSession?.activeAccount?.accountId ?? me.accountId;\n }\n\n // use existing account signer if set, otherwise try to resolve from config\n if (!this.#accountSigner) {\n this.#accountSigner = await resolveAccountSigner(this.#accountSignerConfig);\n if (this.#accountSigner) {\n this.#assertAccountSignerEnvironment(this.#accountSigner);\n this.#accountIdentity = this.#identityFromSigner(this.#accountSigner);\n }\n }\n\n // keep the display session available for SSR hydration\n if (this.#accountSigner?.accountAddress) {\n const session = this.#sessionStore.ensureSession(\n {\n provider: this.#walletProvider ? this.#walletProvider : \"other\",\n loginMethod:\n this.#loginMethod ??\n (this.#walletProvider === \"metamask\" ? \"metamask\" : null),\n primaryWallet:\n this.#accountSigner.ownerAddress ?? this.#accountSigner.accountAddress,\n smartAccount: this.#accountSigner.accountAddress,\n accountId: me.accountId,\n username: me.username ?? undefined,\n },\n { maxAgeSeconds: this.#getCurrentTokenStorageOptions().maxAgeSeconds },\n );\n this.#walletProvider = session.provider;\n this.#loginMethod = session.loginMethod ?? this.#loginMethod;\n }\n\n this.#notifyStateChange();\n return { accountId: me.accountId, username: me.username };\n } catch {\n this.#clearExpiredSessionState();\n return null;\n }\n }\n\n /**\n * Clears stored auth state and removes the persisted auth token.\n */\n async logout(): Promise<void> {\n this.#realtime.disconnectPrivate();\n this.#tokenStorage.clear();\n this.#isAuthenticated = false;\n this.#mainAccountId = null;\n this.#activeAccountId = null;\n this.#loginMethod = null;\n this.#accountIdentity = null;\n\n this.#sessionStore.clear();\n\n this.#notifyStateChange();\n this.events.emit(\"loggedOut\", undefined);\n }\n\n #clearExpiredSessionState(): void {\n const shouldEmitLoggedOut = this.#isAuthenticated;\n this.#realtime.disconnectPrivate();\n this.#tokenStorage.clear();\n this.#sessionStore.clear();\n this.#isAuthenticated = false;\n this.#mainAccountId = null;\n this.#activeAccountId = null;\n this.#loginMethod = null;\n this.#accountIdentity = null;\n this.#notifyStateChange();\n if (shouldEmitLoggedOut) {\n this.events.emit(\"loggedOut\", undefined);\n }\n }\n\n /**\n * Returns the remaining lifetime of the stored session token in milliseconds.\n */\n getSessionTimeToExpiry(): number {\n const token = this.#getEnvironmentBoundToken();\n if (!token) return 0;\n return getJwtTimeToExpiry(token);\n }\n\n /**\n * Refreshes the active account-signer session and updates persisted auth state.\n */\n async refreshSession(params?: {\n provider?: \"metamask\" | \"turnkey\" | \"other\";\n loginMethod?: AuthLoginMethod | null;\n }): Promise<LoginResult> {\n if (!this.#isAuthenticated) {\n throw new AuthenticationError(\"Must be authenticated to refresh session\");\n }\n\n const currentSession = this.#getEnvironmentSession();\n return this.#login(\n {\n provider: this.#resolveRefreshProvider(params?.provider),\n loginMethod: params?.loginMethod ?? this.#loginMethod,\n },\n currentSession?.activeAccount,\n );\n }\n\n /**\n * Switches the active account/subaccount by signing the required account switch flow.\n */\n switchAccount(\n accountId: string,\n options?: { smartAccountAddress?: string; label?: string },\n ): { accountId: string; isMain: boolean } {\n if (!this.#isAuthenticated || !this.#mainAccountId) {\n throw new AuthenticationError(\"Must be authenticated to switch accounts\");\n }\n\n this.#activeAccountId = accountId;\n const isMain = accountId === this.#mainAccountId;\n\n this.#sessionStore.setActiveAccount(\n {\n accountId,\n isMain,\n smartAccountAddress: options?.smartAccountAddress,\n label: options?.label,\n },\n { maxAgeSeconds: this.#getCurrentTokenStorageOptions().maxAgeSeconds },\n );\n this.#notifyStateChange();\n\n return { accountId, isMain };\n }\n\n /** Keeps the display-session identity current for the next server render. */\n syncSessionUsername(username: string | null): void {\n this.#sessionStore.setUsername(username, {\n maxAgeSeconds: this.#getCurrentTokenStorageOptions().maxAgeSeconds,\n });\n }\n\n /**\n * Creates a subaccount for the authenticated account and makes it available to the session state.\n */\n async createSubaccount(params: CreateSubaccountParams): Promise<CreateSubaccountResult> {\n if (!this.#isAuthenticated) {\n throw new AuthenticationError(\"Must be authenticated to create subaccounts\");\n }\n\n if (!this.#subaccounts) {\n throw new ConfigurationError(\n \"SubaccountsService not configured. Pass it to constructor or call setSubaccountsService().\",\n );\n }\n\n const { accountSigner, label = \"\", walletProvider = \"wallet\" } = params;\n this.#assertAccountSignerEnvironment(accountSigner);\n\n // request nonce for the subaccount's smart account address\n const { nonce } = await this.requestLoginNonce(accountSigner.accountAddress);\n\n // sign canonical login message with the subaccount account signer\n const message = `Polyester Login\\n\\nNonce: ${nonce}`;\n const signature = await accountSigner.signMessage(message);\n\n // use main account signer's owner address for primary wallet reference\n const primaryWalletAddress =\n this.#accountSigner?.ownerAddress ??\n accountSigner.ownerAddress ??\n this.#accountSigner?.accountAddress ??\n \"\";\n\n const response = await this.#subaccounts.create({\n label,\n smartAccountAddress: accountSigner.accountAddress,\n nonce,\n signature,\n primaryWalletAddress,\n walletProvider,\n });\n\n return {\n subaccountId: response.subaccountId,\n smartAccountSaltNonce: response.smartAccountSaltNonce,\n revision: response.revision,\n };\n }\n\n /**\n * Returns the current account-signer auth state snapshot.\n */\n getState(): AuthState {\n const accountIdentity = this.#accountSigner ?? this.#accountIdentity;\n\n return {\n isAuthenticated: this.#isAuthenticated,\n accountAddress: accountIdentity?.accountAddress ?? null,\n ownerAddress: accountIdentity?.ownerAddress ?? null,\n mainAccountId: this.#mainAccountId,\n activeAccount:\n this.#activeAccountId && this.#mainAccountId\n ? {\n accountId: this.#activeAccountId,\n isMain: this.#activeAccountId === this.#mainAccountId,\n mainAccountId: this.#mainAccountId,\n smartAccountAddress: accountIdentity?.accountAddress,\n }\n : null,\n };\n }\n\n async #resolveAccountSigner(): Promise<AccountSigner | null> {\n if (this.#accountSigner) {\n this.#assertAccountSignerEnvironment(this.#accountSigner);\n return this.#accountSigner;\n }\n\n const resolved = await resolveAccountSigner(this.#accountSignerConfig);\n if (resolved) {\n this.#assertAccountSignerEnvironment(resolved);\n this.#accountSigner = resolved;\n this.#accountIdentity = this.#identityFromSigner(resolved);\n }\n return this.#accountSigner;\n }\n\n #notifyStateChange(): void {\n this.events.emit(\"stateChange\", this.getState());\n }\n\n #getEnvironmentBoundToken(): string | null {\n return this.#sessionStore.getEnvironmentBoundToken(this.#tokenStorage);\n }\n\n #getCurrentTokenStorageOptions(): AuthTokenStorageSetOptions {\n const token = this.#tokenStorage.get();\n if (!token) return { expiresAt: null, maxAgeSeconds: null };\n return createAuthTokenStorageSetOptions(token);\n }\n\n #resolveRefreshProvider(\n provider?: \"metamask\" | \"turnkey\" | \"other\",\n ): \"metamask\" | \"turnkey\" | \"other\" {\n return (\n provider ?? this.#walletProvider ?? this.#getEnvironmentSession()?.provider ?? \"other\"\n );\n }\n\n #assertAccountSignerEnvironment(accountSigner: AccountSigner): void {\n assertAccountSigner(accountSigner);\n if (accountSigner.environmentFingerprint !== this.#environmentFingerprint) {\n throw new ConfigurationError(\n \"Account signer environment does not match client environment.\",\n );\n }\n }\n\n #identityFromSigner(accountSigner: AccountSigner): AccountIdentity {\n return {\n accountAddress: accountSigner.accountAddress,\n ownerAddress: accountSigner.ownerAddress,\n };\n }\n\n #getEnvironmentSession(): SessionData | null {\n return this.#sessionStore.get();\n }\n}\n"],"mappings":";;;;;;;;;;;AAoEA,IAAa,2BAAb,cAA8C,YAAY;CACtD,SAAkB,IAAI,aAAsC;CAE5D;CACA,iBAAuC;CACvC,mBAA2C;CAC3C,mBAAmB;CACnB,iBAAgC;CAChC,mBAAkC;CAClC;CACA,kBAAgE,KAAA;CAChE,eAAuC;CACvC;CACA;CACA;CACA;CAEA,YAAY,EACR,YACA,qBACA,aACA,aACA,UACA,cACA,gBASD;EACC,MAAM,YAAY,QAAQ;EAE1B,KAAKA,uBAAuB;EAC5B,KAAKC,0BAA0B,YAAY;EAC3C,KAAKC,eAAe;EACpB,KAAKC,gBAAgB;EACrB,KAAKC,YAAY;EACjB,KAAKC,gBACD,gBACA,IAAI,iBAAiB,EACjB,wBAAwB,YAAY,YACxC,CAAC;CACT;;;;CAKA,sBAAsB,aAAuC;EACzD,KAAKH,eAAe;CACxB;;;;CAKA,iBAAiB,eAA2C;EACxD,IAAI,eAAe,KAAKI,gCAAgC,aAAa;EACrE,KAAKC,iBAAiB;EACtB,KAAKC,mBAAmB,gBAA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E,YAAY;CAEvF;CAEA,gCAAgC,eAAoC;EAChE,oBAAoB,aAAa;EACjC,IAAI,cAAc,2BAA2B,KAAKZ,yBAC9C,MAAM,IAAI,mBACN,+DACJ;CAER;CAEA,oBAAoB,eAA+C;EAC/D,OAAO;GACH,gBAAgB,cAAc;GAC9B,cAAc,cAAc;EAChC;CACJ;CAEA,yBAA6C;EACzC,OAAO,KAAKI,cAAc,IAAI;CAClC;AACJ"}
1
+ {"version":3,"file":"account-signer-auth.js","names":["#accountSignerConfig","#environmentFingerprint","#subaccounts","#tokenStorage","#realtime","#sessionStore","#assertAccountSignerEnvironment","#accountSigner","#accountIdentity","#identityFromSigner","#notifyStateChange","#login","#resolveAccountSigner","#getEnvironmentSession","#loginMethod","#isAuthenticated","#mainAccountId","#activeAccountId","#walletProvider","#getEnvironmentBoundToken","#clearExpiredSessionState","#getCurrentTokenStorageOptions","#resolveRefreshProvider"],"sources":["../../../src/services/auth/account-signer-auth.ts"],"sourcesContent":["import { AuthService } from \"./auth.js\";\nimport { AuthenticationError, ConfigurationError } from \"../../shared/errors.js\";\nimport { AuthSessionStore } from \"./session.js\";\nimport type { AccountSigner, AccountSignerConfig, HexAddress } from \"../../account-signer/types.js\";\nimport { assertAccountSigner, resolveAccountSigner } from \"../../account-signer/types.js\";\nimport { EventEmitter } from \"../../utils/event-emitter.js\";\nimport { isJwtValid, getJwtTimeToExpiry } from \"../../utils/jwt.js\";\nimport type { SubaccountsService } from \"../subaccounts/index.js\";\nimport type {\n AuthState,\n AuthHydrationData,\n AuthLoginMethod,\n SessionData,\n ActiveAccountInfo,\n} from \"./session.types.js\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport type { PolyesterEnvironment } from \"../../environment.js\";\nimport type { AuthAndPublicApiTransports } from \"../../shared/transports.js\";\nimport {\n createAuthTokenStorageSetOptions,\n type AuthTokenStorage,\n type AuthTokenStorageSetOptions,\n} from \"./token-storage.js\";\n\nexport interface AccountSignerAuthEvents {\n authenticated: { accountId: string; username: string };\n loggedOut: void;\n error: { code: string; message: string };\n servicesReady: void;\n stateChange: AuthState;\n}\n\nexport interface LoginResult {\n accountId: string;\n username: string;\n expiresAt: Date;\n}\n\nexport interface LoginOptions {\n /**\n * The wallet provider to use for login.\n */\n provider: \"metamask\" | \"turnkey\" | \"other\";\n loginMethod?: AuthLoginMethod | null;\n}\n\nexport interface CreateSubaccountParams {\n /** The account signer for the new subaccount (caller derives this, e.g. via Turnkey saltNonce) */\n accountSigner: AccountSigner;\n /** Optional human-readable label for this subaccount */\n label?: string;\n /** Wallet provider hint (e.g. \"turnkey\", \"metamask\"). Defaults to \"wallet\" */\n walletProvider?: string;\n}\n\nexport interface CreateSubaccountResult {\n subaccountId: string;\n smartAccountSaltNonce: number;\n revision: string;\n}\n\ninterface AccountIdentity {\n accountAddress: HexAddress;\n ownerAddress?: HexAddress;\n}\n\n/**\n * Coordinates wallet/account-signer authentication, session storage, subaccount selection, and session refresh.\n */\nexport class AccountSignerAuthService extends AuthService {\n readonly events = new EventEmitter<AccountSignerAuthEvents>();\n\n #accountSignerConfig: AccountSignerConfig | undefined;\n #accountSigner: AccountSigner | null = null;\n #accountIdentity: AccountIdentity | null = null;\n #isAuthenticated = false;\n #mainAccountId: string | null = null;\n #activeAccountId: string | null = null;\n #subaccounts: SubaccountsService;\n #walletProvider: \"metamask\" | \"turnkey\" | \"other\" | undefined = undefined;\n #loginMethod: AuthLoginMethod | null = null;\n #environmentFingerprint: string;\n #tokenStorage: AuthTokenStorage;\n #sessionStore: AuthSessionStore;\n #realtime: PolyesterRealtime;\n\n constructor({\n transports,\n accountSignerConfig,\n environment,\n subaccounts,\n realtime,\n tokenStorage,\n sessionStore,\n }: {\n transports: AuthAndPublicApiTransports;\n accountSignerConfig?: AccountSignerConfig;\n environment: PolyesterEnvironment;\n subaccounts: SubaccountsService;\n realtime: PolyesterRealtime;\n tokenStorage: AuthTokenStorage;\n sessionStore?: AuthSessionStore;\n }) {\n super(transports, realtime);\n\n this.#accountSignerConfig = accountSignerConfig;\n this.#environmentFingerprint = environment.fingerprint;\n this.#subaccounts = subaccounts;\n this.#tokenStorage = tokenStorage;\n this.#realtime = realtime;\n this.#sessionStore =\n sessionStore ??\n new AuthSessionStore({\n environmentFingerprint: environment.fingerprint,\n });\n }\n\n /**\n * Attaches the subaccounts service used when creating a subaccount during authenticated flows.\n */\n setSubaccountsService(subaccounts: SubaccountsService): void {\n this.#subaccounts = subaccounts;\n }\n\n /**\n * Sets the account signer used to sign login and account-switch challenges.\n */\n setAccountSigner(accountSigner: AccountSigner | null): void {\n if (accountSigner) this.#assertAccountSignerEnvironment(accountSigner);\n this.#accountSigner = accountSigner;\n this.#accountIdentity = accountSigner ? this.#identityFromSigner(accountSigner) : null;\n this.#notifyStateChange();\n }\n\n /**\n * Returns the active account signer, throwing if one has not been configured.\n */\n getAccountSigner(): AccountSigner | null {\n return this.#accountSigner;\n }\n\n /**\n * Signs a short-lived login nonce with the configured account signer, exchanges it for a session token, and stores the hydrated account/subaccount session state.\n */\n async login(options: LoginOptions): Promise<LoginResult> {\n return this.#login(options);\n }\n\n async #login(\n options: LoginOptions,\n previousActiveAccount?: ActiveAccountInfo,\n ): Promise<LoginResult> {\n const { provider, loginMethod } = options;\n\n const accountSigner = await this.#resolveAccountSigner();\n\n if (!accountSigner) {\n throw new ConfigurationError(\n \"No account signer configured. Call setAccountSigner() or pass accountSigner in config.\",\n );\n }\n\n const smartAccountAddress = accountSigner.accountAddress;\n const ownerAddress = accountSigner.ownerAddress ?? accountSigner.accountAddress;\n\n const { nonce } = await this.requestLoginNonce(smartAccountAddress);\n\n const message = `Polyester Login\\n\\nNonce: ${nonce}`;\n const signature = await accountSigner.signMessage(message);\n\n const response = await this.loginWithWallet({\n smartAccountAddress,\n nonce,\n signature,\n primaryWalletAddress: ownerAddress,\n walletProvider: provider,\n });\n\n const environmentSession = this.#getEnvironmentSession();\n const resolvedLoginMethod =\n loginMethod ??\n this.#loginMethod ??\n environmentSession?.loginMethod ??\n (provider === \"metamask\" ? \"metamask\" : null);\n\n const tokenOptions = createAuthTokenStorageSetOptions(response.accessToken);\n const activeAccount =\n previousActiveAccount?.mainAccountId === response.accountId\n ? previousActiveAccount\n : undefined;\n this.#sessionStore.commitLogin(\n {\n accessToken: response.accessToken,\n tokenOptions,\n provider,\n loginMethod: resolvedLoginMethod,\n primaryWallet: ownerAddress,\n smartAccount: smartAccountAddress,\n accountId: response.accountId,\n activeAccount,\n username: response.username ?? undefined,\n },\n this.#tokenStorage,\n );\n this.#isAuthenticated = true;\n this.#mainAccountId = response.accountId;\n this.#activeAccountId = activeAccount?.accountId ?? response.accountId;\n this.#walletProvider = provider;\n this.#loginMethod = resolvedLoginMethod;\n this.#accountIdentity = this.#identityFromSigner(accountSigner);\n\n this.#notifyStateChange();\n\n this.events.emit(\"authenticated\", {\n accountId: response.accountId,\n username: response.username,\n });\n\n const expiresAt = response.expiresAt\n ? new Date(\n Number(response.expiresAt.seconds) * 1000 +\n (response.expiresAt.nanos ?? 0) / 1_000_000,\n )\n : new Date();\n\n return {\n accountId: response.accountId,\n username: response.username,\n expiresAt,\n };\n }\n\n /**\n * Builds auth state from a session token and optional active account override.\n */\n hydrateAuthState(state: AuthHydrationData): void {\n const existingToken = this.#getEnvironmentBoundToken();\n if (!existingToken || !isJwtValid(existingToken)) return;\n\n const existingSession = this.#getEnvironmentSession();\n this.#walletProvider = existingSession?.provider ?? this.#walletProvider;\n this.#loginMethod = existingSession?.loginMethod ?? this.#loginMethod;\n\n this.#isAuthenticated = true;\n this.#mainAccountId = state.mainAccountId;\n this.#activeAccountId = state.activeAccountId ?? state.mainAccountId;\n this.#accountIdentity = state.smartAccountAddress\n ? {\n accountAddress: state.smartAccountAddress,\n ownerAddress: state.ownerAddress,\n }\n : null;\n\n this.#notifyStateChange();\n }\n\n /**\n * Loads the stored token, validates that it still belongs to this environment, and restores auth state when possible.\n */\n async restoreSession(): Promise<{ accountId: string; username: string } | null> {\n const existingToken = this.#getEnvironmentBoundToken();\n\n if (!existingToken || !isJwtValid(existingToken)) {\n this.#clearExpiredSessionState();\n return null;\n }\n\n try {\n const me = await this.me();\n this.#isAuthenticated = true;\n this.#mainAccountId = me.accountId;\n\n // preserve active account if already set (e.g. via hydration), otherwise use main\n const existingSession = this.#getEnvironmentSession();\n this.#walletProvider = existingSession?.provider ?? this.#walletProvider;\n this.#loginMethod = existingSession?.loginMethod ?? this.#loginMethod;\n if (!this.#activeAccountId) {\n this.#activeAccountId = existingSession?.activeAccount?.accountId ?? me.accountId;\n }\n\n // use existing account signer if set, otherwise try to resolve from config\n if (!this.#accountSigner) {\n this.#accountSigner = await resolveAccountSigner(this.#accountSignerConfig);\n if (this.#accountSigner) {\n this.#assertAccountSignerEnvironment(this.#accountSigner);\n this.#accountIdentity = this.#identityFromSigner(this.#accountSigner);\n }\n }\n\n // keep the display session available for SSR hydration\n if (this.#accountSigner?.accountAddress) {\n const session = this.#sessionStore.ensureSession(\n {\n provider: this.#walletProvider ? this.#walletProvider : \"other\",\n loginMethod:\n this.#loginMethod ??\n (this.#walletProvider === \"metamask\" ? \"metamask\" : null),\n primaryWallet:\n this.#accountSigner.ownerAddress ?? this.#accountSigner.accountAddress,\n smartAccount: this.#accountSigner.accountAddress,\n accountId: me.accountId,\n username: me.username ?? undefined,\n },\n { maxAgeSeconds: this.#getCurrentTokenStorageOptions().maxAgeSeconds },\n );\n this.#walletProvider = session.provider;\n this.#loginMethod = session.loginMethod ?? this.#loginMethod;\n }\n\n this.#notifyStateChange();\n return { accountId: me.accountId, username: me.username };\n } catch {\n this.#clearExpiredSessionState();\n return null;\n }\n }\n\n /**\n * Clears stored auth state and removes the persisted auth token.\n */\n async logout(): Promise<void> {\n this.#realtime.disconnectPrivate();\n this.#tokenStorage.clear();\n this.#isAuthenticated = false;\n this.#mainAccountId = null;\n this.#activeAccountId = null;\n this.#loginMethod = null;\n this.#accountIdentity = null;\n\n this.#sessionStore.clear();\n\n this.#notifyStateChange();\n this.events.emit(\"loggedOut\", undefined);\n }\n\n #clearExpiredSessionState(): void {\n const shouldEmitLoggedOut = this.#isAuthenticated;\n this.#realtime.disconnectPrivate();\n this.#tokenStorage.clear();\n this.#sessionStore.clear();\n this.#isAuthenticated = false;\n this.#mainAccountId = null;\n this.#activeAccountId = null;\n this.#loginMethod = null;\n this.#accountIdentity = null;\n this.#notifyStateChange();\n if (shouldEmitLoggedOut) {\n this.events.emit(\"loggedOut\", undefined);\n }\n }\n\n /**\n * Returns the remaining lifetime of the stored session token in milliseconds.\n */\n getSessionTimeToExpiry(): number {\n const token = this.#getEnvironmentBoundToken();\n if (!token) return 0;\n return getJwtTimeToExpiry(token);\n }\n\n /**\n * Refreshes the active account-signer session and updates persisted auth state.\n */\n async refreshSession(params?: {\n provider?: \"metamask\" | \"turnkey\" | \"other\";\n loginMethod?: AuthLoginMethod | null;\n }): Promise<LoginResult> {\n if (!this.#isAuthenticated) {\n throw new AuthenticationError(\"Must be authenticated to refresh session\");\n }\n\n const currentSession = this.#getEnvironmentSession();\n return this.#login(\n {\n provider: this.#resolveRefreshProvider(params?.provider),\n loginMethod: params?.loginMethod ?? this.#loginMethod,\n },\n currentSession?.activeAccount,\n );\n }\n\n /**\n * Switches the active account/subaccount by signing the required account switch flow.\n */\n switchAccount(\n accountId: string,\n options?: { smartAccountAddress?: string; label?: string },\n ): { accountId: string; isMain: boolean } {\n if (!this.#isAuthenticated || !this.#mainAccountId) {\n throw new AuthenticationError(\"Must be authenticated to switch accounts\");\n }\n\n this.#activeAccountId = accountId;\n const isMain = accountId === this.#mainAccountId;\n\n this.#sessionStore.setActiveAccount(\n {\n accountId,\n isMain,\n smartAccountAddress: options?.smartAccountAddress,\n label: options?.label,\n },\n { maxAgeSeconds: this.#getCurrentTokenStorageOptions().maxAgeSeconds },\n );\n this.#notifyStateChange();\n\n return { accountId, isMain };\n }\n\n /** Keeps the display-session identity current for the next server render. */\n syncSessionUsername(username: string | null): void {\n this.#sessionStore.setUsername(username, {\n maxAgeSeconds: this.#getCurrentTokenStorageOptions().maxAgeSeconds,\n });\n }\n\n /**\n * Creates a subaccount for the authenticated account and makes it available to the session state.\n */\n async createSubaccount(params: CreateSubaccountParams): Promise<CreateSubaccountResult> {\n if (!this.#isAuthenticated) {\n throw new AuthenticationError(\"Must be authenticated to create subaccounts\");\n }\n\n if (!this.#subaccounts) {\n throw new ConfigurationError(\n \"SubaccountsService not configured. Pass it to constructor or call setSubaccountsService().\",\n );\n }\n\n const { accountSigner, label = \"\", walletProvider = \"wallet\" } = params;\n this.#assertAccountSignerEnvironment(accountSigner);\n\n // request nonce for the subaccount's smart account address\n const { nonce } = await this.requestLoginNonce(accountSigner.accountAddress);\n\n // sign canonical login message with the subaccount account signer\n const message = `Polyester Login\\n\\nNonce: ${nonce}`;\n const signature = await accountSigner.signMessage(message);\n\n // use main account signer's owner address for primary wallet reference\n const primaryWalletAddress =\n this.#accountSigner?.ownerAddress ??\n accountSigner.ownerAddress ??\n this.#accountSigner?.accountAddress ??\n \"\";\n\n const response = await this.#subaccounts.create({\n label,\n smartAccountAddress: accountSigner.accountAddress,\n nonce,\n signature,\n primaryWalletAddress,\n walletProvider,\n });\n\n return {\n subaccountId: response.subaccountId,\n smartAccountSaltNonce: response.smartAccountSaltNonce,\n revision: response.revision,\n };\n }\n\n /**\n * Returns the current account-signer auth state snapshot.\n */\n getState(): AuthState {\n const accountIdentity = this.#accountSigner ?? this.#accountIdentity;\n\n return {\n isAuthenticated: this.#isAuthenticated,\n accountAddress: accountIdentity?.accountAddress ?? null,\n ownerAddress: accountIdentity?.ownerAddress ?? null,\n mainAccountId: this.#mainAccountId,\n activeAccount:\n this.#activeAccountId && this.#mainAccountId\n ? {\n accountId: this.#activeAccountId,\n isMain: this.#activeAccountId === this.#mainAccountId,\n mainAccountId: this.#mainAccountId,\n smartAccountAddress: accountIdentity?.accountAddress,\n }\n : null,\n };\n }\n\n async #resolveAccountSigner(): Promise<AccountSigner | null> {\n if (this.#accountSigner) {\n this.#assertAccountSignerEnvironment(this.#accountSigner);\n return this.#accountSigner;\n }\n\n const resolved = await resolveAccountSigner(this.#accountSignerConfig);\n if (resolved) {\n this.#assertAccountSignerEnvironment(resolved);\n this.#accountSigner = resolved;\n this.#accountIdentity = this.#identityFromSigner(resolved);\n }\n return this.#accountSigner;\n }\n\n #notifyStateChange(): void {\n this.events.emit(\"stateChange\", this.getState());\n }\n\n #getEnvironmentBoundToken(): string | null {\n return this.#sessionStore.getEnvironmentBoundToken(this.#tokenStorage);\n }\n\n #getCurrentTokenStorageOptions(): AuthTokenStorageSetOptions {\n const token = this.#tokenStorage.get();\n if (!token) return { expiresAt: null, maxAgeSeconds: null };\n return createAuthTokenStorageSetOptions(token);\n }\n\n #resolveRefreshProvider(\n provider?: \"metamask\" | \"turnkey\" | \"other\",\n ): \"metamask\" | \"turnkey\" | \"other\" {\n return (\n provider ?? this.#walletProvider ?? this.#getEnvironmentSession()?.provider ?? \"other\"\n );\n }\n\n #assertAccountSignerEnvironment(accountSigner: AccountSigner): void {\n assertAccountSigner(accountSigner);\n if (accountSigner.environmentFingerprint !== this.#environmentFingerprint) {\n throw new ConfigurationError(\n \"Account signer environment does not match client environment.\",\n );\n }\n }\n\n #identityFromSigner(accountSigner: AccountSigner): AccountIdentity {\n return {\n accountAddress: accountSigner.accountAddress,\n ownerAddress: accountSigner.ownerAddress,\n };\n }\n\n #getEnvironmentSession(): SessionData | null {\n return this.#sessionStore.get();\n }\n}\n"],"mappings":";;;;;;;;;;;AAqEA,IAAa,2BAAb,cAA8C,YAAY;CACtD,SAAkB,IAAI,aAAsC;CAE5D;CACA,iBAAuC;CACvC,mBAA2C;CAC3C,mBAAmB;CACnB,iBAAgC;CAChC,mBAAkC;CAClC;CACA,kBAAgE,KAAA;CAChE,eAAuC;CACvC;CACA;CACA;CACA;CAEA,YAAY,EACR,YACA,qBACA,aACA,aACA,UACA,cACA,gBASD;EACC,MAAM,YAAY,QAAQ;EAE1B,KAAKA,uBAAuB;EAC5B,KAAKC,0BAA0B,YAAY;EA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AC;CACnD;CAEA,4BAA2C;EACvC,OAAO,KAAKF,cAAc,yBAAyB,KAAKF,aAAa;CACzE;CAEA,iCAA6D;EACzD,MAAM,QAAQ,KAAKA,cAAc,IAAI;EACrC,IAAI,CAAC,OAAO,OAAO;GAAE,WAAW;GAAM,eAAe;EAAK;EAC1D,OAAO,iCAAiC,KAAK;CACjD;CAEA,wBACI,UACgC;EAChC,OACI,YAAY,KAAKe,mBAAmB,KAAKL,uBAAuB,CAAC,EAAE,YAAY;CAEvF;CAEA,gCAAgC,eAAoC;EAChE,oBAAoB,aAAa;EACjC,IAAI,cAAc,2BAA2B,KAAKZ,yBAC9C,MAAM,IAAI,mBACN,+DACJ;CAER;CAEA,oBAAoB,eAA+C;EAC/D,OAAO;GACH,gBAAgB,cAAc;GAC9B,cAAc,cAAc;EAChC;CACJ;CAEA,yBAA6C;EACzC,OAAO,KAAKI,cAAc,IAAI;CAClC;AACJ"}
@@ -1,9 +1,9 @@
1
1
  import { SessionLevel } from "../../gen/auth/v1/mfa_pb.js";
2
+ import { AuthAndPublicApiTransports } from "../../shared/transports.js";
2
3
  import { PolyesterMutationOptions, PolyesterRequestOptions } from "../../shared/request-options.js";
3
4
  import { PolyesterRealtime } from "../../realtime/types.js";
4
5
  import "../../realtime/index.js";
5
6
  import { ProfileService } from "./profile/profile.js";
6
- import { Transport } from "@connectrpc/connect";
7
7
  import * as v from "valibot";
8
8
  //#region src/services/auth/auth.d.ts
9
9
  declare const LoginWithWalletInputSchema: v.StrictObjectSchema<{
@@ -16,10 +16,6 @@ declare const LoginWithWalletInputSchema: v.StrictObjectSchema<{
16
16
  readonly walletProvider: v.OptionalSchema<v.StringSchema<undefined>, "">;
17
17
  }, undefined>;
18
18
  type LoginWithWalletInput = v.InferInput<typeof LoginWithWalletInputSchema>;
19
- interface AuthServiceTransports {
20
- publicApi: Transport;
21
- authApi: Transport;
22
- }
23
19
  declare const MeSchema: v.ObjectSchema<{
24
20
  readonly accountId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
25
21
  readonly apiKeyId: v.SchemaWithPipe<readonly [v.OptionalSchema<v.BigintSchema<undefined>, undefined>, v.TransformAction<bigint | undefined, string | undefined>]>;
@@ -75,7 +71,7 @@ type Nonce = v.InferOutput<typeof NonceSchema>;
75
71
  declare class AuthService {
76
72
  #private;
77
73
  profile: ProfileService;
78
- constructor(transports: AuthServiceTransports, realtime: PolyesterRealtime);
74
+ constructor(transports: AuthAndPublicApiTransports, realtime: PolyesterRealtime);
79
75
  /**
80
76
  * Returns the authenticated caller's account context, including account ID, optional API key ID, username, and session assurance details from the presented token or API key.
81
77
  */
@@ -93,5 +89,5 @@ declare class AuthService {
93
89
  protected loginWithWallet(input: LoginWithWalletInput, options?: PolyesterMutationOptions): Promise<LoginWithWalletResponse>;
94
90
  }
95
91
  //#endregion
96
- export { AuthService, AuthServiceTransports, LoginWithWalletInput, LoginWithWalletInputSchema, LoginWithWalletResponse, Me, Nonce };
92
+ export { AuthService, LoginWithWalletInput, LoginWithWalletInputSchema, LoginWithWalletResponse, Me, Nonce };
97
93
  //# sourceMappingURL=auth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","names":[],"sources":["../../../src/services/auth/auth.ts"],"mappings":";;;;;;;;cAmBa,4BAA0B,EAAA;;;;;;;;;KAU3B,uBAAuB,EAAE,kBAAkB;UAEtC;EACb,WAAW;EACX,SAAS;;cAGP,UAAQ,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;KAOF,KAAK,EAAE,mBAAmB;cAEhC,+BAA6B,EAAA;;;;;;;;;KAOvB,0BAA0B,EAAE,mBAAmB;cAErD,aAAW,EAAA;;;;;;;;;;KAKL,QAAQ,EAAE,mBAAmB;;;;cAK5B;;EAGT,SAAS;EAEG,YAAA,YAAY,uBAAuB,UAAU;;;;EASnD,GAAG,UAAU,0BAA0B,QAAQ;;;;;;;EAW/C,kBACF,6BACA,UAAU,0BACX,QAAQ;;;;YAaK,gBACZ,OAAO,sBACP,UAAU,2BACX,QAAQ"}
1
+ {"version":3,"file":"auth.d.ts","names":[],"sources":["../../../src/services/auth/auth.ts"],"mappings":";;;;;;;;cAoBa,4BAA0B,EAAA;;;;;;;;;KAU3B,uBAAuB,EAAE,kBAAkB;cAEjD,UAAQ,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;KAOF,KAAK,EAAE,mBAAmB;cAEhC,+BAA6B,EAAA;;;;;;;;;KAOvB,0BAA0B,EAAE,mBAAmB;cAErD,aAAW,EAAA;;;;;;;;;;KAKL,QAAQ,EAAE,mBAAmB;;;;cAK5B;;EAGT,SAAS;EAEG,YAAA,YAAY,4BAA4B,UAAU;;;;EASxD,GAAG,UAAU,0BAA0B,QAAQ;;;;;;;EAW/C,kBACF,6BACA,UAAU,0BACX,QAAQ;;;;YAaK,gBACZ,OAAO,sBACP,UAAU,2BACX,QAAQ"}
@@ -42,7 +42,7 @@ var AuthService = class {
42
42
  constructor(transports, realtime) {
43
43
  this.#publicClient = createClient(AuthService$1, transports.publicApi);
44
44
  this.#authClient = createClient(AuthService$1, transports.authApi);
45
- this.profile = new ProfileService(transports.authApi, realtime);
45
+ this.profile = new ProfileService(transports, realtime);
46
46
  }
47
47
  /**
48
48
  * Returns the authenticated caller's account context, including account ID, optional API key ID, username, and session assurance details from the presented token or API key.
@@ -1 +1 @@
1
- {"version":3,"file":"auth.js","names":["#publicClient","Proto.AuthService","#authClient"],"sources":["../../../src/services/auth/auth.ts"],"sourcesContent":["import { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport * as Proto from \"../../gen/auth/v1/auth_pb.js\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport { ProfileService } from \"./profile/profile.js\";\nimport {\n OptionalPublicIdSchema,\n OptionalTimestampMsSchema,\n PublicIdSchema,\n TimestampSchema,\n} from \"../../shared/schemas.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { MfaSessionInfoSchema } from \"../mfa/mfa.schemas.js\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\n\nexport const LoginWithWalletInputSchema = v.strictObject({\n smartAccountAddress: v.string(),\n nonce: v.string(),\n signature: v.string(),\n userAgent: v.optional(v.string(), \"\"),\n ip: v.optional(v.string(), \"\"),\n primaryWalletAddress: v.optional(v.string(), \"\"),\n walletProvider: v.optional(v.string(), \"\"),\n});\n\nexport type LoginWithWalletInput = v.InferInput<typeof LoginWithWalletInputSchema>;\n\nexport interface AuthServiceTransports {\n publicApi: Transport;\n authApi: Transport;\n}\n\nconst MeSchema = v.object({\n accountId: PublicIdSchema,\n apiKeyId: OptionalPublicIdSchema,\n username: v.string(),\n session: v.optional(MfaSessionInfoSchema),\n});\n\nexport type Me = v.InferOutput<typeof MeSchema>;\n\nconst LoginWithWalletResponseSchema = v.object({\n accessToken: v.string(),\n expiresAt: v.optional(TimestampSchema),\n accountId: PublicIdSchema,\n username: v.string(),\n});\n\nexport type LoginWithWalletResponse = v.InferOutput<typeof LoginWithWalletResponseSchema>;\n\nconst NonceSchema = v.object({\n nonce: v.string(),\n expiresAt: OptionalTimestampMsSchema,\n});\n\nexport type Nonce = v.InferOutput<typeof NonceSchema>;\n\n/**\n * Handles wallet-based authentication, caller introspection, and authenticated profile operations.\n */\nexport class AuthService {\n #publicClient: Client<typeof Proto.AuthService>;\n #authClient: Client<typeof Proto.AuthService>;\n profile: ProfileService;\n\n constructor(transports: AuthServiceTransports, realtime: PolyesterRealtime) {\n this.#publicClient = createClient(Proto.AuthService, transports.publicApi);\n this.#authClient = createClient(Proto.AuthService, transports.authApi);\n this.profile = new ProfileService(transports.authApi, realtime);\n }\n\n /**\n * Returns the authenticated caller's account context, including account ID, optional API key ID, username, and session assurance details from the presented token or API key.\n */\n async me(options?: PolyesterRequestOptions): Promise<Me> {\n const res = await this.#authClient.me({}, toConnectCallOptions(options));\n return parse(MeSchema, res);\n }\n\n /**\n * Requests a short-lived nonce for the given smart-account EVM address.\n * The nonce is single-purpose, replaced by subsequent requests, and expires\n * after about five minutes. The optional expiry is milliseconds since the\n * Unix epoch.\n */\n async requestLoginNonce(\n smartAccountAddress: string,\n options?: PolyesterRequestOptions,\n ): Promise<Nonce> {\n return parse(\n NonceSchema,\n await this.#publicClient.getNonce(\n { smartAccountAddress },\n toConnectCallOptions(options),\n ),\n );\n }\n\n /**\n * Exchanges a signed login nonce for an authenticated session token and account identity returned by the auth API.\n */\n protected async loginWithWallet(\n input: LoginWithWalletInput,\n options?: PolyesterMutationOptions,\n ): Promise<LoginWithWalletResponse> {\n const validatedInput = parse(LoginWithWalletInputSchema, input);\n const res = await this.#publicClient.loginWithWallet(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(LoginWithWalletResponseSchema, res);\n }\n}\n"],"mappings":";;;;;;;;;AAmBA,MAAa,6BAA6B,EAAE,aAAa;CACrD,qBAAqB,EAAE,OAAO;CAC9B,OAAO,EAAE,OAAO;CAChB,WAAW,EAAE,OAAO;CACpB,WAAW,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CACpC,IAAI,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CAC7B,sBAAsB,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CAC/C,gBAAgB,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;AAC7C,CAAC;AASD,MAAM,WAAW,EAAE,OAAO;CACtB,WAAW;CACX,UAAU;CACV,UAAU,EAAE,OAAO;CACnB,SAAS,EAAE,SAAS,oBAAoB;AAC5C,CAAC;AAID,MAAM,gCAAgC,EAAE,OAAO;CAC3C,aAAa,EAAE,OAAO;CACtB,WAAW,EAAE,SAAS,eAAe;CACrC,WAAW;CACX,UAAU,EAAE,OAAO;AACvB,CAAC;AAID,MAAM,cAAc,EAAE,OAAO;CACzB,OAAO,EAAE,OAAO;CAChB,WAAW;AACf,CAAC;;;;AAOD,IAAa,cAAb,MAAyB;CACrB;CACA;CACA;CAEA,YAAY,YAAmC,UAA6B;EACxE,KAAKA,gBAAgB,aAAaC,eAAmB,WAAW,SAAS;EACzE,KAAKC,cAAc,aAAaD,eAAmB,WAAW,OAAO;EACrE,KAAK,UAAU,IAAI,eAAe,WAAW,SAAS,QAAQ;CAClE;;;;CAKA,MAAM,GAAG,SAAgD;EACrD,MAAM,MAAM,MAAM,KAAKC,YAAY,GAAG,CAAC,GAAG,qBAAqB,OAAO,CAAC;EACvE,OAAO,MAAM,UAAU,GAAG;CAC9B;;;;;;;CAQA,MAAM,kBACF,qBACA,SACc;EACd,OAAO,MACH,aACA,MAAM,KAAKF,cAAc,SACrB,EAAE,oBAAoB,GACtB,qBAAqB,OAAO,CAChC,CACJ;CACJ;;;;CAKA,MAAgB,gBACZ,OACA,SACgC;EAChC,MAAM,iBAAiB,MAAM,4BAA4B,KAAK;EAC9D,MAAM,MAAM,MAAM,KAAKA,cAAc,gBACjC,gBACA,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,+BAA+B,GAAG;CACnD;AACJ"}
1
+ {"version":3,"file":"auth.js","names":["#publicClient","Proto.AuthService","#authClient"],"sources":["../../../src/services/auth/auth.ts"],"sourcesContent":["import { createClient, type Client } from \"@connectrpc/connect\";\nimport * as Proto from \"../../gen/auth/v1/auth_pb.js\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport { ProfileService } from \"./profile/profile.js\";\nimport {\n OptionalPublicIdSchema,\n OptionalTimestampMsSchema,\n PublicIdSchema,\n TimestampSchema,\n} from \"../../shared/schemas.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { MfaSessionInfoSchema } from \"../mfa/mfa.schemas.js\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport type { AuthAndPublicApiTransports } from \"../../shared/transports.js\";\n\nexport const LoginWithWalletInputSchema = v.strictObject({\n smartAccountAddress: v.string(),\n nonce: v.string(),\n signature: v.string(),\n userAgent: v.optional(v.string(), \"\"),\n ip: v.optional(v.string(), \"\"),\n primaryWalletAddress: v.optional(v.string(), \"\"),\n walletProvider: v.optional(v.string(), \"\"),\n});\n\nexport type LoginWithWalletInput = v.InferInput<typeof LoginWithWalletInputSchema>;\n\nconst MeSchema = v.object({\n accountId: PublicIdSchema,\n apiKeyId: OptionalPublicIdSchema,\n username: v.string(),\n session: v.optional(MfaSessionInfoSchema),\n});\n\nexport type Me = v.InferOutput<typeof MeSchema>;\n\nconst LoginWithWalletResponseSchema = v.object({\n accessToken: v.string(),\n expiresAt: v.optional(TimestampSchema),\n accountId: PublicIdSchema,\n username: v.string(),\n});\n\nexport type LoginWithWalletResponse = v.InferOutput<typeof LoginWithWalletResponseSchema>;\n\nconst NonceSchema = v.object({\n nonce: v.string(),\n expiresAt: OptionalTimestampMsSchema,\n});\n\nexport type Nonce = v.InferOutput<typeof NonceSchema>;\n\n/**\n * Handles wallet-based authentication, caller introspection, and authenticated profile operations.\n */\nexport class AuthService {\n #publicClient: Client<typeof Proto.AuthService>;\n #authClient: Client<typeof Proto.AuthService>;\n profile: ProfileService;\n\n constructor(transports: AuthAndPublicApiTransports, realtime: PolyesterRealtime) {\n this.#publicClient = createClient(Proto.AuthService, transports.publicApi);\n this.#authClient = createClient(Proto.AuthService, transports.authApi);\n this.profile = new ProfileService(transports, realtime);\n }\n\n /**\n * Returns the authenticated caller's account context, including account ID, optional API key ID, username, and session assurance details from the presented token or API key.\n */\n async me(options?: PolyesterRequestOptions): Promise<Me> {\n const res = await this.#authClient.me({}, toConnectCallOptions(options));\n return parse(MeSchema, res);\n }\n\n /**\n * Requests a short-lived nonce for the given smart-account EVM address.\n * The nonce is single-purpose, replaced by subsequent requests, and expires\n * after about five minutes. The optional expiry is milliseconds since the\n * Unix epoch.\n */\n async requestLoginNonce(\n smartAccountAddress: string,\n options?: PolyesterRequestOptions,\n ): Promise<Nonce> {\n return parse(\n NonceSchema,\n await this.#publicClient.getNonce(\n { smartAccountAddress },\n toConnectCallOptions(options),\n ),\n );\n }\n\n /**\n * Exchanges a signed login nonce for an authenticated session token and account identity returned by the auth API.\n */\n protected async loginWithWallet(\n input: LoginWithWalletInput,\n options?: PolyesterMutationOptions,\n ): Promise<LoginWithWalletResponse> {\n const validatedInput = parse(LoginWithWalletInputSchema, input);\n const res = await this.#publicClient.loginWithWallet(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(LoginWithWalletResponseSchema, res);\n }\n}\n"],"mappings":";;;;;;;;;AAoBA,MAAa,6BAA6B,EAAE,aAAa;CACrD,qBAAqB,EAAE,OAAO;CAC9B,OAAO,EAAE,OAAO;CAChB,WAAW,EAAE,OAAO;CACpB,WAAW,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CACpC,IAAI,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CAC7B,sBAAsB,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CAC/C,gBAAgB,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;AAC7C,CAAC;AAID,MAAM,WAAW,EAAE,OAAO;CACtB,WAAW;CACX,UAAU;CACV,UAAU,EAAE,OAAO;CACnB,SAAS,EAAE,SAAS,oBAAoB;AAC5C,CAAC;AAID,MAAM,gCAAgC,EAAE,OAAO;CAC3C,aAAa,EAAE,OAAO;CACtB,WAAW,EAAE,SAAS,eAAe;CACrC,WAAW;CACX,UAAU,EAAE,OAAO;AACvB,CAAC;AAID,MAAM,cAAc,EAAE,OAAO;CACzB,OAAO,EAAE,OAAO;CAChB,WAAW;AACf,CAAC;;;;AAOD,IAAa,cAAb,MAAyB;CACrB;CACA;CACA;CAEA,YAAY,YAAwC,UAA6B;EAC7E,KAAKA,gBAAgB,aAAaC,eAAmB,WAAW,SAAS;EACzE,KAAKC,cAAc,aAAaD,eAAmB,WAAW,OAAO;EACrE,KAAK,UAAU,IAAI,eAAe,YAAY,QAAQ;CAC1D;;;;CAKA,MAAM,GAAG,SAAgD;EACrD,MAAM,MAAM,MAAM,KAAKC,YAAY,GAAG,CAAC,GAAG,qBAAqB,OAAO,CAAC;EACvE,OAAO,MAAM,UAAU,GAAG;CAC9B;;;;;;;CAQA,MAAM,kBACF,qBACA,SACc;EACd,OAAO,MACH,aACA,MAAM,KAAKF,cAAc,SACrB,EAAE,oBAAoB,GACtB,qBAAqB,OAAO,CAChC,CACJ;CACJ;;;;CAKA,MAAgB,gBACZ,OACA,SACgC;EAChC,MAAM,iBAAiB,MAAM,4BAA4B,KAAK;EAC9D,MAAM,MAAM,MAAM,KAAKA,cAAc,gBACjC,gBACA,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,+BAA+B,GAAG;CACnD;AACJ"}
@@ -1,9 +1,9 @@
1
+ import { AuthApiTransports } from "../../../shared/transports.js";
1
2
  import { PolyesterMutationOptions, PolyesterRequestOptions } from "../../../shared/request-options.js";
2
3
  import { PolyesterRealtime } from "../../../realtime/types.js";
3
4
  import "../../../realtime/index.js";
4
5
  import { BaseSubscribeInput } from "../../../shared/types.js";
5
6
  import { AccountIdentity, Profile, UpdateProfileInputSchema, UsernameHistoryEntry } from "./profile.schemas.js";
6
- import { Transport } from "@connectrpc/connect";
7
7
  import * as v from "valibot";
8
8
  //#region src/services/auth/profile/profile.d.ts
9
9
  interface SubscribeIdentityInput extends BaseSubscribeInput<AccountIdentity> {}
@@ -12,7 +12,7 @@ interface SubscribeIdentityInput extends BaseSubscribeInput<AccountIdentity> {}
12
12
  */
13
13
  declare class ProfileService {
14
14
  #private;
15
- constructor(transport: Transport, realtime: PolyesterRealtime);
15
+ constructor(transports: AuthApiTransports, realtime: PolyesterRealtime);
16
16
  /**
17
17
  * Fetches the caller's public profile, including username eligibility/cooldown, verified social handles, avatar, VIP tier, and account creation timestamp.
18
18
  */
@@ -1 +1 @@
1
- {"version":3,"file":"profile.d.ts","names":[],"sources":["../../../../src/services/auth/profile/profile.ts"],"mappings":";;;;;;;;UAsBU,+BAA+B,mBAAmB;;;;cAK/C;;EAIG,YAAA,WAAW,WAAW,UAAU;;;;EAQtC,IAAI,UAAU,0BAA0B,QAAQ;;;;EAShD,OACF,OAAO,EAAE,kBAAkB,2BAC3B,UAAU,2BACX,QAAQ;;;;EAYL,mBAAmB,UAAU,0BAA0B,QAAQ;;;;EAQrE,kBAAkB,OAAO"}
1
+ {"version":3,"file":"profile.d.ts","names":[],"sources":["../../../../src/services/auth/profile/profile.ts"],"mappings":";;;;;;;;UAuBU,+BAA+B,mBAAmB;;;;cAK/C;;EAIG,YAAA,YAAY,mBAAmB,UAAU;;;;EAQ/C,IAAI,UAAU,0BAA0B,QAAQ;;;;EAShD,OACF,OAAO,EAAE,kBAAkB,2BAC3B,UAAU,2BACX,QAAQ;;;;EAYL,mBAAmB,UAAU,0BAA0B,QAAQ;;;;EAQrE,kBAAkB,OAAO"}
@@ -12,8 +12,8 @@ import * as v from "valibot";
12
12
  var ProfileService = class {
13
13
  #client;
14
14
  #realtime;
15
- constructor(transport, realtime) {
16
- this.#client = createClient(ProfileService$1, transport);
15
+ constructor(transports, realtime) {
16
+ this.#client = createClient(ProfileService$1, transports.authApi);
17
17
  this.#realtime = realtime;
18
18
  }
19
19
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"profile.js","names":["#client","Proto.ProfileService","#realtime","Proto.AccountIdentitySchema","AccountIdentitySchema"],"sources":["../../../../src/services/auth/profile/profile.ts"],"sourcesContent":["import { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport * as Proto from \"../../../gen/auth/v1/profile_pb.js\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../../shared/validation.js\";\nimport { removeUndefined } from \"../../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../../shared/request-options.js\";\nimport {\n AccountIdentitySchema,\n ProfileSchema,\n UpdateProfileInputSchema,\n UsernameHistoryEntrySchema,\n type AccountIdentity,\n type Profile,\n type UsernameHistoryEntry,\n} from \"./profile.schemas.js\";\nimport type { BaseSubscribeInput } from \"../../../shared/types.js\";\nimport type { PolyesterRealtime } from \"../../../realtime/index.js\";\n\ninterface SubscribeIdentityInput extends BaseSubscribeInput<AccountIdentity> {}\n\n/**\n * Manages the authenticated account's public profile and realtime identity updates.\n */\nexport class ProfileService {\n #client: Client<typeof Proto.ProfileService>;\n #realtime: PolyesterRealtime;\n\n constructor(transport: Transport, realtime: PolyesterRealtime) {\n this.#client = createClient(Proto.ProfileService, transport);\n this.#realtime = realtime;\n }\n\n /**\n * Fetches the caller's public profile, including username eligibility/cooldown, verified social handles, avatar, VIP tier, and account creation timestamp.\n */\n async get(options?: PolyesterRequestOptions): Promise<Profile> {\n const res = await this.#client.getProfile({}, toConnectCallOptions(options));\n if (!res) throw new Error(\"Profile not found\");\n return parse(ProfileSchema, res);\n }\n\n /**\n * Updates only the provided mutable profile fields; omitted fields are unchanged, while present empty strings clear optional text fields such as bio, website, Twitter, and avatar URL.\n */\n async update(\n input: v.InferInput<typeof UpdateProfileInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<Profile> {\n const validatedInput = parse(UpdateProfileInputSchema, input);\n const res = await this.#client.updateProfile(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n return parse(ProfileSchema, res);\n }\n\n /**\n * Returns the caller's recent username changes, newest first, capped at 20 entries.\n */\n async getUsernameHistory(options?: PolyesterRequestOptions): Promise<UsernameHistoryEntry[]> {\n const res = await this.#client.getUsernameHistory({}, toConnectCallOptions(options));\n return parse(v.array(UsernameHistoryEntrySchema), res.history);\n }\n\n /**\n * Subscribes to public identity updates and emits normalized account identity records with base58 account IDs, username, avatar URL, and root smart-account address.\n */\n subscribeIdentity(input: SubscribeIdentityInput): () => void {\n const channel = \"public:identity:updates:proto\";\n return this.#realtime.connectProtoChannel({\n channel,\n schema: Proto.AccountIdentitySchema,\n onPublication: (data) => {\n const identity = parse(AccountIdentitySchema, data);\n input.onEvent(identity);\n },\n onConnected: () => input.onOpen?.(),\n onDisconnected: () => input.onClose?.(),\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AA2BA,IAAa,iBAAb,MAA4B;CACxB;CACA;CAEA,YAAY,WAAsB,UAA6B;EAC3D,KAAKA,UAAU,aAAaC,kBAAsB,SAAS;EAC3D,KAAKC,YAAY;CACrB;;;;CAKA,MAAM,IAAI,SAAqD;EAC3D,MAAM,MAAM,MAAM,KAAKF,QAAQ,WAAW,CAAC,GAAG,qBAAqB,OAAO,CAAC;EAC3E,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,mBAAmB;EAC7C,OAAO,MAAM,eAAe,GAAG;CACnC;;;;CAKA,MAAM,OACF,OACA,SACgB;EAChB,MAAM,iBAAiB,MAAM,0BAA0B,KAAK;EAC5D,MAAM,MAAM,MAAM,KAAKA,QAAQ,cAC3B,gBAAgB,cAAc,GAC9B,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,eAAe,GAAG;CACnC;;;;CAKA,MAAM,mBAAmB,SAAoE;EACzF,MAAM,MAAM,MAAM,KAAKA,QAAQ,mBAAmB,CAAC,GAAG,qBAAqB,OAAO,CAAC;EACnF,OAAO,MAAM,EAAE,MAAM,0BAA0B,GAAG,IAAI,OAAO;CACjE;;;;CAKA,kBAAkB,OAA2C;EAEzD,OAAO,KAAKE,UAAU,oBAAoB;GACtC,SAAA;GACA,QAAQC;GACR,gBAAgB,SAAS;IACrB,MAAM,WAAW,MAAMC,yBAAuB,IAAI;IAClD,MAAM,QAAQ,QAAQ;GAC1B;GACA,mBAAmB,MAAM,SAAS;GAClC,sBAAsB,MAAM,UAAU;GACtC,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
1
+ {"version":3,"file":"profile.js","names":["#client","Proto.ProfileService","#realtime","Proto.AccountIdentitySchema","AccountIdentitySchema"],"sources":["../../../../src/services/auth/profile/profile.ts"],"sourcesContent":["import { createClient, type Client } from \"@connectrpc/connect\";\nimport * as Proto from \"../../../gen/auth/v1/profile_pb.js\";\nimport type { AuthApiTransports } from \"../../../shared/transports.js\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../../shared/validation.js\";\nimport { removeUndefined } from \"../../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../../shared/request-options.js\";\nimport {\n AccountIdentitySchema,\n ProfileSchema,\n UpdateProfileInputSchema,\n UsernameHistoryEntrySchema,\n type AccountIdentity,\n type Profile,\n type UsernameHistoryEntry,\n} from \"./profile.schemas.js\";\nimport type { BaseSubscribeInput } from \"../../../shared/types.js\";\nimport type { PolyesterRealtime } from \"../../../realtime/index.js\";\n\ninterface SubscribeIdentityInput extends BaseSubscribeInput<AccountIdentity> {}\n\n/**\n * Manages the authenticated account's public profile and realtime identity updates.\n */\nexport class ProfileService {\n #client: Client<typeof Proto.ProfileService>;\n #realtime: PolyesterRealtime;\n\n constructor(transports: AuthApiTransports, realtime: PolyesterRealtime) {\n this.#client = createClient(Proto.ProfileService, transports.authApi);\n this.#realtime = realtime;\n }\n\n /**\n * Fetches the caller's public profile, including username eligibility/cooldown, verified social handles, avatar, VIP tier, and account creation timestamp.\n */\n async get(options?: PolyesterRequestOptions): Promise<Profile> {\n const res = await this.#client.getProfile({}, toConnectCallOptions(options));\n if (!res) throw new Error(\"Profile not found\");\n return parse(ProfileSchema, res);\n }\n\n /**\n * Updates only the provided mutable profile fields; omitted fields are unchanged, while present empty strings clear optional text fields such as bio, website, Twitter, and avatar URL.\n */\n async update(\n input: v.InferInput<typeof UpdateProfileInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<Profile> {\n const validatedInput = parse(UpdateProfileInputSchema, input);\n const res = await this.#client.updateProfile(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n return parse(ProfileSchema, res);\n }\n\n /**\n * Returns the caller's recent username changes, newest first, capped at 20 entries.\n */\n async getUsernameHistory(options?: PolyesterRequestOptions): Promise<UsernameHistoryEntry[]> {\n const res = await this.#client.getUsernameHistory({}, toConnectCallOptions(options));\n return parse(v.array(UsernameHistoryEntrySchema), res.history);\n }\n\n /**\n * Subscribes to public identity updates and emits normalized account identity records with base58 account IDs, username, avatar URL, and root smart-account address.\n */\n subscribeIdentity(input: SubscribeIdentityInput): () => void {\n const channel = \"public:identity:updates:proto\";\n return this.#realtime.connectProtoChannel({\n channel,\n schema: Proto.AccountIdentitySchema,\n onPublication: (data) => {\n const identity = parse(AccountIdentitySchema, data);\n input.onEvent(identity);\n },\n onConnected: () => input.onOpen?.(),\n onDisconnected: () => input.onClose?.(),\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AA4BA,IAAa,iBAAb,MAA4B;CACxB;CACA;CAEA,YAAY,YAA+B,UAA6B;EACpE,KAAKA,UAAU,aAAaC,kBAAsB,WAAW,OAAO;EACpE,KAAKC,YAAY;CACrB;;;;CAKA,MAAM,IAAI,SAAqD;EAC3D,MAAM,MAAM,MAAM,KAAKF,QAAQ,WAAW,CAAC,GAAG,qBAAqB,OAAO,CAAC;EAC3E,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,mBAAmB;EAC7C,OAAO,MAAM,eAAe,GAAG;CACnC;;;;CAKA,MAAM,OACF,OACA,SACgB;EAChB,MAAM,iBAAiB,MAAM,0BAA0B,KAAK;EAC5D,MAAM,MAAM,MAAM,KAAKA,QAAQ,cAC3B,gBAAgB,cAAc,GAC9B,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,eAAe,GAAG;CACnC;;;;CAKA,MAAM,mBAAmB,SAAoE;EACzF,MAAM,MAAM,MAAM,KAAKA,QAAQ,mBAAmB,CAAC,GAAG,qBAAqB,OAAO,CAAC;EACnF,OAAO,MAAM,EAAE,MAAM,0BAA0B,GAAG,IAAI,OAAO;CACjE;;;;CAKA,kBAAkB,OAA2C;EAEzD,OAAO,KAAKE,UAAU,oBAAoB;GACtC,SAAA;GACA,QAAQC;GACR,gBAAgB,SAAS;IACrB,MAAM,WAAW,MAAMC,yBAAuB,IAAI;IAClD,MAAM,QAAQ,QAAQ;GAC1B;GACA,mBAAmB,MAAM,SAAS;GAClC,sBAAsB,MAAM,UAAU;GACtC,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
@@ -1,3 +1,4 @@
1
+ import { AuthApiTransports } from "../../shared/transports.js";
1
2
  import { PolyesterRequestOptions } from "../../shared/request-options.js";
2
3
  import { AccountScopedInput } from "../../shared/account-scope.js";
3
4
  import { SubaccountResolver } from "../subaccount-resolver.js";
@@ -6,7 +7,6 @@ import "../../realtime/index.js";
6
7
  import { BaseSubscribeInput } from "../../shared/types.js";
7
8
  import { SdkScales } from "../../shared/decimal-surface.js";
8
9
  import { BalanceHistoryInput, BalanceHistoryResponse, EquityHistoryInput, EquityHistoryResponse, LedgerBalance } from "./balances.schemas.js";
9
- import { Transport } from "@connectrpc/connect";
10
10
  //#region src/services/balances/balances.d.ts
11
11
  interface SubscribeBalancesInput extends BaseSubscribeInput<LedgerBalance> {
12
12
  accountId: string;
@@ -16,7 +16,7 @@ interface SubscribeBalancesInput extends BaseSubscribeInput<LedgerBalance> {
16
16
  */
17
17
  declare class BalancesService {
18
18
  #private;
19
- constructor(transport: Transport, realtime: PolyesterRealtime, resolver: SubaccountResolver | undefined, scales: SdkScales);
19
+ constructor(transports: AuthApiTransports, realtime: PolyesterRealtime, resolver: SubaccountResolver | undefined, scales: SdkScales);
20
20
  /**
21
21
  * Returns current asset balances for the resolved root account or subaccount, including trading, funding, reserved, and available amounts as decimal strings.
22
22
  */
@@ -1 +1 @@
1
- {"version":3,"file":"balances.d.ts","names":[],"sources":["../../../src/services/balances/balances.ts"],"mappings":";;;;;;;;;;UA4BU,+BAA+B,mBAAmB;EACxD;;;;;cAMS;;EAUL,YAAA,WAAW,WACX,UAAU,mBACV,UAAU,gCACV,QAAQ;;;;EAcN,KACF,QAAO,oBACP,UAAU,0BACX,QAAQ;;;;EAgBL,kBACF,OAAO,qBACP,UAAU,0BACX,QAAQ;;;;EAWL,iBACF,OAAO,oBACP,UAAU,0BACX,QAAQ;;;;EAcX,UAAU,OAAO"}
1
+ {"version":3,"file":"balances.d.ts","names":[],"sources":["../../../src/services/balances/balances.ts"],"mappings":";;;;;;;;;;UA6BU,+BAA+B,mBAAmB;EACxD;;;;;cAMS;;EAUL,YAAA,YAAY,mBACZ,UAAU,mBACV,UAAU,gCACV,QAAQ;;;;EAcN,KACF,QAAO,oBACP,UAAU,0BACX,QAAQ;;;;EAgBL,kBACF,OAAO,qBACP,UAAU,0BACX,QAAQ;;;;EAWL,iBACF,OAAO,oBACP,UAAU,0BACX,QAAQ;;;;EAcX,UAAU,OAAO"}
@@ -19,8 +19,8 @@ var BalancesService = class {
19
19
  #ledgerBalanceSchema;
20
20
  #balanceHistoryResponseSchema;
21
21
  #equityHistoryResponseSchema;
22
- constructor(transport, realtime, resolver, scales) {
23
- this.#client = createClient(LedgerReadService, transport);
22
+ constructor(transports, realtime, resolver, scales) {
23
+ this.#client = createClient(LedgerReadService, transports.authApi);
24
24
  this.#realtime = realtime;
25
25
  this.#resolver = resolver;
26
26
  this.#scales = scales;
@@ -1 +1 @@
1
- {"version":3,"file":"balances.js","names":["#client","Proto.LedgerReadService","#realtime","#resolver","#scales","#ledgerBalanceSchema","#balanceHistoryResponseSchema","#equityHistoryResponseSchema","Proto.AssetBalanceSchema"],"sources":["../../../src/services/balances/balances.ts"],"sourcesContent":["import * as Proto from \"../../gen/ledger/read/v1/ledger_read_pb.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport { connectReadyGatedProtoChannel } from \"../../realtime/ready-gated-subscription.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { accountScopeToSubaccountId, type AccountScopedInput } from \"../../shared/account-scope.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n BalanceHistoryInputSchema,\n BalancesListInputSchema,\n EquityHistoryInputSchema,\n createBalanceHistoryResponseSchema,\n createEquityHistoryResponseSchema,\n createLedgerBalanceSchema,\n type LedgerBalance,\n type BalanceHistoryInput,\n type BalanceHistoryResponse,\n type EquityHistoryInput,\n type EquityHistoryResponse,\n} from \"./balances.schemas.js\";\n\ninterface SubscribeBalancesInput extends BaseSubscribeInput<LedgerBalance> {\n accountId: string;\n}\n\n/**\n * Reads and streams ledger balances plus balance and equity history for the authenticated account scope.\n */\nexport class BalancesService {\n #client: Client<typeof Proto.LedgerReadService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n #scales: SdkScales;\n #ledgerBalanceSchema: ReturnType<typeof createLedgerBalanceSchema>;\n #balanceHistoryResponseSchema: ReturnType<typeof createBalanceHistoryResponseSchema>;\n #equityHistoryResponseSchema: ReturnType<typeof createEquityHistoryResponseSchema>;\n\n constructor(\n transport: Transport,\n realtime: PolyesterRealtime,\n resolver: SubaccountResolver | undefined,\n scales: SdkScales,\n ) {\n this.#client = createClient(Proto.LedgerReadService, transport);\n this.#realtime = realtime;\n this.#resolver = resolver;\n this.#scales = scales;\n this.#ledgerBalanceSchema = createLedgerBalanceSchema();\n this.#balanceHistoryResponseSchema = createBalanceHistoryResponseSchema();\n this.#equityHistoryResponseSchema = createEquityHistoryResponseSchema(scales);\n }\n\n /**\n * Returns current asset balances for the resolved root account or subaccount, including trading, funding, reserved, and available amounts as decimal strings.\n */\n async list(\n input: AccountScopedInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<LedgerBalance[]> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validated = parse(BalancesListInputSchema, resolved);\n const res = await this.#client.getBalances(\n {\n subaccountId: accountScopeToSubaccountId(validated.account),\n },\n toConnectCallOptions(options),\n );\n return parse(v.array(this.#ledgerBalanceSchema), res.balances);\n }\n\n /**\n * Returns columnar balance history for the resolved account scope over a selected range, optionally filtered by a non-negative integer ledger asset ID and account buckets. Ledger 0 or omission includes all assets.\n */\n async getBalanceHistory(\n input: BalanceHistoryInput,\n options?: PolyesterRequestOptions,\n ): Promise<BalanceHistoryResponse> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validated = parse(BalanceHistoryInputSchema, resolved);\n const res = await this.#client.getBalanceHistory(validated, toConnectCallOptions(options));\n return parse(this.#balanceHistoryResponseSchema, res);\n }\n\n /**\n * Returns equity history series for the resolved account scope over a selected range, optionally grouped by account or asset and filtered by account buckets.\n */\n async getEquityHistory(\n input: EquityHistoryInput,\n options?: PolyesterRequestOptions,\n ): Promise<EquityHistoryResponse> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validated = parse(EquityHistoryInputSchema, resolved);\n const res = await this.#client.getEquityHistorySeries(\n validated,\n toConnectCallOptions(options),\n );\n return parse(this.#equityHistoryResponseSchema, res);\n }\n\n /**\n * Subscribes to private balance updates on private:ledger:balances:{accountId}:proto and emits every balance record as a decimal-string row. Records for assets unknown to the catalog route a CatalogLookupError to onError.\n */\n subscribe(input: SubscribeBalancesInput): () => void {\n const channel = `private:ledger:balances:${input.accountId}:proto`;\n return connectReadyGatedProtoChannel(this.#realtime, {\n channel,\n schema: Proto.AssetBalanceSchema,\n ready: () => this.#scales.ready(),\n onPublication: (data) => {\n const b = parse(this.#ledgerBalanceSchema, data);\n input.onEvent(b);\n },\n onConnected: input.onOpen,\n onDisconnected: input.onClose,\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAmCA,IAAa,kBAAb,MAA6B;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YACI,WACA,UACA,UACA,QACF;EACE,KAAKA,UAAU,aAAaC,mBAAyB,SAAS;EAC9D,KAAKC,YAAY;EACjB,KAAKC,YAAY;EACjB,KAAKC,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C;GACnB;GACA,aAAa,MAAM;GACnB,gBAAgB,MAAM;GACtB,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
1
+ {"version":3,"file":"balances.js","names":["#client","Proto.LedgerReadService","#realtime","#resolver","#scales","#ledgerBalanceSchema","#balanceHistoryResponseSchema","#equityHistoryResponseSchema","Proto.AssetBalanceSchema"],"sources":["../../../src/services/balances/balances.ts"],"sourcesContent":["import * as Proto from \"../../gen/ledger/read/v1/ledger_read_pb.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport { connectReadyGatedProtoChannel } from \"../../realtime/ready-gated-subscription.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { accountScopeToSubaccountId, type AccountScopedInput } from \"../../shared/account-scope.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport {\n BalanceHistoryInputSchema,\n BalancesListInputSchema,\n EquityHistoryInputSchema,\n createBalanceHistoryResponseSchema,\n createEquityHistoryResponseSchema,\n createLedgerBalanceSchema,\n type LedgerBalance,\n type BalanceHistoryInput,\n type BalanceHistoryResponse,\n type EquityHistoryInput,\n type EquityHistoryResponse,\n} from \"./balances.schemas.js\";\n\ninterface SubscribeBalancesInput extends BaseSubscribeInput<LedgerBalance> {\n accountId: string;\n}\n\n/**\n * Reads and streams ledger balances plus balance and equity history for the authenticated account scope.\n */\nexport class BalancesService {\n #client: Client<typeof Proto.LedgerReadService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n #scales: SdkScales;\n #ledgerBalanceSchema: ReturnType<typeof createLedgerBalanceSchema>;\n #balanceHistoryResponseSchema: ReturnType<typeof createBalanceHistoryResponseSchema>;\n #equityHistoryResponseSchema: ReturnType<typeof createEquityHistoryResponseSchema>;\n\n constructor(\n transports: AuthApiTransports,\n realtime: PolyesterRealtime,\n resolver: SubaccountResolver | undefined,\n scales: SdkScales,\n ) {\n this.#client = createClient(Proto.LedgerReadService, transports.authApi);\n this.#realtime = realtime;\n this.#resolver = resolver;\n this.#scales = scales;\n this.#ledgerBalanceSchema = createLedgerBalanceSchema();\n this.#balanceHistoryResponseSchema = createBalanceHistoryResponseSchema();\n this.#equityHistoryResponseSchema = createEquityHistoryResponseSchema(scales);\n }\n\n /**\n * Returns current asset balances for the resolved root account or subaccount, including trading, funding, reserved, and available amounts as decimal strings.\n */\n async list(\n input: AccountScopedInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<LedgerBalance[]> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validated = parse(BalancesListInputSchema, resolved);\n const res = await this.#client.getBalances(\n {\n subaccountId: accountScopeToSubaccountId(validated.account),\n },\n toConnectCallOptions(options),\n );\n return parse(v.array(this.#ledgerBalanceSchema), res.balances);\n }\n\n /**\n * Returns columnar balance history for the resolved account scope over a selected range, optionally filtered by a non-negative integer ledger asset ID and account buckets. Ledger 0 or omission includes all assets.\n */\n async getBalanceHistory(\n input: BalanceHistoryInput,\n options?: PolyesterRequestOptions,\n ): Promise<BalanceHistoryResponse> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validated = parse(BalanceHistoryInputSchema, resolved);\n const res = await this.#client.getBalanceHistory(validated, toConnectCallOptions(options));\n return parse(this.#balanceHistoryResponseSchema, res);\n }\n\n /**\n * Returns equity history series for the resolved account scope over a selected range, optionally grouped by account or asset and filtered by account buckets.\n */\n async getEquityHistory(\n input: EquityHistoryInput,\n options?: PolyesterRequestOptions,\n ): Promise<EquityHistoryResponse> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validated = parse(EquityHistoryInputSchema, resolved);\n const res = await this.#client.getEquityHistorySeries(\n validated,\n toConnectCallOptions(options),\n );\n return parse(this.#equityHistoryResponseSchema, res);\n }\n\n /**\n * Subscribes to private balance updates on private:ledger:balances:{accountId}:proto and emits every balance record as a decimal-string row. Records for assets unknown to the catalog route a CatalogLookupError to onError.\n */\n subscribe(input: SubscribeBalancesInput): () => void {\n const channel = `private:ledger:balances:${input.accountId}:proto`;\n return connectReadyGatedProtoChannel(this.#realtime, {\n channel,\n schema: Proto.AssetBalanceSchema,\n ready: () => this.#scales.ready(),\n onPublication: (data) => {\n const b = parse(this.#ledgerBalanceSchema, data);\n input.onEvent(b);\n },\n onConnected: input.onOpen,\n onDisconnected: input.onClose,\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAoCA,IAAa,kBAAb,MAA6B;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YACI,YACA,UACA,UACA,QACF;EACE,KAAKA,UAAU,aAAaC,mBAAyB,WAAW,OAAO;EACvE,KAAKC,YAAY;EACjB,KAAKC,YAAY;EACjB,KAAKC,UAAU;EACf,KAAKC,uBAAuB,0BAA0B;EACtD,KAAKC,gCAAgC,mCAAmC;EACxE,KAAKC,+BAA+B,kCAAkC,MAAM;CAChF;;;;CAKA,MAAM,KACF,QAA4B,CAAC,GAC7B,SACwB;EACxB,MAAM,KAAKH,QAAQ,MAAM;EACzB,MAAM,WAAW,0BAA0B,OAAO,KAAKD,SAAS;EAChE,MAAM,YAAY,MAAM,yBAAyB,QAAQ;EACzD,MAAM,MAAM,MAAM,KAAKH,QAAQ,YAC3B,EACI,cAAc,2BAA2B,UAAU,OAAO,EAC9D,GACA,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,EAAE,MAAM,KAAKK,oBAAoB,GAAG,IAAI,QAAQ;CACjE;;;;CAKA,MAAM,kBACF,OACA,SAC+B;EAC/B,MAAM,KAAKD,QAAQ,MAAM;EACzB,MAAM,WAAW,0BAA0B,OAAO,KAAKD,SAAS;EAChE,MAAM,YAAY,MAAM,2BAA2B,QAAQ;EAC3D,MAAM,MAAM,MAAM,KAAKH,QAAQ,kBAAkB,WAAW,qBAAqB,OAAO,CAAC;EACzF,OAAO,MAAM,KAAKM,+BAA+B,GAAG;CACxD;;;;CAKA,MAAM,iBACF,OACA,SAC8B;EAC9B,MAAM,KAAKF,QAAQ,MAAM;EACzB,MAAM,WAAW,0BAA0B,OAAO,KAAKD,SAAS;EAChE,MAAM,YAAY,MAAM,0BAA0B,QAAQ;EAC1D,MAAM,MAAM,MAAM,KAAKH,QAAQ,uBAC3B,WACA,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,KAAKO,8BAA8B,GAAG;CACvD;;;;CAKA,UAAU,OAA2C;EACjD,MAAM,UAAU,2BAA2B,MAAM,UAAU;EAC3D,OAAO,8BAA8B,KAAKL,WAAW;GACjD;GACA,QAAQM;GACR,aAAa,KAAKJ,QAAQ,MAAM;GAChC,gBAAgB,SAAS;IACrB,MAAM,IAAI,MAAM,KAAKC,sBAAsB,IAAI;IAC/C,MAAM,QAAQ,CAAC;GACnB;GACA,aAAa,MAAM;GACnB,gBAAgB,MAAM;GACtB,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
@@ -1,9 +1,9 @@
1
+ import { PublicApiTransports } from "../../shared/transports.js";
1
2
  import { PolyesterRequestOptions } from "../../shared/request-options.js";
2
3
  import { PolyesterRealtime } from "../../realtime/types.js";
3
4
  import { BaseSubscribeInput } from "../../shared/types.js";
4
5
  import { SdkScales } from "../../shared/decimal-surface.js";
5
6
  import { Candle, CandleColumnar, CandleColumnarInt, CandleInt, GetCandlesColumnsInput, GetCandlesInput, Timeframe } from "./candles.schemas.js";
6
- import { Transport } from "@connectrpc/connect";
7
7
  //#region src/services/candles/candles.d.ts
8
8
  interface SubscribeCandlesInput extends BaseSubscribeInput<Candle> {
9
9
  symbolId: number;
@@ -18,7 +18,7 @@ interface SubscribeCandlesIntsInput extends BaseSubscribeInput<CandleInt> {
18
18
  */
19
19
  declare class CandlesService {
20
20
  #private;
21
- constructor(transport: Transport, realtime: PolyesterRealtime, scales: SdkScales);
21
+ constructor(transports: PublicApiTransports, realtime: PolyesterRealtime, scales: SdkScales);
22
22
  /**
23
23
  * Returns OHLCV candles for a symbol/timeframe request, mapped into row objects with symbol id and timeframe. The proto response is newest-first and may include incomplete/reference data depending on input flags.
24
24
  */
@@ -1 +1 @@
1
- {"version":3,"file":"candles.d.ts","names":[],"sources":["../../../src/services/candles/candles.ts"],"mappings":";;;;;;;UA8BU,8BAA8B,mBAAmB;EACvD;EACA,WAAW;;UAGL,kCAAkC,mBAAmB;EAC3D;EACA,WAAW;;;;;cAWF;;EASG,YAAA,WAAW,WAAW,UAAU,mBAAmB,QAAQ;;;;EAajE,KAAK,OAAO,iBAAiB,UAAU,0BAA0B,QAAQ;;;;EAiBzE,aACF,OAAO,wBACP,UAAU,0BACX,QAAQ;;;;EAaL,iBACF,OAAO,wBACP,UAAU,0BACX,QAAQ;;;;EAaX,UAAU,OAAO;;;;EAOjB,cAAc,OAAO"}
1
+ {"version":3,"file":"candles.d.ts","names":[],"sources":["../../../src/services/candles/candles.ts"],"mappings":";;;;;;;UA+BU,8BAA8B,mBAAmB;EACvD;EACA,WAAW;;UAGL,kCAAkC,mBAAmB;EAC3D;EACA,WAAW;;;;;cAWF;;EASG,YAAA,YAAY,qBAAqB,UAAU,mBAAmB,QAAQ;;;;EAa5E,KAAK,OAAO,iBAAiB,UAAU,0BAA0B,QAAQ;;;;EAiBzE,aACF,OAAO,wBACP,UAAU,0BACX,QAAQ;;;;EAaL,iBACF,OAAO,wBACP,UAAU,0BACX,QAAQ;;;;EAaX,UAAU,OAAO;;;;EAOjB,cAAc,OAAO"}
@@ -22,8 +22,8 @@ var CandlesService = class {
22
22
  #rowIntSchema;
23
23
  #columnarSchema;
24
24
  #columnarIntSchema;
25
- constructor(transport, realtime, scales) {
26
- this.#client = createClient(MarketDataService, transport);
25
+ constructor(transports, realtime, scales) {
26
+ this.#client = createClient(MarketDataService, transports.publicApi);
27
27
  this.#realtime = realtime;
28
28
  this.#scales = scales;
29
29
  this.#rowSchema = createCandleRowSchema(scales);
@@ -1 +1 @@
1
- {"version":3,"file":"candles.js","names":["#client","Proto.MarketDataService","#realtime","#scales","#rowSchema","#rowIntSchema","#columnarSchema","#columnarIntSchema","CandlePointSchema","#subscribeWithSchema","Proto.CandlePointSchema"],"sources":["../../../src/services/candles/candles.ts"],"sourcesContent":["import { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport * as Proto from \"../../gen/marketdata/v1/marketdata_pb.js\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport type { PolyesterRealtime } from \"../../realtime/types.js\";\nimport { connectReadyGatedProtoChannel } from \"../../realtime/ready-gated-subscription.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n type CandleColumnar,\n createCandleRowSchema,\n createCandleRowIntSchema,\n createCandleColumnarSchema,\n createCandleColumnarIntSchema,\n CandlePointSchema,\n TimeframeSchema,\n type Candle,\n type CandleInt,\n type Timeframe,\n type CandleColumnarInt,\n type GetCandlesInput,\n type GetCandlesColumnsInput,\n ListCandlesInputSchema,\n} from \"./candles.schemas.js\";\nimport { TimeframeCodec } from \"./candles.codecs.js\";\n\ninterface SubscribeCandlesInput extends BaseSubscribeInput<Candle> {\n symbolId: number;\n timeframe: Timeframe;\n}\n\ninterface SubscribeCandlesIntsInput extends BaseSubscribeInput<CandleInt> {\n symbolId: number;\n timeframe: Timeframe;\n}\n\nconst SubscribeCandlesParamsSchema = v.object({\n symbolId: v.pipe(v.number(), v.integer(), v.gtValue(0)),\n timeframe: TimeframeSchema,\n});\n\n/**\n * Reads and streams public spot OHLCV candle data in row and columnar formats.\n */\nexport class CandlesService {\n #client: Client<typeof Proto.MarketDataService>;\n #realtime: PolyesterRealtime;\n #scales: SdkScales;\n #rowSchema: ReturnType<typeof createCandleRowSchema>;\n #rowIntSchema: ReturnType<typeof createCandleRowIntSchema>;\n #columnarSchema: ReturnType<typeof createCandleColumnarSchema>;\n #columnarIntSchema: ReturnType<typeof createCandleColumnarIntSchema>;\n\n constructor(transport: Transport, realtime: PolyesterRealtime, scales: SdkScales) {\n this.#client = createClient(Proto.MarketDataService, transport);\n this.#realtime = realtime;\n this.#scales = scales;\n this.#rowSchema = createCandleRowSchema(scales);\n this.#rowIntSchema = createCandleRowIntSchema(scales);\n this.#columnarSchema = createCandleColumnarSchema(scales);\n this.#columnarIntSchema = createCandleColumnarIntSchema(scales);\n }\n\n /**\n * Returns OHLCV candles for a symbol/timeframe request, mapped into row objects with symbol id and timeframe. The proto response is newest-first and may include incomplete/reference data depending on input flags.\n */\n async list(input: GetCandlesInput, options?: PolyesterRequestOptions): Promise<Candle[]> {\n const validatedInput = parse(ListCandlesInputSchema, input);\n await this.#scales.ready();\n const res = await this.#client.getCandles(validatedInput, toConnectCallOptions(options));\n const candles = parse(v.optional(v.array(CandlePointSchema), []), res.candles);\n return candles.map((c) =>\n parse(this.#rowSchema, {\n ...c,\n symbolId: res.symbolId,\n timeframe: res.timeframe,\n }),\n );\n }\n\n /**\n * Returns candle data in chart-friendly column arrays ordered oldest-first by bucket start time. This preserves decimal-string SDK formatting from the columnar schema.\n */\n async listColumnar(\n input: GetCandlesColumnsInput,\n options?: PolyesterRequestOptions,\n ): Promise<CandleColumnar> {\n const validatedInput = parse(ListCandlesInputSchema, input);\n await this.#scales.ready();\n const res = await this.#client.getCandlesColumns(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(this.#columnarSchema, res);\n }\n\n /**\n * Returns the same columnar candle series keyed by numeric bucket-start seconds (`tsSec`) instead of `time`.\n */\n async listColumnarInts(\n input: GetCandlesColumnsInput,\n options?: PolyesterRequestOptions,\n ): Promise<CandleColumnarInt> {\n const validatedInput = parse(ListCandlesInputSchema, input);\n await this.#scales.ready();\n const res = await this.#client.getCandlesColumns(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(this.#columnarIntSchema, res);\n }\n\n /**\n * Subscribes to live candle updates on public:spot:market:candles:{timeframe}:{symbolId}:proto and emits row-form candles.\n */\n subscribe(input: SubscribeCandlesInput): () => void {\n return this.#subscribeWithSchema(input, this.#rowSchema);\n }\n\n /**\n * Subscribes to the same live candle channel as subscribe and emits row candles parsed through the row-int schema.\n */\n subscribeInts(input: SubscribeCandlesIntsInput): () => void {\n return this.#subscribeWithSchema(input, this.#rowIntSchema);\n }\n\n #subscribeWithSchema(\n input: SubscribeCandlesInput | SubscribeCandlesIntsInput,\n schema: ReturnType<typeof createCandleRowSchema>,\n ): () => void {\n const params = parse(SubscribeCandlesParamsSchema, {\n symbolId: input.symbolId,\n timeframe: input.timeframe,\n });\n const protoTimeframe = TimeframeCodec.inputToProto[params.timeframe];\n const channel = `public:spot:market:candles:${params.timeframe}:${params.symbolId}:proto`;\n return connectReadyGatedProtoChannel(this.#realtime, {\n channel,\n schema: Proto.CandlePointSchema,\n ready: () => this.#scales.ready(),\n onPublication: (data) => {\n const point = parse(CandlePointSchema, data);\n const candle = parse(schema, {\n ...point,\n symbolId: params.symbolId,\n timeframe: protoTimeframe,\n });\n input.onEvent(candle);\n },\n onConnected: input.onOpen,\n onDisconnected: input.onClose,\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;AAwCA,MAAM,+BAA+B,EAAE,OAAO;CAC1C,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,QAAQ,GAAG,EAAE,QAAQ,CAAC,CAAC;CACtD,WAAW;AACf,CAAC;;;;AAKD,IAAa,iBAAb,MAA4B;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,WAAsB,UAA6B,QAAmB;EAC9E,KAAKA,UAAU,aAAaC,mBAAyB,SAAS;EAC9D,KAAKC,YAAY;EACjB,KAAKC,UA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,MAAM;EACrB,CAAC;EACD,MAAM,iBAAiB,eAAe,aAAa,OAAO;EAC1D,MAAM,UAAU,8BAA8B,OAAO,UAAU,GAAG,OAAO,SAAS;EAClF,OAAO,8BAA8B,KAAKH,WAAW;GACjD;GACA,QAAQQ;GACR,aAAa,KAAKP,QAAQ,MAAM;GAChC,gBAAgB,SAAS;IACrB,MAAM,QAAQ,MAAMK,qBAAmB,IAAI;IAC3C,MAAM,SAAS,MAAM,QAAQ;KACzB,GAAG;KACH,UAAU,OAAO;KACjB,WAAW;IACf,CAAC;IACD,MAAM,QAAQ,MAAM;GACxB;GACA,aAAa,MAAM;GACnB,gBAAgB,MAAM;GACtB,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
1
+ {"version":3,"file":"candles.js","names":["#client","Proto.MarketDataService","#realtime","#scales","#rowSchema","#rowIntSchema","#columnarSchema","#columnarIntSchema","CandlePointSchema","#subscribeWithSchema","Proto.CandlePointSchema"],"sources":["../../../src/services/candles/candles.ts"],"sourcesContent":["import { createClient, type Client } from \"@connectrpc/connect\";\nimport * as Proto from \"../../gen/marketdata/v1/marketdata_pb.js\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport type { PolyesterRealtime } from \"../../realtime/types.js\";\nimport { connectReadyGatedProtoChannel } from \"../../realtime/ready-gated-subscription.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport type { PublicApiTransports } from \"../../shared/transports.js\";\nimport {\n type CandleColumnar,\n createCandleRowSchema,\n createCandleRowIntSchema,\n createCandleColumnarSchema,\n createCandleColumnarIntSchema,\n CandlePointSchema,\n TimeframeSchema,\n type Candle,\n type CandleInt,\n type Timeframe,\n type CandleColumnarInt,\n type GetCandlesInput,\n type GetCandlesColumnsInput,\n ListCandlesInputSchema,\n} from \"./candles.schemas.js\";\nimport { TimeframeCodec } from \"./candles.codecs.js\";\n\ninterface SubscribeCandlesInput extends BaseSubscribeInput<Candle> {\n symbolId: number;\n timeframe: Timeframe;\n}\n\ninterface SubscribeCandlesIntsInput extends BaseSubscribeInput<CandleInt> {\n symbolId: number;\n timeframe: Timeframe;\n}\n\nconst SubscribeCandlesParamsSchema = v.object({\n symbolId: v.pipe(v.number(), v.integer(), v.gtValue(0)),\n timeframe: TimeframeSchema,\n});\n\n/**\n * Reads and streams public spot OHLCV candle data in row and columnar formats.\n */\nexport class CandlesService {\n #client: Client<typeof Proto.MarketDataService>;\n #realtime: PolyesterRealtime;\n #scales: SdkScales;\n #rowSchema: ReturnType<typeof createCandleRowSchema>;\n #rowIntSchema: ReturnType<typeof createCandleRowIntSchema>;\n #columnarSchema: ReturnType<typeof createCandleColumnarSchema>;\n #columnarIntSchema: ReturnType<typeof createCandleColumnarIntSchema>;\n\n constructor(transports: PublicApiTransports, realtime: PolyesterRealtime, scales: SdkScales) {\n this.#client = createClient(Proto.MarketDataService, transports.publicApi);\n this.#realtime = realtime;\n this.#scales = scales;\n this.#rowSchema = createCandleRowSchema(scales);\n this.#rowIntSchema = createCandleRowIntSchema(scales);\n this.#columnarSchema = createCandleColumnarSchema(scales);\n this.#columnarIntSchema = createCandleColumnarIntSchema(scales);\n }\n\n /**\n * Returns OHLCV candles for a symbol/timeframe request, mapped into row objects with symbol id and timeframe. The proto response is newest-first and may include incomplete/reference data depending on input flags.\n */\n async list(input: GetCandlesInput, options?: PolyesterRequestOptions): Promise<Candle[]> {\n const validatedInput = parse(ListCandlesInputSchema, input);\n await this.#scales.ready();\n const res = await this.#client.getCandles(validatedInput, toConnectCallOptions(options));\n const candles = parse(v.optional(v.array(CandlePointSchema), []), res.candles);\n return candles.map((c) =>\n parse(this.#rowSchema, {\n ...c,\n symbolId: res.symbolId,\n timeframe: res.timeframe,\n }),\n );\n }\n\n /**\n * Returns candle data in chart-friendly column arrays ordered oldest-first by bucket start time. This preserves decimal-string SDK formatting from the columnar schema.\n */\n async listColumnar(\n input: GetCandlesColumnsInput,\n options?: PolyesterRequestOptions,\n ): Promise<CandleColumnar> {\n const validatedInput = parse(ListCandlesInputSchema, input);\n await this.#scales.ready();\n const res = await this.#client.getCandlesColumns(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(this.#columnarSchema, res);\n }\n\n /**\n * Returns the same columnar candle series keyed by numeric bucket-start seconds (`tsSec`) instead of `time`.\n */\n async listColumnarInts(\n input: GetCandlesColumnsInput,\n options?: PolyesterRequestOptions,\n ): Promise<CandleColumnarInt> {\n const validatedInput = parse(ListCandlesInputSchema, input);\n await this.#scales.ready();\n const res = await this.#client.getCandlesColumns(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(this.#columnarIntSchema, res);\n }\n\n /**\n * Subscribes to live candle updates on public:spot:market:candles:{timeframe}:{symbolId}:proto and emits row-form candles.\n */\n subscribe(input: SubscribeCandlesInput): () => void {\n return this.#subscribeWithSchema(input, this.#rowSchema);\n }\n\n /**\n * Subscribes to the same live candle channel as subscribe and emits row candles parsed through the row-int schema.\n */\n subscribeInts(input: SubscribeCandlesIntsInput): () => void {\n return this.#subscribeWithSchema(input, this.#rowIntSchema);\n }\n\n #subscribeWithSchema(\n input: SubscribeCandlesInput | SubscribeCandlesIntsInput,\n schema: ReturnType<typeof createCandleRowSchema>,\n ): () => void {\n const params = parse(SubscribeCandlesParamsSchema, {\n symbolId: input.symbolId,\n timeframe: input.timeframe,\n });\n const protoTimeframe = TimeframeCodec.inputToProto[params.timeframe];\n const channel = `public:spot:market:candles:${params.timeframe}:${params.symbolId}:proto`;\n return connectReadyGatedProtoChannel(this.#realtime, {\n channel,\n schema: Proto.CandlePointSchema,\n ready: () => this.#scales.ready(),\n onPublication: (data) => {\n const point = parse(CandlePointSchema, data);\n const candle = parse(schema, {\n ...point,\n symbolId: params.symbolId,\n timeframe: protoTimeframe,\n });\n input.onEvent(candle);\n },\n onConnected: input.onOpen,\n onDisconnected: input.onClose,\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AQ,MAAM;EACzB,MAAM,MAAM,MAAM,KAAKH,QAAQ,kBAC3B,gBACA,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,KAAKO,oBAAoB,GAAG;CAC7C;;;;CAKA,UAAU,OAA0C;EAChD,OAAO,KAAKE,qBAAqB,OAAO,KAAKL,UAAU;CAC3D;;;;CAKA,cAAc,OAA8C;EACxD,OAAO,KAAKK,qBAAqB,OAAO,KAAKJ,aAAa;CAC9D;CAEA,qBACI,OACA,QACU;EACV,MAAM,SAAS,MAAM,8BAA8B;GAC/C,UAAU,MAAM;GAChB,WAAW,MAAM;EACrB,CAAC;EACD,MAAM,iBAAiB,eAAe,aAAa,OAAO;EAC1D,MAAM,UAAU,8BAA8B,OAAO,UAAU,GAAG,OAAO,SAAS;EAClF,OAAO,8BAA8B,KAAKH,WAAW;GACjD;GACA,QAAQQ;GACR,aAAa,KAAKP,QAAQ,MAAM;GAChC,gBAAgB,SAAS;IACrB,MAAM,QAAQ,MAAMK,qBAAmB,IAAI;IAC3C,MAAM,SAAS,MAAM,QAAQ;KACzB,GAAG;KACH,UAAU,OAAO;KACjB,WAAW;IACf,CAAC;IACD,MAAM,QAAQ,MAAM;GACxB;GACA,aAAa,MAAM;GACnB,gBAAgB,MAAM;GACtB,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
@@ -1,14 +1,14 @@
1
+ import { PublicApiTransports } from "../../shared/transports.js";
1
2
  import { PolyesterRequestOptions } from "../../shared/request-options.js";
2
3
  import { SdkScales } from "../../shared/decimal-surface.js";
3
4
  import { GetUnifiedAssetBalancesInput, GetZippedAssetSupplyGroupInput, GetZippedAssetSupplyInput, UnifiedAssetBalancesResponse, ZippedAssetSupplyGroupResponse, ZippedAssetSupplyResponse } from "./chain-analytics.schemas.js";
4
- import { Transport } from "@connectrpc/connect";
5
5
  //#region src/services/chain-analytics/chain-analytics.d.ts
6
6
  /**
7
7
  * Reads public chain analytics chart series.
8
8
  */
9
9
  declare class ChainAnalyticsService {
10
10
  #private;
11
- constructor(transport: Transport, scales: SdkScales);
11
+ constructor(transports: PublicApiTransports, scales: SdkScales);
12
12
  /**
13
13
  * Returns route-scoped zToken supply chart columns for one zipped asset.
14
14
  */
@@ -1 +1 @@
1
- {"version":3,"file":"chain-analytics.d.ts","names":[],"sources":["../../../src/services/chain-analytics/chain-analytics.ts"],"mappings":";;;;;;;;cA0Ba;;EAIG,YAAA,WAAW,WAAW,QAAQ;;;;EAQpC,qBACF,OAAO,2BACP,UAAU,0BACX,QAAQ;;;;EAaL,0BACF,OAAO,gCACP,UAAU,0BACX,QAAQ;;;;EAaL,wBACF,OAAO,8BACP,UAAU,0BACX,QAAQ"}
1
+ {"version":3,"file":"chain-analytics.d.ts","names":[],"sources":["../../../src/services/chain-analytics/chain-analytics.ts"],"mappings":";;;;;;;;cA2Ba;;EAIG,YAAA,YAAY,qBAAqB,QAAQ;;;;EAQ/C,qBACF,OAAO,2BACP,UAAU,0BACX,QAAQ;;;;EAaL,0BACF,OAAO,gCACP,UAAU,0BACX,QAAQ;;;;EAaL,wBACF,OAAO,8BACP,UAAU,0BACX,QAAQ"}
@@ -10,8 +10,8 @@ import { createClient } from "@connectrpc/connect";
10
10
  var ChainAnalyticsService = class {
11
11
  #client;
12
12
  #scales;
13
- constructor(transport, scales) {
14
- this.#client = createClient(ChainAnalyticsService$1, transport);
13
+ constructor(transports, scales) {
14
+ this.#client = createClient(ChainAnalyticsService$1, transports.publicApi);
15
15
  this.#scales = scales;
16
16
  }
17
17
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"chain-analytics.js","names":["#client","Proto.ChainAnalyticsService","#scales"],"sources":["../../../src/services/chain-analytics/chain-analytics.ts"],"sourcesContent":["import * as Proto from \"../../gen/chain/analytics/v1/analytics_read_pb.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport {\n GetUnifiedAssetBalancesInputSchema,\n GetZippedAssetSupplyGroupInputSchema,\n GetZippedAssetSupplyInputSchema,\n createUnifiedAssetBalancesResponseSchema,\n createZippedAssetSupplyGroupResponseSchema,\n createZippedAssetSupplyResponseSchema,\n type GetUnifiedAssetBalancesInput,\n type GetZippedAssetSupplyGroupInput,\n type GetZippedAssetSupplyInput,\n type UnifiedAssetBalancesResponse,\n type ZippedAssetSupplyGroupResponse,\n type ZippedAssetSupplyResponse,\n} from \"./chain-analytics.schemas.js\";\n\n/**\n * Reads public chain analytics chart series.\n */\nexport class ChainAnalyticsService {\n #client: Client<typeof Proto.ChainAnalyticsService>;\n #scales: SdkScales;\n\n constructor(transport: Transport, scales: SdkScales) {\n this.#client = createClient(Proto.ChainAnalyticsService, transport);\n this.#scales = scales;\n }\n\n /**\n * Returns route-scoped zToken supply chart columns for one zipped asset.\n */\n async getZippedAssetSupply(\n input: GetZippedAssetSupplyInput,\n options?: PolyesterRequestOptions,\n ): Promise<ZippedAssetSupplyResponse> {\n const parsedInput = parse(GetZippedAssetSupplyInputSchema, input);\n await this.#scales.ready();\n const response = await this.#client.getZippedAssetSupply(\n parsedInput,\n toConnectCallOptions(options),\n );\n return parse(createZippedAssetSupplyResponseSchema(this.#scales), response);\n }\n\n /**\n * Returns grouped zToken supply chart columns for all zipped assets in one group.\n */\n async getZippedAssetSupplyGroup(\n input: GetZippedAssetSupplyGroupInput,\n options?: PolyesterRequestOptions,\n ): Promise<ZippedAssetSupplyGroupResponse> {\n const parsedInput = parse(GetZippedAssetSupplyGroupInputSchema, input);\n await this.#scales.ready();\n const response = await this.#client.getZippedAssetSupplyGroup(\n parsedInput,\n toConnectCallOptions(options),\n );\n return parse(createZippedAssetSupplyGroupResponseSchema(this.#scales), response);\n }\n\n /**\n * Returns total public unified-asset balance chart columns.\n */\n async getUnifiedAssetBalances(\n input: GetUnifiedAssetBalancesInput,\n options?: PolyesterRequestOptions,\n ): Promise<UnifiedAssetBalancesResponse> {\n const parsedInput = parse(GetUnifiedAssetBalancesInputSchema, input);\n await this.#scales.ready();\n const response = await this.#client.getUnifiedAssetBalances(\n parsedInput,\n toConnectCallOptions(options),\n );\n return parse(createUnifiedAssetBalancesResponseSchema(this.#scales), response);\n }\n}\n"],"mappings":";;;;;;;;;AA0BA,IAAa,wBAAb,MAAmC;CAC/B;CACA;CAEA,YAAY,WAAsB,QAAmB;EACjD,KAAKA,UAAU,aAAaC,yBAA6B,SAAS;EAClE,KAAKC,UAAU;CACnB;;;;CAKA,MAAM,qBACF,OACA,SACkC;EAClC,MAAM,cAAc,MAAM,iCAAiC,KAAK;EAChE,MAAM,KAAKA,QAAQ,MAAM;EACzB,MAAM,WAAW,MAAM,KAAKF,QAAQ,qBAChC,aACA,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,sCAAsC,KAAKE,OAAO,GAAG,QAAQ;CAC9E;;;;CAKA,MAAM,0BACF,OACA,SACuC;EACvC,MAAM,cAAc,MAAM,sCAAsC,KAAK;EACrE,MAAM,KAAKA,QAAQ,MAAM;EACzB,MAAM,WAAW,MAAM,KAAKF,QAAQ,0BAChC,aACA,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,2CAA2C,KAAKE,OAAO,GAAG,QAAQ;CACnF;;;;CAKA,MAAM,wBACF,OACA,SACqC;EACrC,MAAM,cAAc,MAAM,oCAAoC,KAAK;EACnE,MAAM,KAAKA,QAAQ,MAAM;EACzB,MAAM,WAAW,MAAM,KAAKF,QAAQ,wBAChC,aACA,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,yCAAyC,KAAKE,OAAO,GAAG,QAAQ;CACjF;AACJ"}
1
+ {"version":3,"file":"chain-analytics.js","names":["#client","Proto.ChainAnalyticsService","#scales"],"sources":["../../../src/services/chain-analytics/chain-analytics.ts"],"sourcesContent":["import * as Proto from \"../../gen/chain/analytics/v1/analytics_read_pb.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport type { PublicApiTransports } from \"../../shared/transports.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport {\n GetUnifiedAssetBalancesInputSchema,\n GetZippedAssetSupplyGroupInputSchema,\n GetZippedAssetSupplyInputSchema,\n createUnifiedAssetBalancesResponseSchema,\n createZippedAssetSupplyGroupResponseSchema,\n createZippedAssetSupplyResponseSchema,\n type GetUnifiedAssetBalancesInput,\n type GetZippedAssetSupplyGroupInput,\n type GetZippedAssetSupplyInput,\n type UnifiedAssetBalancesResponse,\n type ZippedAssetSupplyGroupResponse,\n type ZippedAssetSupplyResponse,\n} from \"./chain-analytics.schemas.js\";\n\n/**\n * Reads public chain analytics chart series.\n */\nexport class ChainAnalyticsService {\n #client: Client<typeof Proto.ChainAnalyticsService>;\n #scales: SdkScales;\n\n constructor(transports: PublicApiTransports, scales: SdkScales) {\n this.#client = createClient(Proto.ChainAnalyticsService, transports.publicApi);\n this.#scales = scales;\n }\n\n /**\n * Returns route-scoped zToken supply chart columns for one zipped asset.\n */\n async getZippedAssetSupply(\n input: GetZippedAssetSupplyInput,\n options?: PolyesterRequestOptions,\n ): Promise<ZippedAssetSupplyResponse> {\n const parsedInput = parse(GetZippedAssetSupplyInputSchema, input);\n await this.#scales.ready();\n const response = await this.#client.getZippedAssetSupply(\n parsedInput,\n toConnectCallOptions(options),\n );\n return parse(createZippedAssetSupplyResponseSchema(this.#scales), response);\n }\n\n /**\n * Returns grouped zToken supply chart columns for all zipped assets in one group.\n */\n async getZippedAssetSupplyGroup(\n input: GetZippedAssetSupplyGroupInput,\n options?: PolyesterRequestOptions,\n ): Promise<ZippedAssetSupplyGroupResponse> {\n const parsedInput = parse(GetZippedAssetSupplyGroupInputSchema, input);\n await this.#scales.ready();\n const response = await this.#client.getZippedAssetSupplyGroup(\n parsedInput,\n toConnectCallOptions(options),\n );\n return parse(createZippedAssetSupplyGroupResponseSchema(this.#scales), response);\n }\n\n /**\n * Returns total public unified-asset balance chart columns.\n */\n async getUnifiedAssetBalances(\n input: GetUnifiedAssetBalancesInput,\n options?: PolyesterRequestOptions,\n ): Promise<UnifiedAssetBalancesResponse> {\n const parsedInput = parse(GetUnifiedAssetBalancesInputSchema, input);\n await this.#scales.ready();\n const response = await this.#client.getUnifiedAssetBalances(\n parsedInput,\n toConnectCallOptions(options),\n );\n return parse(createUnifiedAssetBalancesResponseSchema(this.#scales), response);\n }\n}\n"],"mappings":";;;;;;;;;AA2BA,IAAa,wBAAb,MAAmC;CAC/B;CACA;CAEA,YAAY,YAAiC,QAAmB;EAC5D,KAAKA,UAAU,aAAaC,yBAA6B,WAAW,SAAS;EAC7E,KAAKC,UAAU;CACnB;;;;CAKA,MAAM,qBACF,OACA,SACkC;EAClC,MAAM,cAAc,MAAM,iCAAiC,KAAK;EAChE,MAAM,KAAKA,QAAQ,MAAM;EACzB,MAAM,WAAW,MAAM,KAAKF,QAAQ,qBAChC,aACA,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,sCAAsC,KAAKE,OAAO,GAAG,QAAQ;CAC9E;;;;CAKA,MAAM,0BACF,OACA,SACuC;EACvC,MAAM,cAAc,MAAM,sCAAsC,KAAK;EACrE,MAAM,KAAKA,QAAQ,MAAM;EACzB,MAAM,WAAW,MAAM,KAAKF,QAAQ,0BAChC,aACA,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,2CAA2C,KAAKE,OAAO,GAAG,QAAQ;CACnF;;;;CAKA,MAAM,wBACF,OACA,SACqC;EACrC,MAAM,cAAc,MAAM,oCAAoC,KAAK;EACnE,MAAM,KAAKA,QAAQ,MAAM;EACzB,MAAM,WAAW,MAAM,KAAKF,QAAQ,wBAChC,aACA,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,yCAAyC,KAAKE,OAAO,GAAG,QAAQ;CACjF;AACJ"}