@0xsequence/wallet-wdk 3.0.0-beta.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/CHANGELOG.md +182 -0
- package/dist/dbs/auth-commitments.d.ts.map +1 -1
- package/dist/dbs/auth-keys.d.ts +3 -1
- package/dist/dbs/auth-keys.d.ts.map +1 -1
- package/dist/dbs/auth-keys.js +16 -4
- package/dist/dbs/messages.d.ts.map +1 -1
- package/dist/dbs/passkey-credentials.d.ts.map +1 -1
- package/dist/dbs/recovery.d.ts.map +1 -1
- package/dist/dbs/signatures.d.ts.map +1 -1
- package/dist/dbs/transactions.d.ts.map +1 -1
- package/dist/dbs/wallets.d.ts.map +1 -1
- package/dist/env.d.ts +22 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +30 -0
- package/dist/identity/signer.d.ts +5 -4
- package/dist/identity/signer.d.ts.map +1 -1
- package/dist/identity/signer.js +11 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/sequence/cron.d.ts +3 -0
- package/dist/sequence/cron.d.ts.map +1 -1
- package/dist/sequence/cron.js +72 -39
- package/dist/sequence/handlers/authcode-pkce.d.ts +2 -1
- package/dist/sequence/handlers/authcode-pkce.d.ts.map +1 -1
- package/dist/sequence/handlers/authcode-pkce.js +4 -4
- package/dist/sequence/handlers/authcode.d.ts +4 -1
- package/dist/sequence/handlers/authcode.d.ts.map +1 -1
- package/dist/sequence/handlers/authcode.js +23 -6
- package/dist/sequence/handlers/devices.d.ts +1 -1
- package/dist/sequence/handlers/devices.d.ts.map +1 -1
- package/dist/sequence/handlers/devices.js +1 -1
- package/dist/sequence/handlers/guard.d.ts +1 -1
- package/dist/sequence/handlers/guard.d.ts.map +1 -1
- package/dist/sequence/handlers/guard.js +22 -19
- package/dist/sequence/handlers/identity.d.ts +3 -1
- package/dist/sequence/handlers/identity.d.ts.map +1 -1
- package/dist/sequence/handlers/identity.js +14 -7
- package/dist/sequence/handlers/mnemonic.d.ts.map +1 -1
- package/dist/sequence/handlers/mnemonic.js +21 -18
- package/dist/sequence/handlers/otp.d.ts +2 -1
- package/dist/sequence/handlers/otp.d.ts.map +1 -1
- package/dist/sequence/handlers/otp.js +4 -3
- package/dist/sequence/handlers/passkeys.d.ts +6 -4
- package/dist/sequence/handlers/passkeys.d.ts.map +1 -1
- package/dist/sequence/handlers/passkeys.js +8 -5
- package/dist/sequence/handlers/recovery.js +1 -1
- package/dist/sequence/index.d.ts +2 -0
- package/dist/sequence/index.d.ts.map +1 -1
- package/dist/sequence/index.js +1 -0
- package/dist/sequence/manager.d.ts +67 -55
- package/dist/sequence/manager.d.ts.map +1 -1
- package/dist/sequence/manager.js +77 -17
- package/dist/sequence/messages.js +1 -1
- package/dist/sequence/passkeys-provider.d.ts +24 -0
- package/dist/sequence/passkeys-provider.d.ts.map +1 -0
- package/dist/sequence/passkeys-provider.js +15 -0
- package/dist/sequence/recovery.d.ts +2 -0
- package/dist/sequence/recovery.d.ts.map +1 -1
- package/dist/sequence/recovery.js +100 -34
- package/dist/sequence/signers.d.ts.map +1 -1
- package/dist/sequence/signers.js +3 -1
- package/dist/sequence/transactions.d.ts.map +1 -1
- package/dist/sequence/transactions.js +5 -2
- package/dist/sequence/wallets.d.ts +2 -1
- package/dist/sequence/wallets.d.ts.map +1 -1
- package/dist/sequence/wallets.js +32 -22
- package/eslint.config.js +12 -0
- package/package.json +16 -14
- package/src/dbs/auth-commitments.ts +1 -1
- package/src/dbs/auth-keys.ts +20 -6
- package/src/dbs/messages.ts +1 -1
- package/src/dbs/passkey-credentials.ts +1 -1
- package/src/dbs/recovery.ts +1 -1
- package/src/dbs/signatures.ts +1 -1
- package/src/dbs/transactions.ts +1 -1
- package/src/dbs/wallets.ts +1 -1
- package/src/env.ts +58 -0
- package/src/identity/signer.ts +13 -7
- package/src/index.ts +1 -0
- package/src/sequence/cron.ts +75 -42
- package/src/sequence/handlers/authcode-pkce.ts +6 -4
- package/src/sequence/handlers/authcode.ts +26 -5
- package/src/sequence/handlers/devices.ts +1 -1
- package/src/sequence/handlers/guard.ts +6 -4
- package/src/sequence/handlers/identity.ts +18 -8
- package/src/sequence/handlers/mnemonic.ts +5 -3
- package/src/sequence/handlers/otp.ts +5 -3
- package/src/sequence/handlers/passkeys.ts +13 -13
- package/src/sequence/handlers/recovery.ts +1 -1
- package/src/sequence/index.ts +2 -0
- package/src/sequence/manager.ts +168 -14
- package/src/sequence/messages.ts +1 -1
- package/src/sequence/passkeys-provider.ts +55 -0
- package/src/sequence/recovery.ts +165 -56
- package/src/sequence/signers.ts +3 -1
- package/src/sequence/transactions.ts +6 -2
- package/src/sequence/wallets.ts +39 -25
- package/test/authcode-pkce.test.ts +2 -3
- package/test/authcode.test.ts +6 -8
- package/test/constants.ts +4 -2
- package/test/guard.test.ts +5 -5
- package/test/identity-signer.test.ts +1 -1
- package/test/otp.test.ts +1 -1
- package/test/passkeys.test.ts +1 -1
- package/test/recovery.test.ts +3 -3
- package/test/sessions.test.ts +1 -1
- package/test/{test-ssr-safety.mjs → test-ssr-safety.js} +143 -137
- package/test/transactions.test.ts +3 -3
- package/test/wallets.test.ts +5 -5
package/dist/sequence/cron.js
CHANGED
|
@@ -9,12 +9,14 @@ export class Cron {
|
|
|
9
9
|
STORAGE_KEY = 'sequence-cron-jobs';
|
|
10
10
|
isStopping = false;
|
|
11
11
|
currentCheckJobsPromise = Promise.resolve();
|
|
12
|
+
env;
|
|
12
13
|
/**
|
|
13
14
|
* Initializes the Cron scheduler and starts the periodic job checker.
|
|
14
15
|
* @param shared Shared context for modules and logging.
|
|
15
16
|
*/
|
|
16
17
|
constructor(shared) {
|
|
17
18
|
this.shared = shared;
|
|
19
|
+
this.env = shared.env;
|
|
18
20
|
this.start();
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
@@ -25,7 +27,11 @@ export class Cron {
|
|
|
25
27
|
if (this.isStopping)
|
|
26
28
|
return;
|
|
27
29
|
this.executeCheckJobsChain();
|
|
28
|
-
|
|
30
|
+
const setIntervalFn = this.env.timers?.setInterval ?? globalThis.setInterval;
|
|
31
|
+
if (!setIntervalFn) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this.checkInterval = setIntervalFn(() => this.executeCheckJobsChain(), 60 * 1000);
|
|
29
35
|
}
|
|
30
36
|
/**
|
|
31
37
|
* Chains job checks to ensure sequential execution.
|
|
@@ -47,7 +53,10 @@ export class Cron {
|
|
|
47
53
|
async stop() {
|
|
48
54
|
this.isStopping = true;
|
|
49
55
|
if (this.checkInterval) {
|
|
50
|
-
|
|
56
|
+
const clearIntervalFn = this.env.timers?.clearInterval ?? globalThis.clearInterval;
|
|
57
|
+
if (clearIntervalFn) {
|
|
58
|
+
clearIntervalFn(this.checkInterval);
|
|
59
|
+
}
|
|
51
60
|
this.checkInterval = undefined;
|
|
52
61
|
this.shared.modules.logger.log('Cron: Interval cleared.');
|
|
53
62
|
}
|
|
@@ -88,46 +97,24 @@ export class Cron {
|
|
|
88
97
|
return;
|
|
89
98
|
}
|
|
90
99
|
try {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
if (!lock) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const now = Date.now();
|
|
99
|
-
const storage = await this.getStorageState();
|
|
100
|
-
for (const [id, job] of this.jobs) {
|
|
100
|
+
const locks = this.env.locks ?? globalThis.navigator?.locks;
|
|
101
|
+
if (locks?.request) {
|
|
102
|
+
await locks.request('sequence-cron-jobs', async (lock) => {
|
|
101
103
|
if (this.isStopping) {
|
|
102
|
-
|
|
104
|
+
return;
|
|
103
105
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (timeSinceLastRun >= job.interval) {
|
|
107
|
-
try {
|
|
108
|
-
await job.handler();
|
|
109
|
-
if (!this.isStopping) {
|
|
110
|
-
job.lastRun = now;
|
|
111
|
-
storage.set(id, { lastRun: now });
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
116
|
-
this.shared.modules.logger.log(`Cron: Job ${id} was aborted.`);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
console.error(`Cron job ${id} failed:`, error);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
106
|
+
if (!lock) {
|
|
107
|
+
return;
|
|
122
108
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
109
|
+
await this.runJobs();
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
await this.runJobs();
|
|
114
|
+
}
|
|
128
115
|
}
|
|
129
116
|
catch (error) {
|
|
130
|
-
if (error
|
|
117
|
+
if (this.isAbortError(error)) {
|
|
131
118
|
this.shared.modules.logger.log('Cron: navigator.locks.request was aborted.');
|
|
132
119
|
}
|
|
133
120
|
else {
|
|
@@ -135,6 +122,37 @@ export class Cron {
|
|
|
135
122
|
}
|
|
136
123
|
}
|
|
137
124
|
}
|
|
125
|
+
async runJobs() {
|
|
126
|
+
const now = Date.now();
|
|
127
|
+
const storage = await this.getStorageState();
|
|
128
|
+
for (const [id, job] of this.jobs) {
|
|
129
|
+
if (this.isStopping) {
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
const lastRun = storage.get(id)?.lastRun ?? job.lastRun;
|
|
133
|
+
const timeSinceLastRun = now - lastRun;
|
|
134
|
+
if (timeSinceLastRun >= job.interval) {
|
|
135
|
+
try {
|
|
136
|
+
await job.handler();
|
|
137
|
+
if (!this.isStopping) {
|
|
138
|
+
job.lastRun = now;
|
|
139
|
+
storage.set(id, { lastRun: now });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (this.isAbortError(error)) {
|
|
144
|
+
this.shared.modules.logger.log(`Cron: Job ${id} was aborted.`);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
console.error(`Cron job ${id} failed:`, error);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (!this.isStopping) {
|
|
153
|
+
await this.syncWithStorage();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
138
156
|
/**
|
|
139
157
|
* Loads the persisted last run times for jobs from localStorage.
|
|
140
158
|
* @returns Map of job IDs to their last run times.
|
|
@@ -142,7 +160,11 @@ export class Cron {
|
|
|
142
160
|
async getStorageState() {
|
|
143
161
|
if (this.isStopping)
|
|
144
162
|
return new Map();
|
|
145
|
-
const
|
|
163
|
+
const storage = this.env.storage;
|
|
164
|
+
if (!storage) {
|
|
165
|
+
return new Map();
|
|
166
|
+
}
|
|
167
|
+
const state = storage.getItem(this.STORAGE_KEY);
|
|
146
168
|
return new Map(state ? JSON.parse(state) : []);
|
|
147
169
|
}
|
|
148
170
|
/**
|
|
@@ -151,7 +173,18 @@ export class Cron {
|
|
|
151
173
|
async syncWithStorage() {
|
|
152
174
|
if (this.isStopping)
|
|
153
175
|
return;
|
|
176
|
+
const storage = this.env.storage;
|
|
177
|
+
if (!storage) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
154
180
|
const state = Array.from(this.jobs.entries()).map(([id, job]) => [id, { lastRun: job.lastRun }]);
|
|
155
|
-
|
|
181
|
+
storage.setItem(this.STORAGE_KEY, JSON.stringify(state));
|
|
182
|
+
}
|
|
183
|
+
isAbortError(error) {
|
|
184
|
+
const domException = globalThis.DOMException;
|
|
185
|
+
if (domException && error instanceof domException) {
|
|
186
|
+
return error.name === 'AbortError';
|
|
187
|
+
}
|
|
188
|
+
return error?.name === 'AbortError';
|
|
156
189
|
}
|
|
157
190
|
}
|
|
@@ -4,8 +4,9 @@ import { Signatures } from '../signatures.js';
|
|
|
4
4
|
import * as Identity from '@0xsequence/identity-instrument';
|
|
5
5
|
import { IdentitySigner } from '../../identity/signer.js';
|
|
6
6
|
import { AuthCodeHandler } from './authcode.js';
|
|
7
|
+
import type { WdkEnv } from '../../env.js';
|
|
7
8
|
export declare class AuthCodePkceHandler extends AuthCodeHandler implements Handler {
|
|
8
|
-
constructor(signupKind: 'google-pkce' | `custom-${string}`, issuer: string, oauthUrl: string, audience: string, nitro: Identity.IdentityInstrument, signatures: Signatures, commitments: Db.AuthCommitments, authKeys: Db.AuthKeys);
|
|
9
|
+
constructor(signupKind: 'google-pkce' | `custom-${string}`, issuer: string, oauthUrl: string, audience: string, nitro: Identity.IdentityInstrument, signatures: Signatures, commitments: Db.AuthCommitments, authKeys: Db.AuthKeys, env?: WdkEnv);
|
|
9
10
|
commitAuth(target: string, isSignUp: boolean, state?: string, signer?: string): Promise<string>;
|
|
10
11
|
completeAuth(commitment: Db.AuthCommitment, code: string): Promise<[IdentitySigner, {
|
|
11
12
|
[key: string]: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authcode-pkce.d.ts","sourceRoot":"","sources":["../../../src/sequence/handlers/authcode-pkce.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,QAAQ,MAAM,iCAAiC,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"authcode-pkce.d.ts","sourceRoot":"","sources":["../../../src/sequence/handlers/authcode-pkce.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,QAAQ,MAAM,iCAAiC,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,qBAAa,mBAAoB,SAAQ,eAAgB,YAAW,OAAO;gBAEvE,UAAU,EAAE,aAAa,GAAG,UAAU,MAAM,EAAE,EAC9C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,QAAQ,CAAC,kBAAkB,EAClC,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,EAAE,CAAC,eAAe,EAC/B,QAAQ,EAAE,EAAE,CAAC,QAAQ,EACrB,GAAG,CAAC,EAAE,MAAM;IAKD,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAkC7E,YAAY,CACvB,UAAU,EAAE,EAAE,CAAC,cAAc,EAC7B,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,cAAc,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC,CAAC;CAWxD"}
|
|
@@ -2,8 +2,8 @@ import { Hex, Bytes } from 'ox';
|
|
|
2
2
|
import * as Identity from '@0xsequence/identity-instrument';
|
|
3
3
|
import { AuthCodeHandler } from './authcode.js';
|
|
4
4
|
export class AuthCodePkceHandler extends AuthCodeHandler {
|
|
5
|
-
constructor(signupKind, issuer, oauthUrl, audience, nitro, signatures, commitments, authKeys) {
|
|
6
|
-
super(signupKind, issuer, oauthUrl, audience, nitro, signatures, commitments, authKeys);
|
|
5
|
+
constructor(signupKind, issuer, oauthUrl, audience, nitro, signatures, commitments, authKeys, env) {
|
|
6
|
+
super(signupKind, issuer, oauthUrl, audience, nitro, signatures, commitments, authKeys, env);
|
|
7
7
|
}
|
|
8
8
|
async commitAuth(target, isSignUp, state, signer) {
|
|
9
9
|
let challenge = new Identity.AuthCodePkceChallenge(this.issuer, this.audience, this.redirectUri);
|
|
@@ -23,7 +23,7 @@ export class AuthCodePkceHandler extends AuthCodeHandler {
|
|
|
23
23
|
metadata: {},
|
|
24
24
|
isSignUp,
|
|
25
25
|
});
|
|
26
|
-
const searchParams =
|
|
26
|
+
const searchParams = this.serializeQuery({
|
|
27
27
|
code_challenge: codeChallenge,
|
|
28
28
|
code_challenge_method: 'S256',
|
|
29
29
|
client_id: this.audience,
|
|
@@ -33,7 +33,7 @@ export class AuthCodePkceHandler extends AuthCodeHandler {
|
|
|
33
33
|
scope: 'openid profile email',
|
|
34
34
|
state,
|
|
35
35
|
});
|
|
36
|
-
return `${this.oauthUrl}?${searchParams
|
|
36
|
+
return `${this.oauthUrl}?${searchParams}`;
|
|
37
37
|
}
|
|
38
38
|
async completeAuth(commitment, code) {
|
|
39
39
|
const challenge = new Identity.AuthCodePkceChallenge('', '', '');
|
|
@@ -6,6 +6,7 @@ import * as Identity from '@0xsequence/identity-instrument';
|
|
|
6
6
|
import { SignerUnavailable, SignerReady, SignerActionable, BaseSignatureRequest } from '../types/signature-request.js';
|
|
7
7
|
import { IdentitySigner } from '../../identity/signer.js';
|
|
8
8
|
import { IdentityHandler } from './identity.js';
|
|
9
|
+
import type { WdkEnv } from '../../env.js';
|
|
9
10
|
export declare class AuthCodeHandler extends IdentityHandler implements Handler {
|
|
10
11
|
readonly signupKind: 'apple' | 'google-pkce' | `custom-${string}`;
|
|
11
12
|
readonly issuer: string;
|
|
@@ -13,7 +14,7 @@ export declare class AuthCodeHandler extends IdentityHandler implements Handler
|
|
|
13
14
|
readonly audience: string;
|
|
14
15
|
protected readonly commitments: Db.AuthCommitments;
|
|
15
16
|
protected redirectUri: string;
|
|
16
|
-
constructor(signupKind: 'apple' | 'google-pkce' | `custom-${string}`, issuer: string, oauthUrl: string, audience: string, nitro: Identity.IdentityInstrument, signatures: Signatures, commitments: Db.AuthCommitments, authKeys: Db.AuthKeys);
|
|
17
|
+
constructor(signupKind: 'apple' | 'google-pkce' | `custom-${string}`, issuer: string, oauthUrl: string, audience: string, nitro: Identity.IdentityInstrument, signatures: Signatures, commitments: Db.AuthCommitments, authKeys: Db.AuthKeys, env?: WdkEnv);
|
|
17
18
|
get kind(): string;
|
|
18
19
|
setRedirectUri(redirectUri: string): void;
|
|
19
20
|
commitAuth(target: string, isSignUp: boolean, state?: string, signer?: string): Promise<string>;
|
|
@@ -21,5 +22,7 @@ export declare class AuthCodeHandler extends IdentityHandler implements Handler
|
|
|
21
22
|
[key: string]: string;
|
|
22
23
|
}]>;
|
|
23
24
|
status(address: Address.Address, _imageHash: Hex.Hex | undefined, request: BaseSignatureRequest): Promise<SignerUnavailable | SignerReady | SignerActionable>;
|
|
25
|
+
protected serializeQuery(params: Record<string, string>): string;
|
|
26
|
+
private getNavigation;
|
|
24
27
|
}
|
|
25
28
|
//# sourceMappingURL=authcode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authcode.d.ts","sourceRoot":"","sources":["../../../src/sequence/handlers/authcode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAS,MAAM,IAAI,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,QAAQ,MAAM,iCAAiC,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AACtH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OA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AC,EAAE,MAAM;IAKd,IAAW,IAAI,WAEd;IAEM,cAAc,CAAC,WAAW,EAAE,MAAM;IAI5B,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAyB7E,YAAY,CACvB,UAAU,EAAE,EAAE,CAAC,cAAc,EAC7B,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,cAAc,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC,CAAC;IAWjD,MAAM,CACV,OAAO,EAAE,OAAO,CAAC,OAAO,EACxB,UAAU,EAAE,GAAG,CAAC,GAAG,GAAG,SAAS,EAC/B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,iBAAiB,GAAG,WAAW,GAAG,gBAAgB,CAAC;IA4B9D,SAAS,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM;IAUhE,OAAO,CAAC,aAAa;CAOtB"}
|
|
@@ -8,8 +8,8 @@ export class AuthCodeHandler extends IdentityHandler {
|
|
|
8
8
|
audience;
|
|
9
9
|
commitments;
|
|
10
10
|
redirectUri = '';
|
|
11
|
-
constructor(signupKind, issuer, oauthUrl, audience, nitro, signatures, commitments, authKeys) {
|
|
12
|
-
super(nitro, authKeys, signatures, Identity.IdentityType.OIDC);
|
|
11
|
+
constructor(signupKind, issuer, oauthUrl, audience, nitro, signatures, commitments, authKeys, env) {
|
|
12
|
+
super(nitro, authKeys, signatures, Identity.IdentityType.OIDC, env);
|
|
13
13
|
this.signupKind = signupKind;
|
|
14
14
|
this.issuer = issuer;
|
|
15
15
|
this.oauthUrl = oauthUrl;
|
|
@@ -34,14 +34,14 @@ export class AuthCodeHandler extends IdentityHandler {
|
|
|
34
34
|
metadata: {},
|
|
35
35
|
isSignUp,
|
|
36
36
|
});
|
|
37
|
-
const searchParams =
|
|
37
|
+
const searchParams = this.serializeQuery({
|
|
38
38
|
client_id: this.audience,
|
|
39
39
|
redirect_uri: this.redirectUri,
|
|
40
40
|
response_type: 'code',
|
|
41
41
|
state,
|
|
42
42
|
...(this.signupKind === 'apple' ? {} : { scope: 'openid profile email' }),
|
|
43
43
|
});
|
|
44
|
-
return `${this.oauthUrl}?${searchParams
|
|
44
|
+
return `${this.oauthUrl}?${searchParams}`;
|
|
45
45
|
}
|
|
46
46
|
async completeAuth(commitment, code) {
|
|
47
47
|
let challenge = new Identity.AuthCodeChallenge(this.issuer, this.audience, this.redirectUri, code);
|
|
@@ -71,10 +71,27 @@ export class AuthCodeHandler extends IdentityHandler {
|
|
|
71
71
|
status: 'actionable',
|
|
72
72
|
message: 'request-redirect',
|
|
73
73
|
handle: async () => {
|
|
74
|
-
const
|
|
75
|
-
|
|
74
|
+
const navigation = this.getNavigation();
|
|
75
|
+
const url = await this.commitAuth(navigation.getPathname(), false, request.id, address);
|
|
76
|
+
navigation.redirect(url);
|
|
76
77
|
return true;
|
|
77
78
|
},
|
|
78
79
|
};
|
|
79
80
|
}
|
|
81
|
+
serializeQuery(params) {
|
|
82
|
+
const searchParamsCtor = this.env.urlSearchParams ?? globalThis.URLSearchParams;
|
|
83
|
+
if (searchParamsCtor) {
|
|
84
|
+
return new searchParamsCtor(params).toString();
|
|
85
|
+
}
|
|
86
|
+
return Object.entries(params)
|
|
87
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
88
|
+
.join('&');
|
|
89
|
+
}
|
|
90
|
+
getNavigation() {
|
|
91
|
+
const navigation = this.env.navigation;
|
|
92
|
+
if (!navigation) {
|
|
93
|
+
throw new Error('navigation is not available');
|
|
94
|
+
}
|
|
95
|
+
return navigation;
|
|
96
|
+
}
|
|
80
97
|
}
|
|
@@ -8,7 +8,7 @@ export declare class DevicesHandler implements Handler {
|
|
|
8
8
|
private readonly devices;
|
|
9
9
|
kind: "local-device";
|
|
10
10
|
constructor(signatures: Signatures, devices: Devices);
|
|
11
|
-
onStatusChange(
|
|
11
|
+
onStatusChange(_cb: () => void): () => void;
|
|
12
12
|
status(address: Address.Address, _imageHash: Hex.Hex | undefined, request: BaseSignatureRequest): Promise<SignerUnavailable | SignerReady>;
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=devices.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devices.d.ts","sourceRoot":"","sources":["../../../src/sequence/handlers/devices.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAExF,qBAAa,cAAe,YAAW,OAAO;IAI1C,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,IAAI,iBAAoB;gBAGL,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,OAAO;IAGnC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"devices.d.ts","sourceRoot":"","sources":["../../../src/sequence/handlers/devices.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAExF,qBAAa,cAAe,YAAW,OAAO;IAI1C,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,IAAI,iBAAoB;gBAGL,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,OAAO;IAGnC,cAAc,CAAC,GAAG,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAIrC,MAAM,CACV,OAAO,EAAE,OAAO,CAAC,OAAO,EACxB,UAAU,EAAE,GAAG,CAAC,GAAG,GAAG,SAAS,EAC/B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,iBAAiB,GAAG,WAAW,CAAC;CA6B5C"}
|
|
@@ -14,7 +14,7 @@ export declare class GuardHandler implements Handler {
|
|
|
14
14
|
constructor(signatures: Signatures, guards: Guards);
|
|
15
15
|
registerUI(onPromptCode: PromptCodeHandler): () => void;
|
|
16
16
|
unregisterUI(): void;
|
|
17
|
-
onStatusChange(
|
|
17
|
+
onStatusChange(_cb: () => void): () => void;
|
|
18
18
|
status(address: Address.Address, _imageHash: Hex.Hex | undefined, request: BaseSignatureRequest): Promise<SignerUnavailable | SignerReady | SignerActionable>;
|
|
19
19
|
}
|
|
20
20
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../../src/sequence/handlers/guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAA;AAEjC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,WAAW,EAAE,gBAAgB,EAAS,MAAM,mBAAmB,CAAA;AACjH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,KAAK,SAAS,GAAG,CAAC,KAAK,EAAE,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O,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IANzB,IAAI,oBAAc;IAElB,OAAO,CAAC,YAAY,CAA+B;gBAGhC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM;IAG1B,UAAU,CAAC,YAAY,EAAE,iBAAiB;IAO1C,YAAY;IAInB,cAAc,CAAC,GAAG,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAIrC,MAAM,CACV,OAAO,EAAE,OAAO,CAAC,OAAO,EACxB,UAAU,EAAE,GAAG,CAAC,GAAG,GAAG,SAAS,EAC/B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,iBAAiB,GAAG,WAAW,GAAG,gBAAgB,CAAC;CAoE/D"}
|
|
@@ -18,7 +18,7 @@ export class GuardHandler {
|
|
|
18
18
|
unregisterUI() {
|
|
19
19
|
this.onPromptCode = undefined;
|
|
20
20
|
}
|
|
21
|
-
onStatusChange(
|
|
21
|
+
onStatusChange(_cb) {
|
|
22
22
|
return () => { };
|
|
23
23
|
}
|
|
24
24
|
async status(address, _imageHash, request) {
|
|
@@ -61,26 +61,29 @@ export class GuardHandler {
|
|
|
61
61
|
address,
|
|
62
62
|
handler: this,
|
|
63
63
|
status: 'ready',
|
|
64
|
-
handle: () =>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (e instanceof Guard.AuthRequiredError) {
|
|
72
|
-
const respond = async (token) => {
|
|
73
|
-
const signature = await guard.signEnvelope(request.envelope, token);
|
|
74
|
-
await this.signatures.addSignature(request.id, signature);
|
|
75
|
-
resolve(true);
|
|
76
|
-
};
|
|
77
|
-
await onPromptCode(request, e.id, respond);
|
|
64
|
+
handle: () => {
|
|
65
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
66
|
+
return new Promise(async (resolve, reject) => {
|
|
67
|
+
try {
|
|
68
|
+
const signature = await guard.signEnvelope(request.envelope);
|
|
69
|
+
await this.signatures.addSignature(request.id, signature);
|
|
70
|
+
resolve(true);
|
|
78
71
|
}
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
catch (e) {
|
|
73
|
+
if (e instanceof Guard.AuthRequiredError) {
|
|
74
|
+
const respond = async (token) => {
|
|
75
|
+
const signature = await guard.signEnvelope(request.envelope, token);
|
|
76
|
+
await this.signatures.addSignature(request.id, signature);
|
|
77
|
+
resolve(true);
|
|
78
|
+
};
|
|
79
|
+
await onPromptCode(request, e.id, respond);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
reject(e);
|
|
83
|
+
}
|
|
81
84
|
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
85
|
+
});
|
|
86
|
+
},
|
|
84
87
|
};
|
|
85
88
|
}
|
|
86
89
|
}
|
|
@@ -4,13 +4,15 @@ import * as Identity from '@0xsequence/identity-instrument';
|
|
|
4
4
|
import { Signatures } from '../signatures.js';
|
|
5
5
|
import { BaseSignatureRequest } from '../types/signature-request.js';
|
|
6
6
|
import { IdentitySigner } from '../../identity/signer.js';
|
|
7
|
+
import { type WdkEnv } from '../../env.js';
|
|
7
8
|
export declare const identityTypeToHex: (identityType?: Identity.IdentityType) => Hex.Hex;
|
|
8
9
|
export declare class IdentityHandler {
|
|
9
10
|
private readonly nitro;
|
|
10
11
|
private readonly authKeys;
|
|
11
12
|
private readonly signatures;
|
|
12
13
|
readonly identityType: Identity.IdentityType;
|
|
13
|
-
|
|
14
|
+
protected readonly env: WdkEnv;
|
|
15
|
+
constructor(nitro: Identity.IdentityInstrument, authKeys: Db.AuthKeys, signatures: Signatures, identityType: Identity.IdentityType, env?: WdkEnv);
|
|
14
16
|
onStatusChange(cb: () => void): () => void;
|
|
15
17
|
protected nitroCommitVerifier(challenge: Identity.Challenge): Promise<Identity.Client.CommitVerifierReturn>;
|
|
16
18
|
protected nitroCompleteAuth(challenge: Identity.Challenge): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../src/sequence/handlers/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../src/sequence/handlers/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,KAAK,QAAQ,MAAM,iCAAiC,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,EAAE,cAAc,EAAqB,MAAM,0BAA0B,CAAA;AAC5E,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,cAAc,CAAA;AAEzD,eAAO,MAAM,iBAAiB,GAAI,eAAe,QAAQ,CAAC,YAAY,KAAG,GAAG,CAAC,GAW5E,CAAA;AAED,qBAAa,eAAe;IAIxB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,UAAU;aACX,YAAY,EAAE,QAAQ,CAAC,YAAY;IANrD,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;gBAGX,KAAK,EAAE,QAAQ,CAAC,kBAAkB,EAClC,QAAQ,EAAE,EAAE,CAAC,QAAQ,EACrB,UAAU,EAAE,UAAU,EACvB,YAAY,EAAE,QAAQ,CAAC,YAAY,EACnD,GAAG,CAAC,EAAE,MAAM;IAKP,cAAc,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;cAIjC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS;cAWjD,iBAAiB,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS;;;;cAkB/C,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,oBAAoB;cAQ1D,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;YAQxE,UAAU;CA0BzB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Hex } from 'ox';
|
|
2
2
|
import * as Identity from '@0xsequence/identity-instrument';
|
|
3
3
|
import { IdentitySigner, toIdentityAuthKey } from '../../identity/signer.js';
|
|
4
|
+
import { resolveWdkEnv } from '../../env.js';
|
|
4
5
|
export const identityTypeToHex = (identityType) => {
|
|
5
6
|
// Bytes4
|
|
6
7
|
switch (identityType) {
|
|
@@ -18,11 +19,13 @@ export class IdentityHandler {
|
|
|
18
19
|
authKeys;
|
|
19
20
|
signatures;
|
|
20
21
|
identityType;
|
|
21
|
-
|
|
22
|
+
env;
|
|
23
|
+
constructor(nitro, authKeys, signatures, identityType, env) {
|
|
22
24
|
this.nitro = nitro;
|
|
23
25
|
this.authKeys = authKeys;
|
|
24
26
|
this.signatures = signatures;
|
|
25
27
|
this.identityType = identityType;
|
|
28
|
+
this.env = resolveWdkEnv(env);
|
|
26
29
|
}
|
|
27
30
|
onStatusChange(cb) {
|
|
28
31
|
return this.authKeys.addListener(cb);
|
|
@@ -33,7 +36,7 @@ export class IdentityHandler {
|
|
|
33
36
|
if (!authKey) {
|
|
34
37
|
throw new Error('no-auth-key');
|
|
35
38
|
}
|
|
36
|
-
const res = await this.nitro.commitVerifier(toIdentityAuthKey(authKey), challenge);
|
|
39
|
+
const res = await this.nitro.commitVerifier(toIdentityAuthKey(authKey, this.env.crypto), challenge);
|
|
37
40
|
return res;
|
|
38
41
|
}
|
|
39
42
|
async nitroCompleteAuth(challenge) {
|
|
@@ -41,13 +44,13 @@ export class IdentityHandler {
|
|
|
41
44
|
if (!authKey) {
|
|
42
45
|
throw new Error('no-auth-key');
|
|
43
46
|
}
|
|
44
|
-
const res = await this.nitro.completeAuth(toIdentityAuthKey(authKey), challenge);
|
|
47
|
+
const res = await this.nitro.completeAuth(toIdentityAuthKey(authKey, this.env.crypto), challenge);
|
|
45
48
|
authKey.identitySigner = res.signer.address;
|
|
46
49
|
authKey.expiresAt = new Date(Date.now() + 1000 * 60 * 3); // 3 minutes
|
|
47
50
|
await this.authKeys.delBySigner('');
|
|
48
51
|
await this.authKeys.delBySigner(authKey.identitySigner);
|
|
49
52
|
await this.authKeys.set(authKey);
|
|
50
|
-
const signer = new IdentitySigner(this.nitro, authKey);
|
|
53
|
+
const signer = new IdentitySigner(this.nitro, authKey, this.env.crypto);
|
|
51
54
|
return { signer, email: res.identity.email };
|
|
52
55
|
}
|
|
53
56
|
async sign(signer, request) {
|
|
@@ -62,16 +65,20 @@ export class IdentityHandler {
|
|
|
62
65
|
if (!authKey) {
|
|
63
66
|
return undefined;
|
|
64
67
|
}
|
|
65
|
-
return new IdentitySigner(this.nitro, authKey);
|
|
68
|
+
return new IdentitySigner(this.nitro, authKey, this.env.crypto);
|
|
66
69
|
}
|
|
67
70
|
async getAuthKey(signer) {
|
|
68
71
|
let authKey = await this.authKeys.getBySigner(signer);
|
|
69
72
|
if (!signer && !authKey) {
|
|
70
|
-
const
|
|
73
|
+
const crypto = this.env.crypto ?? globalThis.crypto;
|
|
74
|
+
if (!crypto?.subtle) {
|
|
75
|
+
throw new Error('crypto.subtle is not available');
|
|
76
|
+
}
|
|
77
|
+
const keyPair = await crypto.subtle.generateKey({
|
|
71
78
|
name: 'ECDSA',
|
|
72
79
|
namedCurve: 'P-256',
|
|
73
80
|
}, false, ['sign', 'verify']);
|
|
74
|
-
const publicKey = await
|
|
81
|
+
const publicKey = await crypto.subtle.exportKey('raw', keyPair.publicKey);
|
|
75
82
|
authKey = {
|
|
76
83
|
address: Hex.fromBytes(new Uint8Array(publicKey)),
|
|
77
84
|
identitySigner: '',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mnemonic.d.ts","sourceRoot":"","sources":["../../../src/sequence/handlers/mnemonic.ts"],"names":[],"m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ic',
|
|
70
|
-
handle: () =>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
70
|
+
handle: () => {
|
|
71
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
72
|
+
return new Promise(async (resolve, reject) => {
|
|
73
|
+
const respond = async (mnemonic) => {
|
|
74
|
+
const signer = MnemonicHandler.toSigner(mnemonic);
|
|
75
|
+
if (!signer) {
|
|
76
|
+
return reject('invalid-mnemonic');
|
|
77
|
+
}
|
|
78
|
+
if (!Address.isEqual(signer.address, address)) {
|
|
79
|
+
return reject('wrong-mnemonic');
|
|
80
|
+
}
|
|
81
|
+
const signature = await signer.sign(request.envelope.wallet, request.envelope.chainId, request.envelope.payload);
|
|
82
|
+
await this.signatures.addSignature(request.id, {
|
|
83
|
+
address,
|
|
84
|
+
signature,
|
|
85
|
+
});
|
|
86
|
+
resolve(true);
|
|
87
|
+
};
|
|
88
|
+
await onPromptMnemonic(respond);
|
|
89
|
+
});
|
|
90
|
+
},
|
|
88
91
|
};
|
|
89
92
|
}
|
|
90
93
|
}
|
|
@@ -6,12 +6,13 @@ import * as Db from '../../dbs/index.js';
|
|
|
6
6
|
import { Signatures } from '../signatures.js';
|
|
7
7
|
import { SignerUnavailable, SignerReady, SignerActionable, BaseSignatureRequest } from '../types/signature-request.js';
|
|
8
8
|
import { IdentityHandler } from './identity.js';
|
|
9
|
+
import type { WdkEnv } from '../../env.js';
|
|
9
10
|
type RespondFn = (otp: string) => Promise<void>;
|
|
10
11
|
export type PromptOtpHandler = (recipient: string, respond: RespondFn) => Promise<void>;
|
|
11
12
|
export declare class OtpHandler extends IdentityHandler implements Handler {
|
|
12
13
|
kind: "login-email-otp";
|
|
13
14
|
private onPromptOtp;
|
|
14
|
-
constructor(nitro: Identity.IdentityInstrument, signatures: Signatures, authKeys: Db.AuthKeys);
|
|
15
|
+
constructor(nitro: Identity.IdentityInstrument, signatures: Signatures, authKeys: Db.AuthKeys, env?: WdkEnv);
|
|
15
16
|
registerUI(onPromptOtp: PromptOtpHandler): () => void;
|
|
16
17
|
unregisterUI(): void;
|
|
17
18
|
getSigner(email: string): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otp.d.ts","sourceRoot":"","sources":["../../../src/sequence/handlers/otp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,IAAI,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACjD,OAAO,KAAK,QAAQ,MAAM,iCAAiC,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AAEtH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"otp.d.ts","sourceRoot":"","sources":["../../../src/sequence/handlers/otp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,IAAI,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACjD,OAAO,KAAK,QAAQ,MAAM,iCAAiC,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AAEtH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,KAAK,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAE/C,MAAM,MAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAEvF,qBAAa,UAAW,SAAQ,eAAgB,YAAW,OAAO;IAChE,IAAI,oBAAsB;IAE1B,OAAO,CAAC,WAAW,CAA8B;gBAErC,KAAK,EAAE,QAAQ,CAAC,kBAAkB,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,MAAM;IAIpG,UAAU,CAAC,WAAW,EAAE,gBAAgB;IAOxC,YAAY;IAIN,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAUzG,MAAM,CACV,OAAO,EAAE,OAAO,CAAC,OAAO,EACxB,UAAU,EAAE,GAAG,CAAC,GAAG,GAAG,SAAS,EAC/B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,iBAAiB,GAAG,WAAW,GAAG,gBAAgB,CAAC;IA4C9D,OAAO,CAAC,UAAU;CAqCnB"}
|
|
@@ -5,8 +5,8 @@ import { AnswerIncorrectError, ChallengeExpiredError, TooManyAttemptsError } fro
|
|
|
5
5
|
export class OtpHandler extends IdentityHandler {
|
|
6
6
|
kind = Kinds.LoginEmailOtp;
|
|
7
7
|
onPromptOtp;
|
|
8
|
-
constructor(nitro, signatures, authKeys) {
|
|
9
|
-
super(nitro, authKeys, signatures, Identity.IdentityType.Email);
|
|
8
|
+
constructor(nitro, signatures, authKeys, env) {
|
|
9
|
+
super(nitro, authKeys, signatures, Identity.IdentityType.Email, env);
|
|
10
10
|
}
|
|
11
11
|
registerUI(onPromptOtp) {
|
|
12
12
|
this.onPromptOtp = onPromptOtp;
|
|
@@ -61,13 +61,14 @@ export class OtpHandler extends IdentityHandler {
|
|
|
61
61
|
await this.handleAuth(challenge, onPromptOtp);
|
|
62
62
|
return true;
|
|
63
63
|
}
|
|
64
|
-
catch
|
|
64
|
+
catch {
|
|
65
65
|
return false;
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
handleAuth(challenge, onPromptOtp) {
|
|
71
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
71
72
|
return new Promise(async (resolve, reject) => {
|
|
72
73
|
try {
|
|
73
74
|
const { loginHint, challenge: codeChallenge } = await this.nitroCommitVerifier(challenge);
|