@outlayer/sdk 0.1.0-alpha.1 → 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -165,7 +165,8 @@ Reusing the same key returns the original result without re-executing.
165
165
  ```ts
166
166
  const client = new OutlayerClient({
167
167
  apiKey: process.env.OUTLAYER_API_KEY!,
168
- baseUrl: 'https://api.outlayer.fastnear.com', // default
168
+ network: 'mainnet', // default; or 'testnet'
169
+ baseUrl: 'https://api.outlayer.fastnear.com', // optional, overrides network
169
170
  fetch: customFetch, // optional, for SSR/proxies
170
171
  retry: {
171
172
  maxAttempts: 5,
@@ -175,6 +176,17 @@ const client = new OutlayerClient({
175
176
  });
176
177
  ```
177
178
 
179
+ ### Testnet vs mainnet
180
+
181
+ `network: 'testnet'` targets `https://api.testnet.outlayer.fastnear.com`. Useful for development without spending real funds.
182
+
183
+ **Important**: NEAR Intents (cross-chain swaps and gasless withdrawals) only work on mainnet. On testnet you can still:
184
+ - register a wallet, derive addresses
185
+ - read balances, set policy, sign messages
186
+ - submit NEAR contract calls
187
+
188
+ …but `swap`, `intentsWithdraw`, and `intentsDeposit` will fail at the intents layer.
189
+
178
190
  ## Browser usage
179
191
 
180
192
  Don't ship your API key to a browser. The key has full wallet authority. Either:
package/dist/index.cjs CHANGED
@@ -94,7 +94,16 @@ async function errorFromResponse(response, parsed) {
94
94
  }
95
95
 
96
96
  // src/http.ts
