@dynamic-labs-wallet/node 1.1.66 → 1.1.67

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/index.cjs CHANGED
@@ -88,7 +88,7 @@ function _object_without_properties_loose(source, excluded) {
88
88
  }
89
89
  }
90
90
 
91
- var version = "1.1.66";
91
+ var version = "1.1.67";
92
92
 
93
93
  const MAX_CAUSE_CHAIN_LENGTH = 4;
94
94
  const SAFE_ERROR_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/;
@@ -3208,6 +3208,182 @@ const asAuthError = async (error, operation)=>{
3208
3208
  };
3209
3209
  }
3210
3210
 
3211
+ class DeviceGrantError extends Error {
3212
+ constructor(code, message){
3213
+ super(message);
3214
+ this.name = 'DeviceGrantError';
3215
+ this.code = code;
3216
+ }
3217
+ }
3218
+ const stripTrailingSlashes = (url)=>{
3219
+ let end = url.length;
3220
+ while(end > 0 && url[end - 1] === '/')end -= 1;
3221
+ return url.slice(0, end);
3222
+ };
3223
+ const isLocalhost = (hostname)=>hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]';
3224
+ // The grant code and minted JWT are bearer secrets — refuse to send them over
3225
+ // plaintext or to a malformed base URL.
3226
+ const assertSecureBaseUrl = (baseUrl)=>{
3227
+ let url;
3228
+ try {
3229
+ url = new URL(baseUrl);
3230
+ } catch (e) {
3231
+ throw new DeviceGrantError('protocol', 'Invalid or insecure baseUrl provided.');
3232
+ }
3233
+ if (url.protocol !== 'https:' && !(url.protocol === 'http:' && isLocalhost(url.hostname))) {
3234
+ throw new DeviceGrantError('protocol', 'baseUrl must be an https: URL (http: is allowed for localhost only).');
3235
+ }
3236
+ };
3237
+ const readErrorBody = async (res)=>{
3238
+ try {
3239
+ const parsed = await res.json();
3240
+ return typeof parsed.error === 'string' ? ` ${parsed.error}` : '';
3241
+ } catch (e) {
3242
+ return '';
3243
+ }
3244
+ };
3245
+ const postJson = async (fetchApi, url, body, signal, operation)=>{
3246
+ let res;
3247
+ try {
3248
+ res = await fetchApi(url, {
3249
+ method: 'POST',
3250
+ headers: {
3251
+ accept: 'application/json',
3252
+ 'content-type': 'application/json'
3253
+ },
3254
+ body: JSON.stringify(body),
3255
+ signal
3256
+ });
3257
+ } catch (err) {
3258
+ if (signal == null ? void 0 : signal.aborted) throw abortError();
3259
+ throw err;
3260
+ }
3261
+ if (!res.ok) {
3262
+ const detail = await readErrorBody(res);
3263
+ throw new Error(`${operation} failed (status ${res.status}).${detail}`);
3264
+ }
3265
+ return await res.json();
3266
+ };
3267
+ const abortError = ()=>new DeviceGrantError('aborted', 'Device grant login was aborted.');
3268
+ const sleep = (ms, signal)=>new Promise((resolve, reject)=>{
3269
+ if (signal == null ? void 0 : signal.aborted) return reject(abortError());
3270
+ const timer = setTimeout(()=>{
3271
+ signal == null ? void 0 : signal.removeEventListener('abort', onAbort);
3272
+ resolve();
3273
+ }, ms);
3274
+ const onAbort = ()=>{
3275
+ clearTimeout(timer);
3276
+ reject(abortError());
3277
+ };
3278
+ signal == null ? void 0 : signal.addEventListener('abort', onAbort, {
3279
+ once: true
3280
+ });
3281
+ });
3282
+ /**
3283
+ * POST /api/v0/auth/grant/code — RFC 8628 device-authorization init.
3284
+ * Public endpoint; `grant_code` returned is the polling secret.
3285
+ */ const requestDeviceGrantCode = async ({ baseUrl = core$1.DYNAMIC_AUTH_PROD_BASE_API_URL, clientType = 'cli', clientMetadata, sessionPublicKey, signal, fetchApi = fetch } = {})=>{
3286
+ assertSecureBaseUrl(baseUrl);
3287
+ const wire = await postJson(fetchApi, `${stripTrailingSlashes(baseUrl)}/api/v0/auth/grant/code`, {
3288
+ client_type: clientType,
3289
+ client_metadata: clientMetadata,
3290
+ session_public_key: sessionPublicKey
3291
+ }, signal, 'device grant code request');
3292
+ if (!wire.grant_code || !wire.user_code || !wire.verification_uri) {
3293
+ throw new DeviceGrantError('protocol', 'Grant code response was missing grant_code, user_code, or verification_uri.');
3294
+ }
3295
+ var _wire_interval, _wire_expires_in;
3296
+ return {
3297
+ grantCode: wire.grant_code,
3298
+ userCode: wire.user_code,
3299
+ verificationUri: wire.verification_uri,
3300
+ verificationUriComplete: wire.verification_uri_complete,
3301
+ interval: (_wire_interval = wire.interval) != null ? _wire_interval : 5,
3302
+ expiresIn: (_wire_expires_in = wire.expires_in) != null ? _wire_expires_in : 600
3303
+ };
3304
+ };
3305
+ /**
3306
+ * POST /api/v0/auth/grant/token — single poll. Status arrives via a 200 +
3307
+ * status discriminator (the RFC's error-via-200 convention).
3308
+ */ const pollDeviceGrantToken = async ({ baseUrl = core$1.DYNAMIC_AUTH_PROD_BASE_API_URL, grantCode, signal, fetchApi = fetch })=>{
3309
+ assertSecureBaseUrl(baseUrl);
3310
+ const wire = await postJson(fetchApi, `${stripTrailingSlashes(baseUrl)}/api/v0/auth/grant/token`, {
3311
+ grant_code: grantCode
3312
+ }, signal, 'device grant token poll');
3313
+ if (typeof wire.status !== 'string' || !wire.status) {
3314
+ throw new DeviceGrantError('protocol', 'Grant token response carried no status.');
3315
+ }
3316
+ if (wire.status === 'approved') {
3317
+ if (!wire.jwt) {
3318
+ throw new DeviceGrantError('protocol', 'Grant approved but the response carried no JWT.');
3319
+ }
3320
+ return {
3321
+ status: 'approved',
3322
+ jwt: wire.jwt,
3323
+ tokenType: wire.token_type
3324
+ };
3325
+ }
3326
+ return {
3327
+ status: wire.status
3328
+ };
3329
+ };
3330
+ /**
3331
+ * Full RFC 8628 login: request a grant code, hand the verification URI to the
3332
+ * caller via onVerification, then poll until the user approves, denies, or the
3333
+ * grant expires. Resolves with the minted user JWT (for authenticateJwt).
3334
+ */ const loginWithDeviceGrant = async (options = {})=>{
3335
+ var _options_fetchApi;
3336
+ const fetchApi = (_options_fetchApi = options.fetchApi) != null ? _options_fetchApi : fetch;
3337
+ const grant = await requestDeviceGrantCode({
3338
+ baseUrl: options.baseUrl,
3339
+ clientType: options.clientType,
3340
+ clientMetadata: options.clientMetadata,
3341
+ sessionPublicKey: options.sessionPublicKey,
3342
+ signal: options.signal,
3343
+ fetchApi
3344
+ });
3345
+ var _options_timeoutMs;
3346
+ // expires_in counts from grant issuance, not from when the caller finishes
3347
+ // displaying the code — start the deadline now.
3348
+ const deadline = Date.now() + ((_options_timeoutMs = options.timeoutMs) != null ? _options_timeoutMs : grant.expiresIn * 1000);
3349
+ await (options.onVerification == null ? void 0 : options.onVerification.call(options, {
3350
+ userCode: grant.userCode,
3351
+ verificationUri: grant.verificationUri,
3352
+ verificationUriComplete: grant.verificationUriComplete
3353
+ }));
3354
+ var _options_pollIntervalMs;
3355
+ let interval = (_options_pollIntervalMs = options.pollIntervalMs) != null ? _options_pollIntervalMs : Math.max(grant.interval, 1) * 1000;
3356
+ while(Date.now() < deadline){
3357
+ if (Date.now() + interval >= deadline) {
3358
+ throw new DeviceGrantError('expired', 'Grant expired before approval.');
3359
+ }
3360
+ await sleep(interval, options.signal);
3361
+ const res = await pollDeviceGrantToken({
3362
+ baseUrl: options.baseUrl,
3363
+ grantCode: grant.grantCode,
3364
+ signal: options.signal,
3365
+ fetchApi
3366
+ });
3367
+ if (res.status === 'approved' && 'jwt' in res) {
3368
+ return {
3369
+ jwt: res.jwt,
3370
+ tokenType: res.tokenType
3371
+ };
3372
+ }
3373
+ switch(res.status){
3374
+ case 'denied':
3375
+ throw new DeviceGrantError('denied', 'Grant was denied in the browser.');
3376
+ case 'expired':
3377
+ throw new DeviceGrantError('expired', 'Grant expired before approval.');
3378
+ case 'slow_down':
3379
+ // RFC 8628 §3.5: add 5 seconds on each slow_down response.
3380
+ interval += 5000;
3381
+ break;
3382
+ }
3383
+ }
3384
+ throw new DeviceGrantError('expired', 'Grant expired before approval.');
3385
+ };
3386
+
3211
3387
  Object.defineProperty(exports, "EarnClient", {
3212
3388
  enumerable: true,
3213
3389
  get: function () { return core$1.EarnClient; }
@@ -3237,6 +3413,7 @@ Object.defineProperty(exports, "SignMessageRawSignHashFunctionEnum", {
3237
3413
  get: function () { return sdkApiCore.SignMessageRawSignHashFunctionEnum; }
3238
3414
  });
3239
3415
  exports.ClientValidationError = ClientValidationError;
3416
+ exports.DeviceGrantError = DeviceGrantError;
3240
3417
  exports.DynamicServerApiClient = DynamicServerApiClient;
3241
3418
  exports.DynamicWalletClient = DynamicWalletClient;
3242
3419
  exports.ERROR_RAW_SIGN_CONTEXT_REQUIRED = ERROR_RAW_SIGN_CONTEXT_REQUIRED;
@@ -3258,8 +3435,11 @@ exports.getMPCSignatureScheme = getMPCSignatureScheme;
3258
3435
  exports.getMPCSigner = getMPCSigner;
3259
3436
  exports.isHexString = isHexString;
3260
3437
  exports.logError = logError;
3438
+ exports.loginWithDeviceGrant = loginWithDeviceGrant;
3261
3439
  exports.mergeUniqueKeyShares = mergeUniqueKeyShares;
3262
3440
  exports.parseIndexMapDerivationPath = parseIndexMapDerivationPath;
3441
+ exports.pollDeviceGrantToken = pollDeviceGrantToken;
3442
+ exports.requestDeviceGrantCode = requestDeviceGrantCode;
3263
3443
  exports.resolveRawSignContext = resolveRawSignContext;
3264
3444
  exports.retryPromise = retryPromise;
3265
3445
  exports.revokeDelegation = revokeDelegation;
package/index.esm.js CHANGED
@@ -88,7 +88,7 @@ function _object_without_properties_loose(source, excluded) {
88
88
  }
89
89
  }
90
90
 
91
- var version = "1.1.66";
91
+ var version = "1.1.67";
92
92
 
93
93
  const MAX_CAUSE_CHAIN_LENGTH = 4;
94
94
  const SAFE_ERROR_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/;
@@ -3208,4 +3208,180 @@ const asAuthError = async (error, operation)=>{
3208
3208
  };
3209
3209
  }