97
- var DEFAULT_BASE_URL = "https://api.outlayer.fastnear.com";
97
+ var NETWORK_BASE_URLS = {
98
+ mainnet: "https://api.outlayer.fastnear.com",
99
+ testnet: "https://api.testnet.outlayer.fastnear.com"
100
+ };
101
+ var DEFAULT_BASE_URL = NETWORK_BASE_URLS.mainnet;
102
+ function resolveBaseUrl(opts) {
103
+ if (opts.baseUrl) return opts.baseUrl;
104
+ if (opts.network) return NETWORK_BASE_URLS[opts.network];
105
+ return DEFAULT_BASE_URL;
106
+ }
98
107
  var DEFAULT_RETRY = {
99
108
  maxAttempts: 3,
100
109
  initialDelayMs: 100,
@@ -102,7 +111,7 @@ var DEFAULT_RETRY = {
102
111
  };
103
112
  function makeClient(opts) {
104
113
  const init = {
105
- baseUrl: opts.baseUrl ?? DEFAULT_BASE_URL,
114
+ baseUrl: resolveBaseUrl(opts),
106
115
  headers: { Authorization: `Bearer ${opts.apiKey}` }
107
116
  };
108
117
  if (opts.fetch) init.fetch = opts.fetch;
@@ -112,7 +121,7 @@ function makeClient(opts) {
112
121
  }
113
122
  function makeUnauthenticatedClient(opts = {}) {
114
123
  const init = {
115
- baseUrl: opts.baseUrl ?? DEFAULT_BASE_URL
124
+ baseUrl: resolveBaseUrl(opts)
116
125
  };
117
126
  if (opts.fetch) init.fetch = opts.fetch;
118
127
  return createClient__default.default(init);
@@ -377,6 +386,7 @@ var OutlayerClient = class {
377
386
  exports.ApprovalsAPI = ApprovalsAPI;
378
387
  exports.AuditAPI = AuditAPI;
379
388
  exports.BadRequestError = BadRequestError;
389
+ exports.NETWORK_BASE_URLS = NETWORK_BASE_URLS;
380
390
  exports.NotFoundError = NotFoundError;
381
391
  exports.OutlayerClient = OutlayerClient;
382
392
  exports.OutlayerError = OutlayerError;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/client.ts"],"names":["createClient"],"mappings":";;;;;;;;;;;AAkBO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EAC9B,IAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EAET,YAAY,IAAA,EAA4B;AACtC,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,SAAS,IAAA,CAAK,MAAA;AACnB,IAAA,IAAA,CAAK,UAAU,IAAA,CAAK,OAAA;AAAA,EACtB;AACF;AAEO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AkB,cAAc;AAAA,OAC1C,CAAA;AAAA,MACH,IAAA,CAAK;AAAA,KACP;AAAA,EACF;AAAA,EAEA,UAAU,IAAA,EAA+C;AACvD,IAAA,OAAO,YAAA;AAAA,MACL,MAAM,KAAK,MAAA,CAAO,IAAA,CAAK,iCAAiC,EAAE,IAAA,EAAM,MAAM,CAAA;AAAA,MACtE,IAAA,CAAK;AAAA,KACP;AAAA,EACF;AAAA,EAEA,YAAY,IAAA,EAAwD;AAClE,IAAA,OAAO,YAAA;AAAA,MACL,MAAM,KAAK,MAAA,CAAO,IAAA,CAAK,2BAA2B,EAAE,IAAA,EAAM,MAAM,CAAA;AAAA,MAChE,IAAA,CAAK;AAAA,KACP;AAAA,EACF;AAAA;AAAA,EAIA,WAAW,EAAA,EAA4C;AACrD,IAAA,OAAO,YAAA;AAAA,MACL,MAAM,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,0BAAA,EAA4B,EAAE,MAAA,EAAQ,EAAE,IAAA,EAAM,EAAE,EAAA,EAAG,IAAK,CAAA;AAAA,MAC9E,IAAA,CAAK;AAAA,KACP;AAAA,EACF;AAAA,EAEA,YAAA,CACE,IAAA,GAAwF,EAAC,EAC3D;AAC9B,IAAA,OAAO,YAAA;AAAA,MACL,MAAM,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,qBAAA,EAAuB,EAAE,MAAA,EAAQ,EAAE,KAAA,EAAO,IAAA,EAAK,EAAG,CAAA;AAAA,MACxE,IAAA,CAAK;AAAA,KACP;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import type { components } from './types.js';\n\nexport type ApiErrorCode = components['schemas']['ErrorCode'];\nexport type ErrorCode = ApiErrorCode | 'network_error' | 'parse_error';\n\nexport type ErrorBody = {\n error?: ApiErrorCode;\n message?: string;\n details?: unknown;\n};\n\nexport interface OutlayerErrorOptions {\n code: ErrorCode;\n message: string;\n status: number;\n details?: unknown;\n}\n\nexport class OutlayerError extends Error {\n readonly code: ErrorCode;\n readonly status: number;\n readonly details: unknown;\n\n constructor(opts: OutlayerErrorOptions) {\n super(opts.message);\n this.name = 'OutlayerError';\n this.code = opts.code;\n this.status = opts.status;\n this.details = opts.details;\n }\n}\n\nexport class PolicyDeniedError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'PolicyDeniedError';\n }\n}\n\nexport class WalletFrozenError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'WalletFrozenError';\n }\n}\n\nexport class UnauthorizedError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'UnauthorizedError';\n }\n}\n\nexport class RateLimitedError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'RateLimitedError';\n }\n}\n\nexport class NotFoundError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'NotFoundError';\n }\n}\n\nexport class BadRequestError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'BadRequestError';\n }\n}\n\nconst codeToCtor: Partial<Record<ErrorCode, new (opts: OutlayerErrorOptions) => OutlayerError>> = {\n policy_denied: PolicyDeniedError,\n wallet_frozen: WalletFrozenError,\n missing_auth: UnauthorizedError,\n invalid_api_key: UnauthorizedError,\n timestamp_expired: UnauthorizedError,\n rate_limited: RateLimitedError,\n request_not_found: NotFoundError,\n approval_not_found: NotFoundError,\n bad_request: BadRequestError,\n invalid_address: BadRequestError,\n insufficient_balance: BadRequestError,\n unsupported_chain: BadRequestError,\n unsupported_token: BadRequestError,\n};\n\nexport function makeError(body: ErrorBody, status: number): OutlayerError {\n const code: ErrorCode = body.error ?? 'parse_error';\n const message = body.message ?? `HTTP ${status}`;\n const opts: OutlayerErrorOptions = body.details !== undefined\n ? { code, message, status, details: body.details }\n : { code, message, status };\n const Ctor = codeToCtor[code] ?? OutlayerError;\n return new Ctor(opts);\n}\n\nexport async function errorFromResponse(response: Response, parsed?: unknown): Promise<OutlayerError> {\n let body: ErrorBody;\n if (parsed && typeof parsed === 'object') {\n body = parsed as ErrorBody;\n } else {\n try {\n body = (await response.clone().json()) as ErrorBody;\n } catch {\n body = { error: 'internal_error', message: response.statusText };\n }\n }\n return makeError(body, response.status);\n}\n","import createClient, { type Client } from 'openapi-fetch';\nimport type { paths } from './types.js';\nimport { OutlayerError, errorFromResponse } from './errors.js';\n\nexport const DEFAULT_BASE_URL = 'https://api.outlayer.fastnear.com';\n\nexport type RetryConfig = {\n maxAttempts?: number;\n initialDelayMs?: number;\n maxDelayMs?: number;\n};\n\nexport type ClientOptions = {\n apiKey: string;\n baseUrl?: string;\n fetch?: typeof fetch;\n retry?: RetryConfig;\n};\n\nexport type UnauthenticatedOptions = {\n baseUrl?: string;\n fetch?: typeof fetch;\n};\n\nexport const DEFAULT_RETRY: Required<RetryConfig> = {\n maxAttempts: 3,\n initialDelayMs: 100,\n maxDelayMs: 1600,\n};\n\nexport type FetchClient = Client<paths, `${string}/${string}`>;\n\nexport function makeClient(opts: ClientOptions): { client: FetchClient; retry: Required<RetryConfig> } {\n const init: Parameters<typeof createClient<paths>>[0] = {\n baseUrl: opts.baseUrl ?? DEFAULT_BASE_URL,\n headers: { Authorization: `Bearer ${opts.apiKey}` },\n };\n if (opts.fetch) init.fetch = opts.fetch;\n const client = createClient<paths>(init);\n const retry: Required<RetryConfig> = { ...DEFAULT_RETRY, ...opts.retry };\n return { client, retry };\n}\n\nexport function makeUnauthenticatedClient(opts: UnauthenticatedOptions = {}): FetchClient {\n const init: Parameters<typeof createClient<paths>>[0] = {\n baseUrl: opts.baseUrl ?? DEFAULT_BASE_URL,\n };\n if (opts.fetch) init.fetch = opts.fetch;\n return createClient<paths>(init);\n}\n\nexport type FetchCall<T> = () => Promise<{\n data?: T;\n error?: unknown;\n response: Response;\n}>;\n\nexport async function runWithRetry<T>(\n call: FetchCall<T>,\n retry: Required<RetryConfig>,\n): Promise<T> {\n let lastError: unknown;\n for (let attempt = 1; attempt <= retry.maxAttempts; attempt++) {\n try {\n const { data, error, response } = await call();\n if (response.ok) {\n return data as T;\n }\n const err = await errorFromResponse(response, error);\n if (err.status >= 500 && attempt < retry.maxAttempts) {\n lastError = err;\n await sleep(backoff(attempt, retry));\n continue;\n }\n throw err;\n } catch (e) {\n if (e instanceof OutlayerError) throw e;\n lastError = e;\n if (attempt < retry.maxAttempts && isNetworkError(e)) {\n await sleep(backoff(attempt, retry));\n continue;\n }\n throw new OutlayerError({\n code: 'network_error',\n message: e instanceof Error ? e.message : String(e),\n status: 0,\n });\n }\n }\n throw lastError;\n}\n\nfunction backoff(attempt: number, cfg: Required<RetryConfig>): number {\n return Math.min(cfg.maxDelayMs, cfg.initialDelayMs * 2 ** (attempt - 1));\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((r) => setTimeout(r, ms));\n}\n\nfunction isNetworkError(e: unknown): boolean {\n return e instanceof TypeError;\n}\n\nexport function newIdempotencyKey(): string {\n return crypto.randomUUID();\n}\n","import type { components } from './types.js';\nimport {\n type ClientOptions,\n type FetchClient,\n type RetryConfig,\n type UnauthenticatedOptions,\n DEFAULT_RETRY,\n makeClient,\n makeUnauthenticatedClient,\n newIdempotencyKey,\n runWithRetry,\n} from './http.js';\nimport { errorFromResponse } from './errors.js';\n\ntype Schemas = components['schemas'];\n\n// ---------------------------------------------------------------------------\n// Re-exported user-facing types (so consumers don't import paths/components)\n// ---------------------------------------------------------------------------\n\nexport type Chain = Schemas['Chain'];\nexport type RequestType = Schemas['RequestType'];\nexport type RequestStatus = Schemas['RequestStatus'];\n\nexport type RegisterRequest = Schemas['RegisterRequest'];\nexport type RegisterResponse = Schemas['RegisterResponse'];\nexport type AddressResponse = Schemas['AddressResponse'];\nexport type BalanceResponse = Schemas['BalanceResponse'];\nexport type TokensResponse = Schemas['TokensResponse'];\n\nexport type CallRequest = Schemas['CallRequest'];\nexport type CallResponse = Schemas['CallResponse'];\nexport type TransferRequest = Schemas['TransferRequest'];\nexport type IntentsDepositRequest = Schemas['IntentsDepositRequest'];\nexport type IntentsDepositResponse = Schemas['IntentsDepositResponse'];\n\nexport type WithdrawRequest = Schemas['WithdrawRequest'];\nexport type WithdrawResponse = Schemas['WithdrawResponse'];\nexport type DryRunResponse = Schemas['DryRunResponse'];\n\nexport type SwapRequest = Schemas['SwapRequest'];\nexport type SwapResponse = Schemas['SwapResponse'];\nexport type SwapQuoteResponse = Schemas['SwapQuoteResponse'];\n\nexport type SignMessageRequest = Schemas['SignMessageRequest'];\nexport type SignMessageResponse = Schemas['SignMessageResponse'];\n\nexport type RequestStatusResponse = Schemas['RequestStatusResponse'];\nexport type RequestListResponse = Schemas['RequestListResponse'];\n\nexport type PolicyResponse = Schemas['PolicyResponse'];\nexport type PolicyRules = Schemas['PolicyRules'];\nexport type ApprovalConfig = Schemas['ApprovalConfig'];\nexport type EncryptPolicyRequest = Schemas['EncryptPolicyRequest'];\nexport type EncryptPolicyResponse = Schemas['EncryptPolicyResponse'];\nexport type SignPolicyResponse = Schemas['SignPolicyResponse'];\n\nexport type PendingApproval = Schemas['PendingApproval'];\nexport type PendingApprovalsResponse = Schemas['PendingApprovalsResponse'];\nexport type Nep413Auth = Schemas['Nep413Auth'];\nexport type ApproveResponse = Schemas['ApproveResponse'];\n\nexport type AuditEvent = Schemas['AuditEvent'];\nexport type AuditResponse = Schemas['AuditResponse'];\n\n// ---------------------------------------------------------------------------\n// Shared helpers\n// ---------------------------------------------------------------------------\n\ntype Idempotent = { idempotencyKey?: string };\n\nfunction idempotencyHeader(key: string | undefined): Record<string, string> {\n return { 'Idempotency-Key': key ?? newIdempotencyKey() };\n}\n\n// ---------------------------------------------------------------------------\n// Sub-namespaces\n// ---------------------------------------------------------------------------\n\nexport class PolicyAPI {\n constructor(\n private readonly client: FetchClient,\n private readonly retry: Required<RetryConfig>,\n ) {}\n\n get(): Promise<PolicyResponse> {\n return runWithRetry(() => this.client.GET('/wallet/v1/policy'), this.retry);\n }\n\n encrypt(body: EncryptPolicyRequest): Promise<EncryptPolicyResponse> {\n return runWithRetry(() => this.client.POST('/wallet/v1/encrypt-policy', { body }), this.retry);\n }\n\n sign(encryptedData: string): Promise<SignPolicyResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/sign-policy', { body: { encrypted_data: encryptedData } }),\n this.retry,\n );\n }\n\n invalidateCache(walletId: string): Promise<void> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/invalidate-cache', { body: { wallet_id: walletId } }),\n this.retry,\n ).then(() => undefined);\n }\n}\n\nexport class ApprovalsAPI {\n constructor(\n private readonly client: FetchClient,\n private readonly retry: Required<RetryConfig>,\n ) {}\n\n listPending(): Promise<PendingApprovalsResponse> {\n return runWithRetry(() => this.client.GET('/wallet/v1/pending_approvals'), this.retry);\n }\n\n approve(approvalId: string, auth: Nep413Auth): Promise<ApproveResponse> {\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/approve/{id}', {\n params: { path: { id: approvalId } },\n body: auth,\n }),\n this.retry,\n );\n }\n\n reject(approvalId: string, auth: Nep413Auth, reason?: string): Promise<ApproveResponse> {\n const body = reason !== undefined ? { ...auth, reason } : auth;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/reject/{id}', {\n params: { path: { id: approvalId } },\n body,\n }),\n this.retry,\n );\n }\n}\n\nexport class AuditAPI {\n constructor(\n private readonly client: FetchClient,\n private readonly retry: Required<RetryConfig>,\n ) {}\n\n list(opts: { limit?: number; offset?: number } = {}): Promise<AuditResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/audit', { params: { query: opts } }),\n this.retry,\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Main client\n// ---------------------------------------------------------------------------\n\nexport class OutlayerClient {\n private readonly client: FetchClient;\n private readonly retry: Required<RetryConfig>;\n\n readonly policy: PolicyAPI;\n readonly approvals: ApprovalsAPI;\n readonly audit: AuditAPI;\n\n constructor(opts: ClientOptions) {\n const { client, retry } = makeClient(opts);\n this.client = client;\n this.retry = retry;\n this.policy = new PolicyAPI(client, retry);\n this.approvals = new ApprovalsAPI(client, retry);\n this.audit = new AuditAPI(client, retry);\n }\n\n // ------- Static factory: register a new wallet (no auth) -------\n\n /**\n * Register a new wallet and obtain an API key.\n *\n * - Empty call: anonymous wallet on OutLayer's shared master. Convenient, no setup.\n * - With `vaultId`: bind to a deployed customer vault so keys derive through\n * the per-vault master. Vault binding is permanent.\n * - With `body`: full control — pass any `RegisterRequest` field (e.g., NEP-413\n * account-binding fields). `vaultId` is merged into `body.vault_id` if not\n * already set.\n *\n * Vault deployment is NOT done here — use the dashboard\n * (https://outlayer.fastnear.com/vault) or `outlayer vault init` CLI.\n * See docs/vaults.md for the full flow.\n */\n static async register(\n opts: {\n vaultId?: string;\n body?: RegisterRequest;\n } & UnauthenticatedOptions = {},\n ): Promise<RegisterResponse> {\n const client = makeUnauthenticatedClient(opts);\n const body: RegisterRequest = { ...(opts.body ?? {}) };\n if (opts.vaultId !== undefined && body.vault_id === undefined) {\n body.vault_id = opts.vaultId;\n }\n const { data, error, response } = await client.POST('/register', { body });\n if (!response.ok) throw await errorFromResponse(response, error);\n return data as RegisterResponse;\n }\n\n // ------- Wallet read -------\n\n getAddress(chain: Chain): Promise<AddressResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/address', { params: { query: { chain } } }),\n this.retry,\n );\n }\n\n getBalance(\n opts: { chain?: Chain; token?: string; source?: 'chain' | 'intents' } = {},\n ): Promise<BalanceResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/balance', { params: { query: opts } }),\n this.retry,\n );\n }\n\n listTokens(): Promise<TokensResponse> {\n return runWithRetry(() => this.client.GET('/wallet/v1/tokens'), this.retry);\n }\n\n // ------- Wallet write -------\n\n call(opts: CallRequest & Idempotent): Promise<CallResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/call', {\n body: body as CallRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n transfer(opts: TransferRequest & Idempotent): Promise<CallResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/transfer', {\n body: body as TransferRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n intentsDeposit(opts: IntentsDepositRequest & Idempotent): Promise<IntentsDepositResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/intents/deposit', {\n body: body as IntentsDepositRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n withdraw(opts: WithdrawRequest & Idempotent): Promise<WithdrawResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/intents/withdraw', {\n body: body as WithdrawRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n withdrawDryRun(opts: WithdrawRequest): Promise<DryRunResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/intents/withdraw/dry-run', { body: opts }),\n this.retry,\n );\n }\n\n swap(opts: SwapRequest & Idempotent): Promise<SwapResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/intents/swap', {\n body: body as SwapRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n swapQuote(opts: SwapRequest): Promise<SwapQuoteResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/intents/swap/quote', { body: opts }),\n this.retry,\n );\n }\n\n signMessage(opts: SignMessageRequest): Promise<SignMessageResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/sign-message', { body: opts }),\n this.retry,\n );\n }\n\n // ------- Async request tracking -------\n\n getRequest(id: string): Promise<RequestStatusResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/requests/{id}', { params: { path: { id } } }),\n this.retry,\n );\n }\n\n listRequests(\n opts: { type?: RequestType; status?: RequestStatus; limit?: number; offset?: number } = {},\n ): Promise<RequestListResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/requests', { params: { query: opts } }),\n this.retry,\n );\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/client.ts"],"names":["createClient"],"mappings":";;;;;;;;;;;AAkBO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EAC9B,IAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EAET,YAAY,IAAA,EAA4B;AACtC,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,SAAS,IAAA,CAAK,MAAA;AACnB,IAAA,IAAA,CAAK,UAAU,IAAA,CAAK,OAAA;AAAA,EACtB;AACF;AAEO,IAAM,iBAAA,GAAN,cAAgC,aAAA,CAAc;AAAA,EACnD,YAAY,IAAA,EAA4B;AACtC,IAAA,KAAA,CAAM,IAAI,CAAA;AACV,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AAAA,EACd;AACF;AAEO,IAAM,iBAAA,GAAN,cAAgC,aAAA,CAAc;AAAA,EACnD,YAAY,IAAA,EAA4B;AACtC,IAAA,KAAA,CAAM,IAAI,CAAA;AACV,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AAAA,EACd;AACF;AAEO,IAAM,iBAAA,GAAN,cAAgC,aAAA,CAAc;AAAA,EACnD,YAAY,IAAA,EAA4B;AACtC,IAAA,KAAA,CAAM,IAAI,CAAA;AACV,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AAAA,EACd;AACF;AAEO,IAAM,gBAAA,GAAN,cAA+B,aAAA,CAAc;AAAA,EAClD,YAAY,IAAA,EAA4B;AACtC,IAAA,KAAA,CAAM,IAAI,CAAA;AACV,IAAA,IAAA,CAAK,IAAA,GAAO,kBAAA;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A2B,EAAE,IAAA,EAAM,MAAM,CAAA;AAAA,MAChE,IAAA,CAAK;AAAA,KACP;AAAA,EACF;AAAA;AAAA,EAIA,WAAW,EAAA,EAA4C;AACrD,IAAA,OAAO,YAAA;AAAA,MACL,MAAM,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,0BAAA,EAA4B,EAAE,MAAA,EAAQ,EAAE,IAAA,EAAM,EAAE,EAAA,EAAG,IAAK,CAAA;AAAA,MAC9E,IAAA,CAAK;AAAA,KACP;AAAA,EACF;AAAA,EAEA,YAAA,CACE,IAAA,GAAwF,EAAC,EAC3D;AAC9B,IAAA,OAAO,YAAA;AAAA,MACL,MAAM,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,qBAAA,EAAuB,EAAE,MAAA,EAAQ,EAAE,KAAA,EAAO,IAAA,EAAK,EAAG,CAAA;AAAA,MACxE,IAAA,CAAK;AAAA,KACP;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import type { components } from './types.js';\n\nexport type ApiErrorCode = components['schemas']['ErrorCode'];\nexport type ErrorCode = ApiErrorCode | 'network_error' | 'parse_error';\n\nexport type ErrorBody = {\n error?: ApiErrorCode;\n message?: string;\n details?: unknown;\n};\n\nexport interface OutlayerErrorOptions {\n code: ErrorCode;\n message: string;\n status: number;\n details?: unknown;\n}\n\nexport class OutlayerError extends Error {\n readonly code: ErrorCode;\n readonly status: number;\n readonly details: unknown;\n\n constructor(opts: OutlayerErrorOptions) {\n super(opts.message);\n this.name = 'OutlayerError';\n this.code = opts.code;\n this.status = opts.status;\n this.details = opts.details;\n }\n}\n\nexport class PolicyDeniedError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'PolicyDeniedError';\n }\n}\n\nexport class WalletFrozenError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'WalletFrozenError';\n }\n}\n\nexport class UnauthorizedError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'UnauthorizedError';\n }\n}\n\nexport class RateLimitedError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'RateLimitedError';\n }\n}\n\nexport class NotFoundError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'NotFoundError';\n }\n}\n\nexport class BadRequestError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'BadRequestError';\n }\n}\n\nconst codeToCtor: Partial<Record<ErrorCode, new (opts: OutlayerErrorOptions) => OutlayerError>> = {\n policy_denied: PolicyDeniedError,\n wallet_frozen: WalletFrozenError,\n missing_auth: UnauthorizedError,\n invalid_api_key: UnauthorizedError,\n timestamp_expired: UnauthorizedError,\n rate_limited: RateLimitedError,\n request_not_found: NotFoundError,\n approval_not_found: NotFoundError,\n bad_request: BadRequestError,\n invalid_address: BadRequestError,\n insufficient_balance: BadRequestError,\n unsupported_chain: BadRequestError,\n unsupported_token: BadRequestError,\n};\n\nexport function makeError(body: ErrorBody, status: number): OutlayerError {\n const code: ErrorCode = body.error ?? 'parse_error';\n const message = body.message ?? `HTTP ${status}`;\n const opts: OutlayerErrorOptions = body.details !== undefined\n ? { code, message, status, details: body.details }\n : { code, message, status };\n const Ctor = codeToCtor[code] ?? OutlayerError;\n return new Ctor(opts);\n}\n\nexport async function errorFromResponse(response: Response, parsed?: unknown): Promise<OutlayerError> {\n let body: ErrorBody;\n if (parsed && typeof parsed === 'object') {\n body = parsed as ErrorBody;\n } else {\n try {\n body = (await response.clone().json()) as ErrorBody;\n } catch {\n body = { error: 'internal_error', message: response.statusText };\n }\n }\n return makeError(body, response.status);\n}\n","import createClient, { type Client } from 'openapi-fetch';\nimport type { paths } from './types.js';\nimport { OutlayerError, errorFromResponse } from './errors.js';\n\nexport type Network = 'mainnet' | 'testnet';\n\nexport const NETWORK_BASE_URLS: Record<Network, string> = {\n mainnet: 'https://api.outlayer.fastnear.com',\n testnet: 'https://api.testnet.outlayer.fastnear.com',\n};\n\nexport const DEFAULT_BASE_URL = NETWORK_BASE_URLS.mainnet;\n\nexport type RetryConfig = {\n maxAttempts?: number;\n initialDelayMs?: number;\n maxDelayMs?: number;\n};\n\nexport type ClientOptions = {\n apiKey: string;\n /**\n * NEAR network to target. Defaults to `mainnet`. NEAR Intents (cross-chain\n * swaps + gasless withdrawals) only work on mainnet — use testnet for the\n * register / policy / sign-message flow while developing.\n */\n network?: Network;\n /** Overrides `network` for self-hosted or staging deployments. */\n baseUrl?: string;\n fetch?: typeof fetch;\n retry?: RetryConfig;\n};\n\nexport type UnauthenticatedOptions = {\n network?: Network;\n baseUrl?: string;\n fetch?: typeof fetch;\n};\n\nfunction resolveBaseUrl(opts: { network?: Network; baseUrl?: string }): string {\n if (opts.baseUrl) return opts.baseUrl;\n if (opts.network) return NETWORK_BASE_URLS[opts.network];\n return DEFAULT_BASE_URL;\n}\n\nexport const DEFAULT_RETRY: Required<RetryConfig> = {\n maxAttempts: 3,\n initialDelayMs: 100,\n maxDelayMs: 1600,\n};\n\nexport type FetchClient = Client<paths, `${string}/${string}`>;\n\nexport function makeClient(opts: ClientOptions): { client: FetchClient; retry: Required<RetryConfig> } {\n const init: Parameters<typeof createClient<paths>>[0] = {\n baseUrl: resolveBaseUrl(opts),\n headers: { Authorization: `Bearer ${opts.apiKey}` },\n };\n if (opts.fetch) init.fetch = opts.fetch;\n const client = createClient<paths>(init);\n const retry: Required<RetryConfig> = { ...DEFAULT_RETRY, ...opts.retry };\n return { client, retry };\n}\n\nexport function makeUnauthenticatedClient(opts: UnauthenticatedOptions = {}): FetchClient {\n const init: Parameters<typeof createClient<paths>>[0] = {\n baseUrl: resolveBaseUrl(opts),\n };\n if (opts.fetch) init.fetch = opts.fetch;\n return createClient<paths>(init);\n}\n\nexport type FetchCall<T> = () => Promise<{\n data?: T;\n error?: unknown;\n response: Response;\n}>;\n\nexport async function runWithRetry<T>(\n call: FetchCall<T>,\n retry: Required<RetryConfig>,\n): Promise<T> {\n let lastError: unknown;\n for (let attempt = 1; attempt <= retry.maxAttempts; attempt++) {\n try {\n const { data, error, response } = await call();\n if (response.ok) {\n return data as T;\n }\n const err = await errorFromResponse(response, error);\n if (err.status >= 500 && attempt < retry.maxAttempts) {\n lastError = err;\n await sleep(backoff(attempt, retry));\n continue;\n }\n throw err;\n } catch (e) {\n if (e instanceof OutlayerError) throw e;\n lastError = e;\n if (attempt < retry.maxAttempts && isNetworkError(e)) {\n await sleep(backoff(attempt, retry));\n continue;\n }\n throw new OutlayerError({\n code: 'network_error',\n message: e instanceof Error ? e.message : String(e),\n status: 0,\n });\n }\n }\n throw lastError;\n}\n\nfunction backoff(attempt: number, cfg: Required<RetryConfig>): number {\n return Math.min(cfg.maxDelayMs, cfg.initialDelayMs * 2 ** (attempt - 1));\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((r) => setTimeout(r, ms));\n}\n\nfunction isNetworkError(e: unknown): boolean {\n return e instanceof TypeError;\n}\n\nexport function newIdempotencyKey(): string {\n return crypto.randomUUID();\n}\n","import type { components } from './types.js';\nimport {\n type ClientOptions,\n type FetchClient,\n type RetryConfig,\n type UnauthenticatedOptions,\n DEFAULT_RETRY,\n makeClient,\n makeUnauthenticatedClient,\n newIdempotencyKey,\n runWithRetry,\n} from './http.js';\nimport { errorFromResponse } from './errors.js';\n\ntype Schemas = components['schemas'];\n\n// ---------------------------------------------------------------------------\n// Re-exported user-facing types (so consumers don't import paths/components)\n// ---------------------------------------------------------------------------\n\nexport type Chain = Schemas['Chain'];\nexport type RequestType = Schemas['RequestType'];\nexport type RequestStatus = Schemas['RequestStatus'];\n\nexport type RegisterRequest = Schemas['RegisterRequest'];\nexport type RegisterResponse = Schemas['RegisterResponse'];\nexport type AddressResponse = Schemas['AddressResponse'];\nexport type BalanceResponse = Schemas['BalanceResponse'];\nexport type TokensResponse = Schemas['TokensResponse'];\n\nexport type CallRequest = Schemas['CallRequest'];\nexport type CallResponse = Schemas['CallResponse'];\nexport type TransferRequest = Schemas['TransferRequest'];\nexport type IntentsDepositRequest = Schemas['IntentsDepositRequest'];\nexport type IntentsDepositResponse = Schemas['IntentsDepositResponse'];\n\nexport type WithdrawRequest = Schemas['WithdrawRequest'];\nexport type WithdrawResponse = Schemas['WithdrawResponse'];\nexport type DryRunResponse = Schemas['DryRunResponse'];\n\nexport type SwapRequest = Schemas['SwapRequest'];\nexport type SwapResponse = Schemas['SwapResponse'];\nexport type SwapQuoteResponse = Schemas['SwapQuoteResponse'];\n\nexport type SignMessageRequest = Schemas['SignMessageRequest'];\nexport type SignMessageResponse = Schemas['SignMessageResponse'];\n\nexport type RequestStatusResponse = Schemas['RequestStatusResponse'];\nexport type RequestListResponse = Schemas['RequestListResponse'];\n\nexport type PolicyResponse = Schemas['PolicyResponse'];\nexport type PolicyRules = Schemas['PolicyRules'];\nexport type ApprovalConfig = Schemas['ApprovalConfig'];\nexport type EncryptPolicyRequest = Schemas['EncryptPolicyRequest'];\nexport type EncryptPolicyResponse = Schemas['EncryptPolicyResponse'];\nexport type SignPolicyResponse = Schemas['SignPolicyResponse'];\n\nexport type PendingApproval = Schemas['PendingApproval'];\nexport type PendingApprovalsResponse = Schemas['PendingApprovalsResponse'];\nexport type Nep413Auth = Schemas['Nep413Auth'];\nexport type ApproveResponse = Schemas['ApproveResponse'];\n\nexport type AuditEvent = Schemas['AuditEvent'];\nexport type AuditResponse = Schemas['AuditResponse'];\n\n// ---------------------------------------------------------------------------\n// Shared helpers\n// ---------------------------------------------------------------------------\n\ntype Idempotent = { idempotencyKey?: string };\n\nfunction idempotencyHeader(key: string | undefined): Record<string, string> {\n return { 'Idempotency-Key': key ?? newIdempotencyKey() };\n}\n\n// ---------------------------------------------------------------------------\n// Sub-namespaces\n// ---------------------------------------------------------------------------\n\nexport class PolicyAPI {\n constructor(\n private readonly client: FetchClient,\n private readonly retry: Required<RetryConfig>,\n ) {}\n\n get(): Promise<PolicyResponse> {\n return runWithRetry(() => this.client.GET('/wallet/v1/policy'), this.retry);\n }\n\n encrypt(body: EncryptPolicyRequest): Promise<EncryptPolicyResponse> {\n return runWithRetry(() => this.client.POST('/wallet/v1/encrypt-policy', { body }), this.retry);\n }\n\n sign(encryptedData: string): Promise<SignPolicyResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/sign-policy', { body: { encrypted_data: encryptedData } }),\n this.retry,\n );\n }\n\n invalidateCache(walletId: string): Promise<void> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/invalidate-cache', { body: { wallet_id: walletId } }),\n this.retry,\n ).then(() => undefined);\n }\n}\n\nexport class ApprovalsAPI {\n constructor(\n private readonly client: FetchClient,\n private readonly retry: Required<RetryConfig>,\n ) {}\n\n listPending(): Promise<PendingApprovalsResponse> {\n return runWithRetry(() => this.client.GET('/wallet/v1/pending_approvals'), this.retry);\n }\n\n approve(approvalId: string, auth: Nep413Auth): Promise<ApproveResponse> {\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/approve/{id}', {\n params: { path: { id: approvalId } },\n body: auth,\n }),\n this.retry,\n );\n }\n\n reject(approvalId: string, auth: Nep413Auth, reason?: string): Promise<ApproveResponse> {\n const body = reason !== undefined ? { ...auth, reason } : auth;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/reject/{id}', {\n params: { path: { id: approvalId } },\n body,\n }),\n this.retry,\n );\n }\n}\n\nexport class AuditAPI {\n constructor(\n private readonly client: FetchClient,\n private readonly retry: Required<RetryConfig>,\n ) {}\n\n list(opts: { limit?: number; offset?: number } = {}): Promise<AuditResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/audit', { params: { query: opts } }),\n this.retry,\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Main client\n// ---------------------------------------------------------------------------\n\nexport class OutlayerClient {\n private readonly client: FetchClient;\n private readonly retry: Required<RetryConfig>;\n\n readonly policy: PolicyAPI;\n readonly approvals: ApprovalsAPI;\n readonly audit: AuditAPI;\n\n constructor(opts: ClientOptions) {\n const { client, retry } = makeClient(opts);\n this.client = client;\n this.retry = retry;\n this.policy = new PolicyAPI(client, retry);\n this.approvals = new ApprovalsAPI(client, retry);\n this.audit = new AuditAPI(client, retry);\n }\n\n // ------- Static factory: register a new wallet (no auth) -------\n\n /**\n * Register a new wallet and obtain an API key.\n *\n * - Empty call: anonymous wallet on OutLayer's shared master. Convenient, no setup.\n * - With `vaultId`: bind to a deployed customer vault so keys derive through\n * the per-vault master. Vault binding is permanent.\n * - With `body`: full control — pass any `RegisterRequest` field (e.g., NEP-413\n * account-binding fields). `vaultId` is merged into `body.vault_id` if not\n * already set.\n *\n * Vault deployment is NOT done here — use the dashboard\n * (https://outlayer.fastnear.com/vault) or `outlayer vault init` CLI.\n * See docs/vaults.md for the full flow.\n */\n static async register(\n opts: {\n vaultId?: string;\n body?: RegisterRequest;\n } & UnauthenticatedOptions = {},\n ): Promise<RegisterResponse> {\n const client = makeUnauthenticatedClient(opts);\n const body: RegisterRequest = { ...(opts.body ?? {}) };\n if (opts.vaultId !== undefined && body.vault_id === undefined) {\n body.vault_id = opts.vaultId;\n }\n const { data, error, response } = await client.POST('/register', { body });\n if (!response.ok) throw await errorFromResponse(response, error);\n return data as RegisterResponse;\n }\n\n // ------- Wallet read -------\n\n getAddress(chain: Chain): Promise<AddressResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/address', { params: { query: { chain } } }),\n this.retry,\n );\n }\n\n getBalance(\n opts: { chain?: Chain; token?: string; source?: 'chain' | 'intents' } = {},\n ): Promise<BalanceResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/balance', { params: { query: opts } }),\n this.retry,\n );\n }\n\n listTokens(): Promise<TokensResponse> {\n return runWithRetry(() => this.client.GET('/wallet/v1/tokens'), this.retry);\n }\n\n // ------- Wallet write -------\n\n call(opts: CallRequest & Idempotent): Promise<CallResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/call', {\n body: body as CallRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n transfer(opts: TransferRequest & Idempotent): Promise<CallResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/transfer', {\n body: body as TransferRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n intentsDeposit(opts: IntentsDepositRequest & Idempotent): Promise<IntentsDepositResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/intents/deposit', {\n body: body as IntentsDepositRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n withdraw(opts: WithdrawRequest & Idempotent): Promise<WithdrawResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/intents/withdraw', {\n body: body as WithdrawRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n withdrawDryRun(opts: WithdrawRequest): Promise<DryRunResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/intents/withdraw/dry-run', { body: opts }),\n this.retry,\n );\n }\n\n swap(opts: SwapRequest & Idempotent): Promise<SwapResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/intents/swap', {\n body: body as SwapRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n swapQuote(opts: SwapRequest): Promise<SwapQuoteResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/intents/swap/quote', { body: opts }),\n this.retry,\n );\n }\n\n signMessage(opts: SignMessageRequest): Promise<SignMessageResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/sign-message', { body: opts }),\n this.retry,\n );\n }\n\n // ------- Async request tracking -------\n\n getRequest(id: string): Promise<RequestStatusResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/requests/{id}', { params: { path: { id } } }),\n this.retry,\n );\n }\n\n listRequests(\n opts: { type?: RequestType; status?: RequestStatus; limit?: number; offset?: number } = {},\n ): Promise<RequestListResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/requests', { params: { query: opts } }),\n this.retry,\n );\n }\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -1621,6 +1621,8 @@ interface operations {
1621
1621
  };
1622
1622
  }
1623
1623
 
1624
+ type Network = 'mainnet' | 'testnet';
1625
+ declare const NETWORK_BASE_URLS: Record<Network, string>;
1624
1626
  type RetryConfig = {
1625
1627
  maxAttempts?: number;
1626
1628
  initialDelayMs?: number;
@@ -1628,11 +1630,19 @@ type RetryConfig = {
1628
1630
  };
1629
1631
  type ClientOptions = {
1630
1632
  apiKey: string;
1633
+ /**
1634
+ * NEAR network to target. Defaults to `mainnet`. NEAR Intents (cross-chain
1635
+ * swaps + gasless withdrawals) only work on mainnet — use testnet for the
1636
+ * register / policy / sign-message flow while developing.
1637
+ */
1638
+ network?: Network;
1639
+ /** Overrides `network` for self-hosted or staging deployments. */
1631
1640
  baseUrl?: string;
1632
1641
  fetch?: typeof fetch;
1633
1642
  retry?: RetryConfig;
1634
1643
  };
1635
1644
  type UnauthenticatedOptions = {
1645
+ network?: Network;
1636
1646
  baseUrl?: string;
1637
1647
  fetch?: typeof fetch;
1638
1648
  };
@@ -1785,4 +1795,4 @@ declare class BadRequestError extends OutlayerError {
1785
1795
  constructor(opts: OutlayerErrorOptions);
1786
1796
  }
1787
1797
 
1788
- export { type AddressResponse, type ApiErrorCode, type ApprovalConfig, ApprovalsAPI, type ApproveResponse, AuditAPI, type AuditEvent, type AuditResponse, BadRequestError, type BalanceResponse, type CallRequest, type CallResponse, type Chain, type ClientOptions, type DryRunResponse, type EncryptPolicyRequest, type EncryptPolicyResponse, type ErrorCode, type IntentsDepositRequest, type IntentsDepositResponse, type Nep413Auth, NotFoundError, OutlayerClient, OutlayerError, type PendingApproval, type PendingApprovalsResponse, PolicyAPI, PolicyDeniedError, type PolicyResponse, type PolicyRules, RateLimitedError, type RegisterRequest, type RegisterResponse, type RequestListResponse, type RequestStatus, type RequestStatusResponse, type RequestType, type RetryConfig, type SignMessageRequest, type SignMessageResponse, type SignPolicyResponse, type SwapQuoteResponse, type SwapRequest, type SwapResponse, type TokensResponse, type TransferRequest, type UnauthenticatedOptions, UnauthorizedError, WalletFrozenError, type WithdrawRequest, type WithdrawResponse };
1798
+ export { type AddressResponse, type ApiErrorCode, type ApprovalConfig, ApprovalsAPI, type ApproveResponse, AuditAPI, type AuditEvent, type AuditResponse, BadRequestError, type BalanceResponse, type CallRequest, type CallResponse, type Chain, type ClientOptions, type DryRunResponse, type EncryptPolicyRequest, type EncryptPolicyResponse, type ErrorCode, type IntentsDepositRequest, type IntentsDepositResponse, NETWORK_BASE_URLS, type Nep413Auth, type Network, NotFoundError, OutlayerClient, OutlayerError, type PendingApproval, type PendingApprovalsResponse, PolicyAPI, PolicyDeniedError, type PolicyResponse, type PolicyRules, RateLimitedError, type RegisterRequest, type RegisterResponse, type RequestListResponse, type RequestStatus, type RequestStatusResponse, type RequestType, type RetryConfig, type SignMessageRequest, type SignMessageResponse, type SignPolicyResponse, type SwapQuoteResponse, type SwapRequest, type SwapResponse, type TokensResponse, type TransferRequest, type UnauthenticatedOptions, UnauthorizedError, WalletFrozenError, type WithdrawRequest, type WithdrawResponse };
package/dist/index.d.ts CHANGED
@@ -1621,6 +1621,8 @@ interface operations {
1621
1621
  };
1622
1622
  }