3210
3210
 
3211
- export { ClientValidationError, DynamicServerApiClient, DynamicWalletClient, ERROR_RAW_SIGN_CONTEXT_REQUIRED, base64ToBytes, bytesToBase64, createAuthClient, createDelegatedWalletClient, createLogError, decryptDelegatedPayload, decryptDelegatedWebhookData, decryptWalletApiKey, delegatedSignMessage, ensureBase64Padding, formatEvmMessage, formatMessage, generateSessionKeyPair, getExternalServerKeyShareBackupInfo, getMPCSignatureScheme, getMPCSigner, isHexString, logError, mergeUniqueKeyShares, parseIndexMapDerivationPath, resolveRawSignContext, retryPromise, revokeDelegation, signSessionMessage, stringToBytes, stripHexPrefix, withDelegatedServerAuth };
3211
+ class DeviceGrantError extends Error {
3212
+ constructor(code, message){
3213
+ super(message);
3214
+ this.name = 'DeviceGrantError';
3215
+ this.code = code;
3216
+ }
3217
+ }
3218
+ const stripTrailingSlashes = (url)=>{
3219
+ let end = url.length;
3220
+ while(end > 0 && url[end - 1] === '/')end -= 1;
3221
+ return url.slice(0, end);
3222
+ };
3223
+ const isLocalhost = (hostname)=>hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]';
3224
+ // The grant code and minted JWT are bearer secrets — refuse to send them over
3225
+ // plaintext or to a malformed base URL.
3226
+ const assertSecureBaseUrl = (baseUrl)=>{
3227
+ let url;
3228
+ try {
3229
+ url = new URL(baseUrl);
3230
+ } catch (e) {
3231
+ throw new DeviceGrantError('protocol', 'Invalid or insecure baseUrl provided.');
3232
+ }
3233
+ if (url.protocol !== 'https:' && !(url.protocol === 'http:' && isLocalhost(url.hostname))) {
3234
+ throw new DeviceGrantError('protocol', 'baseUrl must be an https: URL (http: is allowed for localhost only).');
3235
+ }
3236
+ };
3237
+ const readErrorBody = async (res)=>{
3238
+ try {
3239
+ const parsed = await res.json();
3240
+ return typeof parsed.error === 'string' ? ` ${parsed.error}` : '';
3241
+ } catch (e) {
3242
+ return '';
3243
+ }
3244
+ };
3245
+ const postJson = async (fetchApi, url, body, signal, operation)=>{
3246
+ let res;
3247
+ try {
3248
+ res = await fetchApi(url, {
3249
+ method: 'POST',
3250
+ headers: {
3251
+ accept: 'application/json',
3252
+ 'content-type': 'application/json'
3253
+ },
3254
+ body: JSON.stringify(body),
3255
+ signal
3256
+ });
3257
+ } catch (err) {
3258
+ if (signal == null ? void 0 : signal.aborted) throw abortError();
3259
+ throw err;
3260
+ }
3261
+ if (!res.ok) {
3262
+ const detail = await readErrorBody(res);
3263
+ throw new Error(`${operation} failed (status ${res.status}).${detail}`);
3264
+ }
3265
+ return await res.json();
3266
+ };
3267
+ const abortError = ()=>new DeviceGrantError('aborted', 'Device grant login was aborted.');
3268
+ const sleep = (ms, signal)=>new Promise((resolve, reject)=>{
3269
+ if (signal == null ? void 0 : signal.aborted) return reject(abortError());
3270
+ const timer = setTimeout(()=>{
3271
+ signal == null ? void 0 : signal.removeEventListener('abort', onAbort);
3272
+ resolve();
3273
+ }, ms);
3274
+ const onAbort = ()=>{
3275
+ clearTimeout(timer);
3276
+ reject(abortError());
3277
+ };
3278
+ signal == null ? void 0 : signal.addEventListener('abort', onAbort, {
3279
+ once: true
3280
+ });
3281
+ });
3282
+ /**
3283
+ * POST /api/v0/auth/grant/code — RFC 8628 device-authorization init.
3284
+ * Public endpoint; `grant_code` returned is the polling secret.
3285
+ */ const requestDeviceGrantCode = async ({ baseUrl = DYNAMIC_AUTH_PROD_BASE_API_URL, clientType = 'cli', clientMetadata, sessionPublicKey, signal, fetchApi = fetch } = {})=>{
3286
+ assertSecureBaseUrl(baseUrl);
3287
+ const wire = await postJson(fetchApi, `${stripTrailingSlashes(baseUrl)}/api/v0/auth/grant/code`, {
3288
+ client_type: clientType,
3289
+ client_metadata: clientMetadata,
3290
+ session_public_key: sessionPublicKey
3291
+ }, signal, 'device grant code request');
3292
+ if (!wire.grant_code || !wire.user_code || !wire.verification_uri) {
3293
+ throw new DeviceGrantError('protocol', 'Grant code response was missing grant_code, user_code, or verification_uri.');
3294
+ }
3295
+ var _wire_interval, _wire_expires_in;
3296
+ return {
3297
+ grantCode: wire.grant_code,
3298
+ userCode: wire.user_code,
3299
+ verificationUri: wire.verification_uri,
3300
+ verificationUriComplete: wire.verification_uri_complete,
3301
+ interval: (_wire_interval = wire.interval) != null ? _wire_interval : 5,
3302
+ expiresIn: (_wire_expires_in = wire.expires_in) != null ? _wire_expires_in : 600
3303
+ };
3304
+ };
3305
+ /**
3306
+ * POST /api/v0/auth/grant/token — single poll. Status arrives via a 200 +
3307
+ * status discriminator (the RFC's error-via-200 convention).
3308
+ */ const pollDeviceGrantToken = async ({ baseUrl = DYNAMIC_AUTH_PROD_BASE_API_URL, grantCode, signal, fetchApi = fetch })=>{
3309
+ assertSecureBaseUrl(baseUrl);
3310
+ const wire = await postJson(fetchApi, `${stripTrailingSlashes(baseUrl)}/api/v0/auth/grant/token`, {
3311
+ grant_code: grantCode
3312
+ }, signal, 'device grant token poll');
3313
+ if (typeof wire.status !== 'string' || !wire.status) {
3314
+ throw new DeviceGrantError('protocol', 'Grant token response carried no status.');
3315
+ }
3316
+ if (wire.status === 'approved') {
3317
+ if (!wire.jwt) {
3318
+ throw new DeviceGrantError('protocol', 'Grant approved but the response carried no JWT.');
3319
+ }
3320
+ return {
3321
+ status: 'approved',
3322
+ jwt: wire.jwt,
3323
+ tokenType: wire.token_type
3324
+ };
3325
+ }
3326
+ return {
3327
+ status: wire.status
3328
+ };
3329
+ };
3330
+ /**
3331
+ * Full RFC 8628 login: request a grant code, hand the verification URI to the
3332
+ * caller via onVerification, then poll until the user approves, denies, or the
3333
+ * grant expires. Resolves with the minted user JWT (for authenticateJwt).
3334
+ */ const loginWithDeviceGrant = async (options = {})=>{
3335
+ var _options_fetchApi;
3336
+ const fetchApi = (_options_fetchApi = options.fetchApi) != null ? _options_fetchApi : fetch;
3337
+ const grant = await requestDeviceGrantCode({
3338
+ baseUrl: options.baseUrl,
3339
+ clientType: options.clientType,
3340
+ clientMetadata: options.clientMetadata,
3341
+ sessionPublicKey: options.sessionPublicKey,
3342
+ signal: options.signal,
3343
+ fetchApi
3344
+ });
3345
+ var _options_timeoutMs;
3346
+ // expires_in counts from grant issuance, not from when the caller finishes
3347
+ // displaying the code — start the deadline now.
3348
+ const deadline = Date.now() + ((_options_timeoutMs = options.timeoutMs) != null ? _options_timeoutMs : grant.expiresIn * 1000);
3349
+ await (options.onVerification == null ? void 0 : options.onVerification.call(options, {
3350
+ userCode: grant.userCode,
3351
+ verificationUri: grant.verificationUri,
3352
+ verificationUriComplete: grant.verificationUriComplete
3353
+ }));
3354
+ var _options_pollIntervalMs;
3355
+ let interval = (_options_pollIntervalMs = options.pollIntervalMs) != null ? _options_pollIntervalMs : Math.max(grant.interval, 1) * 1000;
3356
+ while(Date.now() < deadline){
3357
+ if (Date.now() + interval >= deadline) {
3358
+ throw new DeviceGrantError('expired', 'Grant expired before approval.');
3359
+ }
3360
+ await sleep(interval, options.signal);
3361
+ const res = await pollDeviceGrantToken({
3362
+ baseUrl: options.baseUrl,
3363
+ grantCode: grant.grantCode,
3364
+ signal: options.signal,
3365
+ fetchApi
3366
+ });
3367
+ if (res.status === 'approved' && 'jwt' in res) {
3368
+ return {
3369
+ jwt: res.jwt,
3370
+ tokenType: res.tokenType
3371
+ };
3372
+ }
3373
+ switch(res.status){
3374
+ case 'denied':
3375
+ throw new DeviceGrantError('denied', 'Grant was denied in the browser.');
3376
+ case 'expired':
3377
+ throw new DeviceGrantError('expired', 'Grant expired before approval.');
3378
+ case 'slow_down':
3379
+ // RFC 8628 §3.5: add 5 seconds on each slow_down response.
3380
+ interval += 5000;
3381
+ break;
3382
+ }
3383
+ }
3384
+ throw new DeviceGrantError('expired', 'Grant expired before approval.');
3385
+ };
3386
+
3387
+ export { ClientValidationError, DeviceGrantError, DynamicServerApiClient, DynamicWalletClient, ERROR_RAW_SIGN_CONTEXT_REQUIRED, base64ToBytes, bytesToBase64, createAuthClient, createDelegatedWalletClient, createLogError, decryptDelegatedPayload, decryptDelegatedWebhookData, decryptWalletApiKey, delegatedSignMessage, ensureBase64Padding, formatEvmMessage, formatMessage, generateSessionKeyPair, getExternalServerKeyShareBackupInfo, getMPCSignatureScheme, getMPCSigner, isHexString, logError, loginWithDeviceGrant, mergeUniqueKeyShares, parseIndexMapDerivationPath, pollDeviceGrantToken, requestDeviceGrantCode, resolveRawSignContext, retryPromise, revokeDelegation, signSessionMessage, stringToBytes, stripHexPrefix, withDelegatedServerAuth };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/node",
3
- "version": "1.1.66",
3
+ "version": "1.1.67",
4
4
  "license": "Licensed under the Dynamic Labs, Inc. Terms Of Service (https://www.dynamic.xyz/terms-conditions)",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@dynamic-labs-wallet/core": "1.1.66",
7
+ "@dynamic-labs-wallet/core": "1.1.67",
8
8
  "@dynamic-labs-wallet/forward-mpc-client": "2.0.2",
9
- "@dynamic-labs-wallet/primitives": "1.1.66",
9
+ "@dynamic-labs-wallet/primitives": "1.1.67",
10
10
  "@dynamic-labs/logger": "^5.9.4",
11
11
  "@dynamic-labs/sdk-api-core": "0.144.0",
12
12
  "uuid": "11.1.1",
@@ -0,0 +1,90 @@
1
+ import type { FetchAPI } from '@dynamic-labs/sdk-api-core';
2
+ export type DeviceGrantClientType = 'cli' | 'mcp' | 'demo' | 'ide-plugin' | 'agent_wallet' | 'other' | (string & {});
3
+ export interface DeviceGrantClientMetadata {
4
+ hostname?: string;
5
+ name?: string;
6
+ os?: string;
7
+ version?: string;
8
+ }
9
+ export interface DeviceGrantCode {
10
+ grantCode: string;
11
+ userCode: string;
12
+ verificationUri: string;
13
+ verificationUriComplete?: string;
14
+ /** Polling interval in seconds, server-assigned (RFC 8628 default 5). */
15
+ interval: number;
16
+ /** Grant lifetime in seconds; the grant must be approved within it. */
17
+ expiresIn: number;
18
+ }
19
+ export interface DeviceGrantResult {
20
+ /** Dynamic user JWT — pass to DynamicWalletClient.authenticateJwt. */
21
+ jwt: string;
22
+ tokenType?: string;
23
+ }
24
+ export type DeviceGrantErrorCode = 'denied' | 'expired' | 'aborted' | 'protocol';
25
+ export declare class DeviceGrantError extends Error {
26
+ readonly code: DeviceGrantErrorCode;
27
+ constructor(code: DeviceGrantErrorCode, message: string);
28
+ }
29
+ export interface RequestDeviceGrantCodeOptions {
30
+ baseUrl?: string;
31
+ clientType?: DeviceGrantClientType;
32
+ clientMetadata?: DeviceGrantClientMetadata;
33
+ /**
34
+ * Compressed P-256 session public key (hex, from generateSessionKeyPair).
35
+ * Sent as `session_public_key` and bound into the minted JWT so the
36
+ * session is a signed session — required for signed-session operations.
37
+ */
38
+ sessionPublicKey?: string;
39
+ signal?: AbortSignal;
40
+ /** Custom fetch implementation (tests, proxies). */
41
+ fetchApi?: FetchAPI;
42
+ }
43
+ export interface PollDeviceGrantTokenOptions {
44
+ baseUrl?: string;
45
+ grantCode: string;
46
+ signal?: AbortSignal;
47
+ fetchApi?: FetchAPI;
48
+ }
49
+ export type DeviceGrantTokenStatus = {
50
+ status: 'approved';
51
+ jwt: string;
52
+ tokenType?: string;
53
+ } | {
54
+ status: 'pending' | 'slow_down' | 'denied' | 'expired' | (string & {});
55
+ };
56
+ export interface LoginWithDeviceGrantOptions extends Omit<RequestDeviceGrantCodeOptions, 'fetchApi' | 'signal'> {
57
+ /**
58
+ * Called once with the code the user must approve (open verificationUri in
59
+ * a browser, print userCode, etc.). Opening the URI is the caller's
60
+ * concern — this stays Node-safe and browser-free.
61
+ */
62
+ onVerification?: (verification: {
63
+ userCode: string;
64
+ verificationUri: string;
65
+ verificationUriComplete?: string;
66
+ }) => void | Promise<void>;
67
+ signal?: AbortSignal;
68
+ fetchApi?: FetchAPI;
69
+ /** Overrides the server-assigned poll interval (ms). Mainly for tests. */
70
+ pollIntervalMs?: number;
71
+ /** Overrides the grant lifetime deadline (ms). Mainly for tests. */
72
+ timeoutMs?: number;
73
+ }
74
+ /**
75
+ * POST /api/v0/auth/grant/code — RFC 8628 device-authorization init.
76
+ * Public endpoint; `grant_code` returned is the polling secret.
77
+ */
78
+ export declare const requestDeviceGrantCode: ({ baseUrl, clientType, clientMetadata, sessionPublicKey, signal, fetchApi, }?: RequestDeviceGrantCodeOptions) => Promise<DeviceGrantCode>;
79
+ /**
80
+ * POST /api/v0/auth/grant/token — single poll. Status arrives via a 200 +
81
+ * status discriminator (the RFC's error-via-200 convention).
82
+ */
83
+ export declare const pollDeviceGrantToken: ({ baseUrl, grantCode, signal, fetchApi, }: PollDeviceGrantTokenOptions) => Promise<DeviceGrantTokenStatus>;
84
+ /**
85
+ * Full RFC 8628 login: request a grant code, hand the verification URI to the
86
+ * caller via onVerification, then poll until the user approves, denies, or the
87
+ * grant expires. Resolves with the minted user JWT (for authenticateJwt).
88
+ */
89
+ export declare const loginWithDeviceGrant: (options?: LoginWithDeviceGrantOptions) => Promise<DeviceGrantResult>;
90
+ //# sourceMappingURL=deviceGrant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deviceGrant.d.ts","sourceRoot":"","sources":["../../packages/src/deviceGrant.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAI3D,MAAM,MAAM,qBAAqB,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,YAAY,GAAG,cAAc,GAAG,OAAO,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAErH,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,yEAAyE;IACzE,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,C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,CAAC;IACpB,0EAA0E;IAC1E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA2FD;;;GAGG;AACH,eAAO,MAAM,sBAAsB,kFAOhC,6BAA6B,KAAQ,OAAO,CAAC,eAAe,CA2B9D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,8CAK9B,2BAA2B,KAAG,OAAO,CAAC,sBAAsB,CAmB9D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,aAAmB,2BAA2B,KAAQ,OAAO,CAAC,iBAAiB,CAmD/G,CAAC"}
package/src/index.d.ts CHANGED
@@ -20,6 +20,8 @@ export { ChainEnum } from '@dynamic-labs/sdk-api-core';
20
20
  export type { EarnChainName, EarnEarnings, EarnExecutionStep, EarnSigningPayload, EarnTransactionResult, EarnTransactionStep, EarnVaultDetails, EarnVaultEarnings, EarnVaultPosition, EarnVaultPositionPerformance, EarnVaultReward, EarnVaultSummary, } from '@dynamic-labs-wallet/core';
21
21
  export { createAuthClient } from './authClient.js';
22
22
  export type { AuthResult, CreateAuthClientOptions, DynamicAuthClient } from './authClient.js';
23
+ export { DeviceGrantError, loginWithDeviceGrant, pollDeviceGrantToken, requestDeviceGrantCode } from './deviceGrant.js';
24
+ export type { DeviceGrantClientMetadata, DeviceGrantClientType, DeviceGrantCode, DeviceGrantErrorCode, DeviceGrantResult, DeviceGrantTokenStatus, LoginWithDeviceGrantOptions, PollDeviceGrantTokenOptions, RequestDeviceGrantCodeOptions, } from './deviceGrant.js';
23
25
  export type { SignMessageContext } from '@dynamic-labs-wallet/core';
24
26
  export type { ConfidentialAccountState, ConfidentialTransferOperation, CreateConfidentialSeedRequest, CreateConfidentialSeedResponse, SignConfidentialTransferRequest, SignConfidentialTransferResponse, SvmConfidentialBalanceRequest, SvmConfidentialBalanceResponse, } from '@dynamic-labs-wallet/core';
25
27
  //# sourceMappingURL=index.d.ts.map
@@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