1623
1623
 
1624
+ type Network = 'mainnet' | 'testnet';
1625
+ declare const NETWORK_BASE_URLS: Record<Network, string>;
1624
1626
  type RetryConfig = {
1625
1627
  maxAttempts?: number;
1626
1628
  initialDelayMs?: number;
@@ -1628,11 +1630,19 @@ type RetryConfig = {
1628
1630
  };
1629
1631
  type ClientOptions = {
1630
1632
  apiKey: string;
1633
+ /**
1634
+ * NEAR network to target. Defaults to `mainnet`. NEAR Intents (cross-chain
1635
+ * swaps + gasless withdrawals) only work on mainnet — use testnet for the
1636
+ * register / policy / sign-message flow while developing.
1637
+ */
1638
+ network?: Network;
1639
+ /** Overrides `network` for self-hosted or staging deployments. */
1631
1640
  baseUrl?: string;
1632
1641
  fetch?: typeof fetch;
1633
1642
  retry?: RetryConfig;
1634
1643
  };
1635
1644
  type UnauthenticatedOptions = {
1645
+ network?: Network;
1636
1646
  baseUrl?: string;
1637
1647
  fetch?: typeof fetch;
1638
1648
  };
@@ -1785,4 +1795,4 @@ declare class BadRequestError extends OutlayerError {
1785
1795
  constructor(opts: OutlayerErrorOptions);
1786
1796
  }
1787
1797
 
1788
- export { type AddressResponse, type ApiErrorCode, type ApprovalConfig, ApprovalsAPI, type ApproveResponse, AuditAPI, type AuditEvent, type AuditResponse, BadRequestError, type BalanceResponse, type CallRequest, type CallResponse, type Chain, type ClientOptions, type DryRunResponse, type EncryptPolicyRequest, type EncryptPolicyResponse, type ErrorCode, type IntentsDepositRequest, type IntentsDepositResponse, type Nep413Auth, NotFoundError, OutlayerClient, OutlayerError, type PendingApproval, type PendingApprovalsResponse, PolicyAPI, PolicyDeniedError, type PolicyResponse, type PolicyRules, RateLimitedError, type RegisterRequest, type RegisterResponse, type RequestListResponse, type RequestStatus, type RequestStatusResponse, type RequestType, type RetryConfig, type SignMessageRequest, type SignMessageResponse, type SignPolicyResponse, type SwapQuoteResponse, type SwapRequest, type SwapResponse, type TokensResponse, type TransferRequest, type UnauthenticatedOptions, UnauthorizedError, WalletFrozenError, type WithdrawRequest, type WithdrawResponse };
1798
+ export { type AddressResponse, type ApiErrorCode, type ApprovalConfig, ApprovalsAPI, type ApproveResponse, AuditAPI, type AuditEvent, type AuditResponse, BadRequestError, type BalanceResponse, type CallRequest, type CallResponse, type Chain, type ClientOptions, type DryRunResponse, type EncryptPolicyRequest, type EncryptPolicyResponse, type ErrorCode, type IntentsDepositRequest, type IntentsDepositResponse, NETWORK_BASE_URLS, type Nep413Auth, type Network, NotFoundError, OutlayerClient, OutlayerError, type PendingApproval, type PendingApprovalsResponse, PolicyAPI, PolicyDeniedError, type PolicyResponse, type PolicyRules, RateLimitedError, type RegisterRequest, type RegisterResponse, type RequestListResponse, type RequestStatus, type RequestStatusResponse, type RequestType, type RetryConfig, type SignMessageRequest, type SignMessageResponse, type SignPolicyResponse, type SwapQuoteResponse, type SwapRequest, type SwapResponse, type TokensResponse, type TransferRequest, type UnauthenticatedOptions, UnauthorizedError, WalletFrozenError, type WithdrawRequest, type WithdrawResponse };
package/dist/index.js CHANGED
@@ -88,7 +88,16 @@ async function errorFromResponse(response, parsed) {
88
88
  }
89
89
 
90
90
  // src/http.ts
91
- var DEFAULT_BASE_URL = "https://api.outlayer.fastnear.com";
91
+ var NETWORK_BASE_URLS = {
92
+ mainnet: "https://api.outlayer.fastnear.com",
93
+ testnet: "https://api.testnet.outlayer.fastnear.com"
94
+ };
95
+ var DEFAULT_BASE_URL = NETWORK_BASE_URLS.mainnet;
96
+ function resolveBaseUrl(opts) {
97
+ if (opts.baseUrl) return opts.baseUrl;
98
+ if (opts.network) return NETWORK_BASE_URLS[opts.network];
99
+ return DEFAULT_BASE_URL;
100
+ }
92
101
  var DEFAULT_RETRY = {
93
102
  maxAttempts: 3,
94
103
  initialDelayMs: 100,
@@ -96,7 +105,7 @@ var DEFAULT_RETRY = {
96
105
  };
97
106
  function makeClient(opts) {
98
107
  const init = {
99
- baseUrl: opts.baseUrl ?? DEFAULT_BASE_URL,
108
+ baseUrl: resolveBaseUrl(opts),
100
109
  headers: { Authorization: `Bearer ${opts.apiKey}` }
101
110
  };
102
111
  if (opts.fetch) init.fetch = opts.fetch;
@@ -106,7 +115,7 @@ function makeClient(opts) {
106
115
  }
107
116
  function makeUnauthenticatedClient(opts = {}) {
108
117
  const init = {
109
- baseUrl: opts.baseUrl ?? DEFAULT_BASE_URL
118
+ baseUrl: resolveBaseUrl(opts)
110
119
  };
111
120
  if (opts.fetch) init.fetch = opts.fetch;
112
121
  return createClient(init);
@@ -368,6 +377,6 @@ var OutlayerClient = class {
368
377
  }
369
378
  };
370
379
 
371
- export { ApprovalsAPI, AuditAPI, BadRequestError, NotFoundError, OutlayerClient, OutlayerError, PolicyAPI, PolicyDeniedError, RateLimitedError, UnauthorizedError, WalletFrozenError };
380
+ export { ApprovalsAPI, AuditAPI, BadRequestError, NETWORK_BASE_URLS, NotFoundError, OutlayerClient, OutlayerError, PolicyAPI, PolicyDeniedError, RateLimitedError, UnauthorizedError, WalletFrozenError };
372
381
  //# sourceMappingURL=index.js.map
373
382
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/client.ts"],"names":[],"mappings":";;;;;AAkBO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EAC9B,IAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EAET,YAAY,IAAA,EAA4B;AACtC,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,SAAS,IAAA,CAAK,MAAA;AACnB,IAAA,IAAA,CAAK,UAAU,IAAA,CAAK,OAAA;AAAA,EACtB;AACF;AAEO,IAAM,iBAAA,GAAN,cAAgC,aAAA,CAAc;AAAA,EACnD,YAAY,IAAA,EAA4B;AACtC,IAAA,KAAA,CAAM,IAAI,CAAA;AACV,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AAAA,EACd;AACF;AAEO,IAAM,iBAAA,GAAN,cAAgC,aAAA,CAAc;AAAA,EACnD,YAAY,IAAA,EAA4B;AACtC,IAAA,KAAA,CAAM,IAAI,CAAA;AACV,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AAAA,EACd;AACF;AAEO,IAAM,iBAAA,GAAN,cAAgC,aAAA,CAAc;AAAA,EACnD,YAAY,IAAA,EAA4B;AACtC,IAAA,KAAA,CAAM,IAAI,CAAA;AACV,IAAA,IAAA,C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AW,EAAA,EAA4C;AACrD,IAAA,OAAO,YAAA;AAAA,MACL,MAAM,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,0BAAA,EAA4B,EAAE,MAAA,EAAQ,EAAE,IAAA,EAAM,EAAE,EAAA,EAAG,IAAK,CAAA;AAAA,MAC9E,IAAA,CAAK;AAAA,KACP;AAAA,EACF;AAAA,EAEA,YAAA,CACE,IAAA,GAAwF,EAAC,EAC3D;AAC9B,IAAA,OAAO,YAAA;AAAA,MACL,MAAM,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,qBAAA,EAAuB,EAAE,MAAA,EAAQ,EAAE,KAAA,EAAO,IAAA,EAAK,EAAG,CAAA;AAAA,MACxE,IAAA,CAAK;AAAA,KACP;AAAA,EACF;AACF","file":"index.js","sourcesContent":["import type { components } from './types.js';\n\nexport type ApiErrorCode = components['schemas']['ErrorCode'];\nexport type ErrorCode = ApiErrorCode | 'network_error' | 'parse_error';\n\nexport type ErrorBody = {\n error?: ApiErrorCode;\n message?: string;\n details?: unknown;\n};\n\nexport interface OutlayerErrorOptions {\n code: ErrorCode;\n message: string;\n status: number;\n details?: unknown;\n}\n\nexport class OutlayerError extends Error {\n readonly code: ErrorCode;\n readonly status: number;\n readonly details: unknown;\n\n constructor(opts: OutlayerErrorOptions) {\n super(opts.message);\n this.name = 'OutlayerError';\n this.code = opts.code;\n this.status = opts.status;\n this.details = opts.details;\n }\n}\n\nexport class PolicyDeniedError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'PolicyDeniedError';\n }\n}\n\nexport class WalletFrozenError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'WalletFrozenError';\n }\n}\n\nexport class UnauthorizedError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'UnauthorizedError';\n }\n}\n\nexport class RateLimitedError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'RateLimitedError';\n }\n}\n\nexport class NotFoundError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'NotFoundError';\n }\n}\n\nexport class BadRequestError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'BadRequestError';\n }\n}\n\nconst codeToCtor: Partial<Record<ErrorCode, new (opts: OutlayerErrorOptions) => OutlayerError>> = {\n policy_denied: PolicyDeniedError,\n wallet_frozen: WalletFrozenError,\n missing_auth: UnauthorizedError,\n invalid_api_key: UnauthorizedError,\n timestamp_expired: UnauthorizedError,\n rate_limited: RateLimitedError,\n request_not_found: NotFoundError,\n approval_not_found: NotFoundError,\n bad_request: BadRequestError,\n invalid_address: BadRequestError,\n insufficient_balance: BadRequestError,\n unsupported_chain: BadRequestError,\n unsupported_token: BadRequestError,\n};\n\nexport function makeError(body: ErrorBody, status: number): OutlayerError {\n const code: ErrorCode = body.error ?? 'parse_error';\n const message = body.message ?? `HTTP ${status}`;\n const opts: OutlayerErrorOptions = body.details !== undefined\n ? { code, message, status, details: body.details }\n : { code, message, status };\n const Ctor = codeToCtor[code] ?? OutlayerError;\n return new Ctor(opts);\n}\n\nexport async function errorFromResponse(response: Response, parsed?: unknown): Promise<OutlayerError> {\n let body: ErrorBody;\n if (parsed && typeof parsed === 'object') {\n body = parsed as ErrorBody;\n } else {\n try {\n body = (await response.clone().json()) as ErrorBody;\n } catch {\n body = { error: 'internal_error', message: response.statusText };\n }\n }\n return makeError(body, response.status);\n}\n","import createClient, { type Client } from 'openapi-fetch';\nimport type { paths } from './types.js';\nimport { OutlayerError, errorFromResponse } from './errors.js';\n\nexport const DEFAULT_BASE_URL = 'https://api.outlayer.fastnear.com';\n\nexport type RetryConfig = {\n maxAttempts?: number;\n initialDelayMs?: number;\n maxDelayMs?: number;\n};\n\nexport type ClientOptions = {\n apiKey: string;\n baseUrl?: string;\n fetch?: typeof fetch;\n retry?: RetryConfig;\n};\n\nexport type UnauthenticatedOptions = {\n baseUrl?: string;\n fetch?: typeof fetch;\n};\n\nexport const DEFAULT_RETRY: Required<RetryConfig> = {\n maxAttempts: 3,\n initialDelayMs: 100,\n maxDelayMs: 1600,\n};\n\nexport type FetchClient = Client<paths, `${string}/${string}`>;\n\nexport function makeClient(opts: ClientOptions): { client: FetchClient; retry: Required<RetryConfig> } {\n const init: Parameters<typeof createClient<paths>>[0] = {\n baseUrl: opts.baseUrl ?? DEFAULT_BASE_URL,\n headers: { Authorization: `Bearer ${opts.apiKey}` },\n };\n if (opts.fetch) init.fetch = opts.fetch;\n const client = createClient<paths>(init);\n const retry: Required<RetryConfig> = { ...DEFAULT_RETRY, ...opts.retry };\n return { client, retry };\n}\n\nexport function makeUnauthenticatedClient(opts: UnauthenticatedOptions = {}): FetchClient {\n const init: Parameters<typeof createClient<paths>>[0] = {\n baseUrl: opts.baseUrl ?? DEFAULT_BASE_URL,\n };\n if (opts.fetch) init.fetch = opts.fetch;\n return createClient<paths>(init);\n}\n\nexport type FetchCall<T> = () => Promise<{\n data?: T;\n error?: unknown;\n response: Response;\n}>;\n\nexport async function runWithRetry<T>(\n call: FetchCall<T>,\n retry: Required<RetryConfig>,\n): Promise<T> {\n let lastError: unknown;\n for (let attempt = 1; attempt <= retry.maxAttempts; attempt++) {\n try {\n const { data, error, response } = await call();\n if (response.ok) {\n return data as T;\n }\n const err = await errorFromResponse(response, error);\n if (err.status >= 500 && attempt < retry.maxAttempts) {\n lastError = err;\n await sleep(backoff(attempt, retry));\n continue;\n }\n throw err;\n } catch (e) {\n if (e instanceof OutlayerError) throw e;\n lastError = e;\n if (attempt < retry.maxAttempts && isNetworkError(e)) {\n await sleep(backoff(attempt, retry));\n continue;\n }\n throw new OutlayerError({\n code: 'network_error',\n message: e instanceof Error ? e.message : String(e),\n status: 0,\n });\n }\n }\n throw lastError;\n}\n\nfunction backoff(attempt: number, cfg: Required<RetryConfig>): number {\n return Math.min(cfg.maxDelayMs, cfg.initialDelayMs * 2 ** (attempt - 1));\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((r) => setTimeout(r, ms));\n}\n\nfunction isNetworkError(e: unknown): boolean {\n return e instanceof TypeError;\n}\n\nexport function newIdempotencyKey(): string {\n return crypto.randomUUID();\n}\n","import type { components } from './types.js';\nimport {\n type ClientOptions,\n type FetchClient,\n type RetryConfig,\n type UnauthenticatedOptions,\n DEFAULT_RETRY,\n makeClient,\n makeUnauthenticatedClient,\n newIdempotencyKey,\n runWithRetry,\n} from './http.js';\nimport { errorFromResponse } from './errors.js';\n\ntype Schemas = components['schemas'];\n\n// ---------------------------------------------------------------------------\n// Re-exported user-facing types (so consumers don't import paths/components)\n// ---------------------------------------------------------------------------\n\nexport type Chain = Schemas['Chain'];\nexport type RequestType = Schemas['RequestType'];\nexport type RequestStatus = Schemas['RequestStatus'];\n\nexport type RegisterRequest = Schemas['RegisterRequest'];\nexport type RegisterResponse = Schemas['RegisterResponse'];\nexport type AddressResponse = Schemas['AddressResponse'];\nexport type BalanceResponse = Schemas['BalanceResponse'];\nexport type TokensResponse = Schemas['TokensResponse'];\n\nexport type CallRequest = Schemas['CallRequest'];\nexport type CallResponse = Schemas['CallResponse'];\nexport type TransferRequest = Schemas['TransferRequest'];\nexport type IntentsDepositRequest = Schemas['IntentsDepositRequest'];\nexport type IntentsDepositResponse = Schemas['IntentsDepositResponse'];\n\nexport type WithdrawRequest = Schemas['WithdrawRequest'];\nexport type WithdrawResponse = Schemas['WithdrawResponse'];\nexport type DryRunResponse = Schemas['DryRunResponse'];\n\nexport type SwapRequest = Schemas['SwapRequest'];\nexport type SwapResponse = Schemas['SwapResponse'];\nexport type SwapQuoteResponse = Schemas['SwapQuoteResponse'];\n\nexport type SignMessageRequest = Schemas['SignMessageRequest'];\nexport type SignMessageResponse = Schemas['SignMessageResponse'];\n\nexport type RequestStatusResponse = Schemas['RequestStatusResponse'];\nexport type RequestListResponse = Schemas['RequestListResponse'];\n\nexport type PolicyResponse = Schemas['PolicyResponse'];\nexport type PolicyRules = Schemas['PolicyRules'];\nexport type ApprovalConfig = Schemas['ApprovalConfig'];\nexport type EncryptPolicyRequest = Schemas['EncryptPolicyRequest'];\nexport type EncryptPolicyResponse = Schemas['EncryptPolicyResponse'];\nexport type SignPolicyResponse = Schemas['SignPolicyResponse'];\n\nexport type PendingApproval = Schemas['PendingApproval'];\nexport type PendingApprovalsResponse = Schemas['PendingApprovalsResponse'];\nexport type Nep413Auth = Schemas['Nep413Auth'];\nexport type ApproveResponse = Schemas['ApproveResponse'];\n\nexport type AuditEvent = Schemas['AuditEvent'];\nexport type AuditResponse = Schemas['AuditResponse'];\n\n// ---------------------------------------------------------------------------\n// Shared helpers\n// ---------------------------------------------------------------------------\n\ntype Idempotent = { idempotencyKey?: string };\n\nfunction idempotencyHeader(key: string | undefined): Record<string, string> {\n return { 'Idempotency-Key': key ?? newIdempotencyKey() };\n}\n\n// ---------------------------------------------------------------------------\n// Sub-namespaces\n// ---------------------------------------------------------------------------\n\nexport class PolicyAPI {\n constructor(\n private readonly client: FetchClient,\n private readonly retry: Required<RetryConfig>,\n ) {}\n\n get(): Promise<PolicyResponse> {\n return runWithRetry(() => this.client.GET('/wallet/v1/policy'), this.retry);\n }\n\n encrypt(body: EncryptPolicyRequest): Promise<EncryptPolicyResponse> {\n return runWithRetry(() => this.client.POST('/wallet/v1/encrypt-policy', { body }), this.retry);\n }\n\n sign(encryptedData: string): Promise<SignPolicyResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/sign-policy', { body: { encrypted_data: encryptedData } }),\n this.retry,\n );\n }\n\n invalidateCache(walletId: string): Promise<void> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/invalidate-cache', { body: { wallet_id: walletId } }),\n this.retry,\n ).then(() => undefined);\n }\n}\n\nexport class ApprovalsAPI {\n constructor(\n private readonly client: FetchClient,\n private readonly retry: Required<RetryConfig>,\n ) {}\n\n listPending(): Promise<PendingApprovalsResponse> {\n return runWithRetry(() => this.client.GET('/wallet/v1/pending_approvals'), this.retry);\n }\n\n approve(approvalId: string, auth: Nep413Auth): Promise<ApproveResponse> {\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/approve/{id}', {\n params: { path: { id: approvalId } },\n body: auth,\n }),\n this.retry,\n );\n }\n\n reject(approvalId: string, auth: Nep413Auth, reason?: string): Promise<ApproveResponse> {\n const body = reason !== undefined ? { ...auth, reason } : auth;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/reject/{id}', {\n params: { path: { id: approvalId } },\n body,\n }),\n this.retry,\n );\n }\n}\n\nexport class AuditAPI {\n constructor(\n private readonly client: FetchClient,\n private readonly retry: Required<RetryConfig>,\n ) {}\n\n list(opts: { limit?: number; offset?: number } = {}): Promise<AuditResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/audit', { params: { query: opts } }),\n this.retry,\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Main client\n// ---------------------------------------------------------------------------\n\nexport class OutlayerClient {\n private readonly client: FetchClient;\n private readonly retry: Required<RetryConfig>;\n\n readonly policy: PolicyAPI;\n readonly approvals: ApprovalsAPI;\n readonly audit: AuditAPI;\n\n constructor(opts: ClientOptions) {\n const { client, retry } = makeClient(opts);\n this.client = client;\n this.retry = retry;\n this.policy = new PolicyAPI(client, retry);\n this.approvals = new ApprovalsAPI(client, retry);\n this.audit = new AuditAPI(client, retry);\n }\n\n // ------- Static factory: register a new wallet (no auth) -------\n\n /**\n * Register a new wallet and obtain an API key.\n *\n * - Empty call: anonymous wallet on OutLayer's shared master. Convenient, no setup.\n * - With `vaultId`: bind to a deployed customer vault so keys derive through\n * the per-vault master. Vault binding is permanent.\n * - With `body`: full control — pass any `RegisterRequest` field (e.g., NEP-413\n * account-binding fields). `vaultId` is merged into `body.vault_id` if not\n * already set.\n *\n * Vault deployment is NOT done here — use the dashboard\n * (https://outlayer.fastnear.com/vault) or `outlayer vault init` CLI.\n * See docs/vaults.md for the full flow.\n */\n static async register(\n opts: {\n vaultId?: string;\n body?: RegisterRequest;\n } & UnauthenticatedOptions = {},\n ): Promise<RegisterResponse> {\n const client = makeUnauthenticatedClient(opts);\n const body: RegisterRequest = { ...(opts.body ?? {}) };\n if (opts.vaultId !== undefined && body.vault_id === undefined) {\n body.vault_id = opts.vaultId;\n }\n const { data, error, response } = await client.POST('/register', { body });\n if (!response.ok) throw await errorFromResponse(response, error);\n return data as RegisterResponse;\n }\n\n // ------- Wallet read -------\n\n getAddress(chain: Chain): Promise<AddressResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/address', { params: { query: { chain } } }),\n this.retry,\n );\n }\n\n getBalance(\n opts: { chain?: Chain; token?: string; source?: 'chain' | 'intents' } = {},\n ): Promise<BalanceResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/balance', { params: { query: opts } }),\n this.retry,\n );\n }\n\n listTokens(): Promise<TokensResponse> {\n return runWithRetry(() => this.client.GET('/wallet/v1/tokens'), this.retry);\n }\n\n // ------- Wallet write -------\n\n call(opts: CallRequest & Idempotent): Promise<CallResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/call', {\n body: body as CallRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n transfer(opts: TransferRequest & Idempotent): Promise<CallResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/transfer', {\n body: body as TransferRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n intentsDeposit(opts: IntentsDepositRequest & Idempotent): Promise<IntentsDepositResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/intents/deposit', {\n body: body as IntentsDepositRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n withdraw(opts: WithdrawRequest & Idempotent): Promise<WithdrawResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/intents/withdraw', {\n body: body as WithdrawRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n withdrawDryRun(opts: WithdrawRequest): Promise<DryRunResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/intents/withdraw/dry-run', { body: opts }),\n this.retry,\n );\n }\n\n swap(opts: SwapRequest & Idempotent): Promise<SwapResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/intents/swap', {\n body: body as SwapRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n swapQuote(opts: SwapRequest): Promise<SwapQuoteResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/intents/swap/quote', { body: opts }),\n this.retry,\n );\n }\n\n signMessage(opts: SignMessageRequest): Promise<SignMessageResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/sign-message', { body: opts }),\n this.retry,\n );\n }\n\n // ------- Async request tracking -------\n\n getRequest(id: string): Promise<RequestStatusResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/requests/{id}', { params: { path: { id } } }),\n this.retry,\n );\n }\n\n listRequests(\n opts: { type?: RequestType; status?: RequestStatus; limit?: number; offset?: number } = {},\n ): Promise<RequestListResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/requests', { params: { query: opts } }),\n this.retry,\n );\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/client.ts"],"names":[],"mappings":";;;;;AAkBO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EAC9B,IAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EAET,YAAY,IAAA,EAA4B;AACtC,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,SA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AAE,KAAA,EAAO,IAAA,EAAK,EAAG,CAAA;AAAA,MACxE,IAAA,CAAK;AAAA,KACP;AAAA,EACF;AACF","file":"index.js","sourcesContent":["import type { components } from './types.js';\n\nexport type ApiErrorCode = components['schemas']['ErrorCode'];\nexport type ErrorCode = ApiErrorCode | 'network_error' | 'parse_error';\n\nexport type ErrorBody = {\n error?: ApiErrorCode;\n message?: string;\n details?: unknown;\n};\n\nexport interface OutlayerErrorOptions {\n code: ErrorCode;\n message: string;\n status: number;\n details?: unknown;\n}\n\nexport class OutlayerError extends Error {\n readonly code: ErrorCode;\n readonly status: number;\n readonly details: unknown;\n\n constructor(opts: OutlayerErrorOptions) {\n super(opts.message);\n this.name = 'OutlayerError';\n this.code = opts.code;\n this.status = opts.status;\n this.details = opts.details;\n }\n}\n\nexport class PolicyDeniedError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'PolicyDeniedError';\n }\n}\n\nexport class WalletFrozenError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'WalletFrozenError';\n }\n}\n\nexport class UnauthorizedError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'UnauthorizedError';\n }\n}\n\nexport class RateLimitedError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'RateLimitedError';\n }\n}\n\nexport class NotFoundError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'NotFoundError';\n }\n}\n\nexport class BadRequestError extends OutlayerError {\n constructor(opts: OutlayerErrorOptions) {\n super(opts);\n this.name = 'BadRequestError';\n }\n}\n\nconst codeToCtor: Partial<Record<ErrorCode, new (opts: OutlayerErrorOptions) => OutlayerError>> = {\n policy_denied: PolicyDeniedError,\n wallet_frozen: WalletFrozenError,\n missing_auth: UnauthorizedError,\n invalid_api_key: UnauthorizedError,\n timestamp_expired: UnauthorizedError,\n rate_limited: RateLimitedError,\n request_not_found: NotFoundError,\n approval_not_found: NotFoundError,\n bad_request: BadRequestError,\n invalid_address: BadRequestError,\n insufficient_balance: BadRequestError,\n unsupported_chain: BadRequestError,\n unsupported_token: BadRequestError,\n};\n\nexport function makeError(body: ErrorBody, status: number): OutlayerError {\n const code: ErrorCode = body.error ?? 'parse_error';\n const message = body.message ?? `HTTP ${status}`;\n const opts: OutlayerErrorOptions = body.details !== undefined\n ? { code, message, status, details: body.details }\n : { code, message, status };\n const Ctor = codeToCtor[code] ?? OutlayerError;\n return new Ctor(opts);\n}\n\nexport async function errorFromResponse(response: Response, parsed?: unknown): Promise<OutlayerError> {\n let body: ErrorBody;\n if (parsed && typeof parsed === 'object') {\n body = parsed as ErrorBody;\n } else {\n try {\n body = (await response.clone().json()) as ErrorBody;\n } catch {\n body = { error: 'internal_error', message: response.statusText };\n }\n }\n return makeError(body, response.status);\n}\n","import createClient, { type Client } from 'openapi-fetch';\nimport type { paths } from './types.js';\nimport { OutlayerError, errorFromResponse } from './errors.js';\n\nexport type Network = 'mainnet' | 'testnet';\n\nexport const NETWORK_BASE_URLS: Record<Network, string> = {\n mainnet: 'https://api.outlayer.fastnear.com',\n testnet: 'https://api.testnet.outlayer.fastnear.com',\n};\n\nexport const DEFAULT_BASE_URL = NETWORK_BASE_URLS.mainnet;\n\nexport type RetryConfig = {\n maxAttempts?: number;\n initialDelayMs?: number;\n maxDelayMs?: number;\n};\n\nexport type ClientOptions = {\n apiKey: string;\n /**\n * NEAR network to target. Defaults to `mainnet`. NEAR Intents (cross-chain\n * swaps + gasless withdrawals) only work on mainnet — use testnet for the\n * register / policy / sign-message flow while developing.\n */\n network?: Network;\n /** Overrides `network` for self-hosted or staging deployments. */\n baseUrl?: string;\n fetch?: typeof fetch;\n retry?: RetryConfig;\n};\n\nexport type UnauthenticatedOptions = {\n network?: Network;\n baseUrl?: string;\n fetch?: typeof fetch;\n};\n\nfunction resolveBaseUrl(opts: { network?: Network; baseUrl?: string }): string {\n if (opts.baseUrl) return opts.baseUrl;\n if (opts.network) return NETWORK_BASE_URLS[opts.network];\n return DEFAULT_BASE_URL;\n}\n\nexport const DEFAULT_RETRY: Required<RetryConfig> = {\n maxAttempts: 3,\n initialDelayMs: 100,\n maxDelayMs: 1600,\n};\n\nexport type FetchClient = Client<paths, `${string}/${string}`>;\n\nexport function makeClient(opts: ClientOptions): { client: FetchClient; retry: Required<RetryConfig> } {\n const init: Parameters<typeof createClient<paths>>[0] = {\n baseUrl: resolveBaseUrl(opts),\n headers: { Authorization: `Bearer ${opts.apiKey}` },\n };\n if (opts.fetch) init.fetch = opts.fetch;\n const client = createClient<paths>(init);\n const retry: Required<RetryConfig> = { ...DEFAULT_RETRY, ...opts.retry };\n return { client, retry };\n}\n\nexport function makeUnauthenticatedClient(opts: UnauthenticatedOptions = {}): FetchClient {\n const init: Parameters<typeof createClient<paths>>[0] = {\n baseUrl: resolveBaseUrl(opts),\n };\n if (opts.fetch) init.fetch = opts.fetch;\n return createClient<paths>(init);\n}\n\nexport type FetchCall<T> = () => Promise<{\n data?: T;\n error?: unknown;\n response: Response;\n}>;\n\nexport async function runWithRetry<T>(\n call: FetchCall<T>,\n retry: Required<RetryConfig>,\n): Promise<T> {\n let lastError: unknown;\n for (let attempt = 1; attempt <= retry.maxAttempts; attempt++) {\n try {\n const { data, error, response } = await call();\n if (response.ok) {\n return data as T;\n }\n const err = await errorFromResponse(response, error);\n if (err.status >= 500 && attempt < retry.maxAttempts) {\n lastError = err;\n await sleep(backoff(attempt, retry));\n continue;\n }\n throw err;\n } catch (e) {\n if (e instanceof OutlayerError) throw e;\n lastError = e;\n if (attempt < retry.maxAttempts && isNetworkError(e)) {\n await sleep(backoff(attempt, retry));\n continue;\n }\n throw new OutlayerError({\n code: 'network_error',\n message: e instanceof Error ? e.message : String(e),\n status: 0,\n });\n }\n }\n throw lastError;\n}\n\nfunction backoff(attempt: number, cfg: Required<RetryConfig>): number {\n return Math.min(cfg.maxDelayMs, cfg.initialDelayMs * 2 ** (attempt - 1));\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((r) => setTimeout(r, ms));\n}\n\nfunction isNetworkError(e: unknown): boolean {\n return e instanceof TypeError;\n}\n\nexport function newIdempotencyKey(): string {\n return crypto.randomUUID();\n}\n","import type { components } from './types.js';\nimport {\n type ClientOptions,\n type FetchClient,\n type RetryConfig,\n type UnauthenticatedOptions,\n DEFAULT_RETRY,\n makeClient,\n makeUnauthenticatedClient,\n newIdempotencyKey,\n runWithRetry,\n} from './http.js';\nimport { errorFromResponse } from './errors.js';\n\ntype Schemas = components['schemas'];\n\n// ---------------------------------------------------------------------------\n// Re-exported user-facing types (so consumers don't import paths/components)\n// ---------------------------------------------------------------------------\n\nexport type Chain = Schemas['Chain'];\nexport type RequestType = Schemas['RequestType'];\nexport type RequestStatus = Schemas['RequestStatus'];\n\nexport type RegisterRequest = Schemas['RegisterRequest'];\nexport type RegisterResponse = Schemas['RegisterResponse'];\nexport type AddressResponse = Schemas['AddressResponse'];\nexport type BalanceResponse = Schemas['BalanceResponse'];\nexport type TokensResponse = Schemas['TokensResponse'];\n\nexport type CallRequest = Schemas['CallRequest'];\nexport type CallResponse = Schemas['CallResponse'];\nexport type TransferRequest = Schemas['TransferRequest'];\nexport type IntentsDepositRequest = Schemas['IntentsDepositRequest'];\nexport type IntentsDepositResponse = Schemas['IntentsDepositResponse'];\n\nexport type WithdrawRequest = Schemas['WithdrawRequest'];\nexport type WithdrawResponse = Schemas['WithdrawResponse'];\nexport type DryRunResponse = Schemas['DryRunResponse'];\n\nexport type SwapRequest = Schemas['SwapRequest'];\nexport type SwapResponse = Schemas['SwapResponse'];\nexport type SwapQuoteResponse = Schemas['SwapQuoteResponse'];\n\nexport type SignMessageRequest = Schemas['SignMessageRequest'];\nexport type SignMessageResponse = Schemas['SignMessageResponse'];\n\nexport type RequestStatusResponse = Schemas['RequestStatusResponse'];\nexport type RequestListResponse = Schemas['RequestListResponse'];\n\nexport type PolicyResponse = Schemas['PolicyResponse'];\nexport type PolicyRules = Schemas['PolicyRules'];\nexport type ApprovalConfig = Schemas['ApprovalConfig'];\nexport type EncryptPolicyRequest = Schemas['EncryptPolicyRequest'];\nexport type EncryptPolicyResponse = Schemas['EncryptPolicyResponse'];\nexport type SignPolicyResponse = Schemas['SignPolicyResponse'];\n\nexport type PendingApproval = Schemas['PendingApproval'];\nexport type PendingApprovalsResponse = Schemas['PendingApprovalsResponse'];\nexport type Nep413Auth = Schemas['Nep413Auth'];\nexport type ApproveResponse = Schemas['ApproveResponse'];\n\nexport type AuditEvent = Schemas['AuditEvent'];\nexport type AuditResponse = Schemas['AuditResponse'];\n\n// ---------------------------------------------------------------------------\n// Shared helpers\n// ---------------------------------------------------------------------------\n\ntype Idempotent = { idempotencyKey?: string };\n\nfunction idempotencyHeader(key: string | undefined): Record<string, string> {\n return { 'Idempotency-Key': key ?? newIdempotencyKey() };\n}\n\n// ---------------------------------------------------------------------------\n// Sub-namespaces\n// ---------------------------------------------------------------------------\n\nexport class PolicyAPI {\n constructor(\n private readonly client: FetchClient,\n private readonly retry: Required<RetryConfig>,\n ) {}\n\n get(): Promise<PolicyResponse> {\n return runWithRetry(() => this.client.GET('/wallet/v1/policy'), this.retry);\n }\n\n encrypt(body: EncryptPolicyRequest): Promise<EncryptPolicyResponse> {\n return runWithRetry(() => this.client.POST('/wallet/v1/encrypt-policy', { body }), this.retry);\n }\n\n sign(encryptedData: string): Promise<SignPolicyResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/sign-policy', { body: { encrypted_data: encryptedData } }),\n this.retry,\n );\n }\n\n invalidateCache(walletId: string): Promise<void> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/invalidate-cache', { body: { wallet_id: walletId } }),\n this.retry,\n ).then(() => undefined);\n }\n}\n\nexport class ApprovalsAPI {\n constructor(\n private readonly client: FetchClient,\n private readonly retry: Required<RetryConfig>,\n ) {}\n\n listPending(): Promise<PendingApprovalsResponse> {\n return runWithRetry(() => this.client.GET('/wallet/v1/pending_approvals'), this.retry);\n }\n\n approve(approvalId: string, auth: Nep413Auth): Promise<ApproveResponse> {\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/approve/{id}', {\n params: { path: { id: approvalId } },\n body: auth,\n }),\n this.retry,\n );\n }\n\n reject(approvalId: string, auth: Nep413Auth, reason?: string): Promise<ApproveResponse> {\n const body = reason !== undefined ? { ...auth, reason } : auth;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/reject/{id}', {\n params: { path: { id: approvalId } },\n body,\n }),\n this.retry,\n );\n }\n}\n\nexport class AuditAPI {\n constructor(\n private readonly client: FetchClient,\n private readonly retry: Required<RetryConfig>,\n ) {}\n\n list(opts: { limit?: number; offset?: number } = {}): Promise<AuditResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/audit', { params: { query: opts } }),\n this.retry,\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Main client\n// ---------------------------------------------------------------------------\n\nexport class OutlayerClient {\n private readonly client: FetchClient;\n private readonly retry: Required<RetryConfig>;\n\n readonly policy: PolicyAPI;\n readonly approvals: ApprovalsAPI;\n readonly audit: AuditAPI;\n\n constructor(opts: ClientOptions) {\n const { client, retry } = makeClient(opts);\n this.client = client;\n this.retry = retry;\n this.policy = new PolicyAPI(client, retry);\n this.approvals = new ApprovalsAPI(client, retry);\n this.audit = new AuditAPI(client, retry);\n }\n\n // ------- Static factory: register a new wallet (no auth) -------\n\n /**\n * Register a new wallet and obtain an API key.\n *\n * - Empty call: anonymous wallet on OutLayer's shared master. Convenient, no setup.\n * - With `vaultId`: bind to a deployed customer vault so keys derive through\n * the per-vault master. Vault binding is permanent.\n * - With `body`: full control — pass any `RegisterRequest` field (e.g., NEP-413\n * account-binding fields). `vaultId` is merged into `body.vault_id` if not\n * already set.\n *\n * Vault deployment is NOT done here — use the dashboard\n * (https://outlayer.fastnear.com/vault) or `outlayer vault init` CLI.\n * See docs/vaults.md for the full flow.\n */\n static async register(\n opts: {\n vaultId?: string;\n body?: RegisterRequest;\n } & UnauthenticatedOptions = {},\n ): Promise<RegisterResponse> {\n const client = makeUnauthenticatedClient(opts);\n const body: RegisterRequest = { ...(opts.body ?? {}) };\n if (opts.vaultId !== undefined && body.vault_id === undefined) {\n body.vault_id = opts.vaultId;\n }\n const { data, error, response } = await client.POST('/register', { body });\n if (!response.ok) throw await errorFromResponse(response, error);\n return data as RegisterResponse;\n }\n\n // ------- Wallet read -------\n\n getAddress(chain: Chain): Promise<AddressResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/address', { params: { query: { chain } } }),\n this.retry,\n );\n }\n\n getBalance(\n opts: { chain?: Chain; token?: string; source?: 'chain' | 'intents' } = {},\n ): Promise<BalanceResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/balance', { params: { query: opts } }),\n this.retry,\n );\n }\n\n listTokens(): Promise<TokensResponse> {\n return runWithRetry(() => this.client.GET('/wallet/v1/tokens'), this.retry);\n }\n\n // ------- Wallet write -------\n\n call(opts: CallRequest & Idempotent): Promise<CallResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/call', {\n body: body as CallRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n transfer(opts: TransferRequest & Idempotent): Promise<CallResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/transfer', {\n body: body as TransferRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n intentsDeposit(opts: IntentsDepositRequest & Idempotent): Promise<IntentsDepositResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/intents/deposit', {\n body: body as IntentsDepositRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n withdraw(opts: WithdrawRequest & Idempotent): Promise<WithdrawResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/intents/withdraw', {\n body: body as WithdrawRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n withdrawDryRun(opts: WithdrawRequest): Promise<DryRunResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/intents/withdraw/dry-run', { body: opts }),\n this.retry,\n );\n }\n\n swap(opts: SwapRequest & Idempotent): Promise<SwapResponse> {\n const { idempotencyKey, ...body } = opts;\n return runWithRetry(\n () =>\n this.client.POST('/wallet/v1/intents/swap', {\n body: body as SwapRequest,\n headers: idempotencyHeader(idempotencyKey),\n }),\n this.retry,\n );\n }\n\n swapQuote(opts: SwapRequest): Promise<SwapQuoteResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/intents/swap/quote', { body: opts }),\n this.retry,\n );\n }\n\n signMessage(opts: SignMessageRequest): Promise<SignMessageResponse> {\n return runWithRetry(\n () => this.client.POST('/wallet/v1/sign-message', { body: opts }),\n this.retry,\n );\n }\n\n // ------- Async request tracking -------\n\n getRequest(id: string): Promise<RequestStatusResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/requests/{id}', { params: { path: { id } } }),\n this.retry,\n );\n }\n\n listRequests(\n opts: { type?: RequestType; status?: RequestStatus; limit?: number; offset?: number } = {},\n ): Promise<RequestListResponse> {\n return runWithRetry(\n () => this.client.GET('/wallet/v1/requests', { params: { query: opts } }),\n this.retry,\n );\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outlayer/sdk",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.2",
4
4
  "description": "TypeScript SDK for OutLayer Agent Custody — multi-chain wallets with TEE-enforced policy.",
5
5
  "license": "MIT",
6
6
  "repository": {