@tatchi-xyz/sdk 0.19.0 → 0.20.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/dist/cjs/core/EmailRecovery/index.js +25 -0
- package/dist/cjs/core/EmailRecovery/index.js.map +1 -1
- package/dist/cjs/core/TatchiPasskey/emailRecovery.js +70 -34
- package/dist/cjs/core/TatchiPasskey/emailRecovery.js.map +1 -1
- package/dist/cjs/core/types/emailRecovery.js +33 -0
- package/dist/cjs/core/types/emailRecovery.js.map +1 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react/components/AccountMenuButton/{LinkedDevicesModal-CSSowiHP.css → LinkedDevicesModal-BCrFe5p3.css} +1 -1
- package/dist/{esm/react/components/AccountMenuButton/LinkedDevicesModal-CSSowiHP.css.map → cjs/react/components/AccountMenuButton/LinkedDevicesModal-BCrFe5p3.css.map} +1 -1
- package/dist/cjs/react/components/AccountMenuButton/{ProfileDropdown-CEPMZ1gY.css → ProfileDropdown-CRJrtxDb.css} +1 -1
- package/dist/{esm/react/components/AccountMenuButton/ProfileDropdown-CEPMZ1gY.css.map → cjs/react/components/AccountMenuButton/ProfileDropdown-CRJrtxDb.css.map} +1 -1
- package/dist/cjs/react/components/AccountMenuButton/{Web3AuthProfileButton-DopOg7Xc.css → Web3AuthProfileButton-DXFRw8ND.css} +1 -1
- package/dist/cjs/react/components/AccountMenuButton/{Web3AuthProfileButton-DopOg7Xc.css.map → Web3AuthProfileButton-DXFRw8ND.css.map} +1 -1
- package/dist/cjs/react/components/AccountMenuButton/icons/{TouchIcon-BQWentvJ.css → TouchIcon-DNgbAK_i.css} +1 -1
- package/dist/cjs/react/components/AccountMenuButton/icons/{TouchIcon-BQWentvJ.css.map → TouchIcon-DNgbAK_i.css.map} +1 -1
- package/dist/cjs/react/components/PasskeyAuthMenu/{PasskeyAuthMenu-DwrzWMYx.css → PasskeyAuthMenu-DRwSoF8q.css} +1 -1
- package/dist/cjs/react/components/PasskeyAuthMenu/{PasskeyAuthMenu-DwrzWMYx.css.map → PasskeyAuthMenu-DRwSoF8q.css.map} +1 -1
- package/dist/cjs/react/components/PasskeyAuthMenu/ui/EmailRecoverySlide.js +107 -21
- package/dist/cjs/react/components/PasskeyAuthMenu/ui/EmailRecoverySlide.js.map +1 -1
- package/dist/cjs/react/components/{ShowQRCode-CCN4h6Uv.css → ShowQRCode-CL4gsszN.css} +1 -1
- package/dist/cjs/react/components/{ShowQRCode-CCN4h6Uv.css.map → ShowQRCode-CL4gsszN.css.map} +1 -1
- package/dist/cjs/react/sdk/src/core/EmailRecovery/index.js +25 -0
- package/dist/cjs/react/sdk/src/core/EmailRecovery/index.js.map +1 -1
- package/dist/cjs/react/sdk/src/core/TatchiPasskey/emailRecovery.js +70 -34
- package/dist/cjs/react/sdk/src/core/TatchiPasskey/emailRecovery.js.map +1 -1
- package/dist/cjs/react/sdk/src/core/types/emailRecovery.js +33 -0
- package/dist/cjs/react/sdk/src/core/types/emailRecovery.js.map +1 -0
- package/dist/esm/core/EmailRecovery/index.js +25 -1
- package/dist/esm/core/EmailRecovery/index.js.map +1 -1
- package/dist/esm/core/TatchiPasskey/emailRecovery.js +71 -35
- package/dist/esm/core/TatchiPasskey/emailRecovery.js.map +1 -1
- package/dist/esm/core/types/emailRecovery.js +26 -0
- package/dist/esm/core/types/emailRecovery.js.map +1 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/react/components/AccountMenuButton/{LinkedDevicesModal-CSSowiHP.css → LinkedDevicesModal-BCrFe5p3.css} +1 -1
- package/dist/{cjs/react/components/AccountMenuButton/LinkedDevicesModal-CSSowiHP.css.map → esm/react/components/AccountMenuButton/LinkedDevicesModal-BCrFe5p3.css.map} +1 -1
- package/dist/esm/react/components/AccountMenuButton/{ProfileDropdown-CEPMZ1gY.css → ProfileDropdown-CRJrtxDb.css} +1 -1
- package/dist/{cjs/react/components/AccountMenuButton/ProfileDropdown-CEPMZ1gY.css.map → esm/react/components/AccountMenuButton/ProfileDropdown-CRJrtxDb.css.map} +1 -1
- package/dist/esm/react/components/AccountMenuButton/{Web3AuthProfileButton-DopOg7Xc.css → Web3AuthProfileButton-DXFRw8ND.css} +1 -1
- package/dist/esm/react/components/AccountMenuButton/{Web3AuthProfileButton-DopOg7Xc.css.map → Web3AuthProfileButton-DXFRw8ND.css.map} +1 -1
- package/dist/esm/react/components/AccountMenuButton/icons/{TouchIcon-BQWentvJ.css → TouchIcon-DNgbAK_i.css} +1 -1
- package/dist/esm/react/components/AccountMenuButton/icons/{TouchIcon-BQWentvJ.css.map → TouchIcon-DNgbAK_i.css.map} +1 -1
- package/dist/esm/react/components/PasskeyAuthMenu/{PasskeyAuthMenu-DwrzWMYx.css → PasskeyAuthMenu-DRwSoF8q.css} +1 -1
- package/dist/esm/react/components/PasskeyAuthMenu/{PasskeyAuthMenu-DwrzWMYx.css.map → PasskeyAuthMenu-DRwSoF8q.css.map} +1 -1
- package/dist/esm/react/components/PasskeyAuthMenu/ui/EmailRecoverySlide.js +107 -21
- package/dist/esm/react/components/PasskeyAuthMenu/ui/EmailRecoverySlide.js.map +1 -1
- package/dist/esm/react/components/{ShowQRCode-CCN4h6Uv.css → ShowQRCode-CL4gsszN.css} +1 -1
- package/dist/esm/react/components/{ShowQRCode-CCN4h6Uv.css.map → ShowQRCode-CL4gsszN.css.map} +1 -1
- package/dist/esm/react/sdk/src/core/EmailRecovery/index.js +25 -1
- package/dist/esm/react/sdk/src/core/EmailRecovery/index.js.map +1 -1
- package/dist/esm/react/sdk/src/core/TatchiPasskey/emailRecovery.js +71 -35
- package/dist/esm/react/sdk/src/core/TatchiPasskey/emailRecovery.js.map +1 -1
- package/dist/esm/react/sdk/src/core/types/emailRecovery.js +26 -0
- package/dist/esm/react/sdk/src/core/types/emailRecovery.js.map +1 -0
- package/dist/esm/sdk/wallet-iframe-host.js +111 -33
- package/dist/esm/wasm_vrf_worker/pkg/wasm_vrf_worker_bg.wasm +0 -0
- package/dist/types/src/core/EmailRecovery/index.d.ts +8 -0
- package/dist/types/src/core/EmailRecovery/index.d.ts.map +1 -1
- package/dist/types/src/core/TatchiPasskey/emailRecovery.d.ts +3 -1
- package/dist/types/src/core/TatchiPasskey/emailRecovery.d.ts.map +1 -1
- package/dist/types/src/core/types/emailRecovery.d.ts +10 -0
- package/dist/types/src/core/types/emailRecovery.d.ts.map +1 -0
- package/dist/types/src/core/types/index.d.ts +1 -0
- package/dist/types/src/core/types/index.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/react/components/PasskeyAuthMenu/ui/EmailRecoverySlide.d.ts.map +1 -1
- package/dist/workers/wasm_vrf_worker_bg.wasm +0 -0
- package/package.json +1 -1
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
|
|
2
2
|
const require_accountIds = require('../types/accountIds.js');
|
|
3
3
|
const require_index = require('../IndexedDBManager/index.js');
|
|
4
|
+
const require_base64 = require('../../utils/base64.js');
|
|
4
5
|
const require_emailRecoveryPendingStore = require('./emailRecoveryPendingStore.js');
|
|
5
6
|
|
|
6
7
|
//#region src/core/EmailRecovery/index.ts
|
|
8
|
+
function getTxSuccessValueBase64(outcome) {
|
|
9
|
+
const status = outcome.status;
|
|
10
|
+
if (!status || typeof status !== "object") return null;
|
|
11
|
+
if (!("SuccessValue" in status)) return null;
|
|
12
|
+
const value = status.SuccessValue;
|
|
13
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
14
|
+
}
|
|
15
|
+
function parseLinkDeviceRegisterUserResponse(outcome) {
|
|
16
|
+
try {
|
|
17
|
+
const successValueB64 = getTxSuccessValueBase64(outcome);
|
|
18
|
+
if (!successValueB64) return null;
|
|
19
|
+
const bytes = require_base64.base64Decode(successValueB64);
|
|
20
|
+
const text = new TextDecoder().decode(bytes);
|
|
21
|
+
if (!text.trim()) return null;
|
|
22
|
+
const parsed = JSON.parse(text);
|
|
23
|
+
if (!parsed || typeof parsed !== "object") return null;
|
|
24
|
+
const candidate = parsed;
|
|
25
|
+
return typeof candidate.verified === "boolean" ? candidate : null;
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
7
30
|
async function hashRecoveryEmails(emails, accountId) {
|
|
8
31
|
const encoder = new TextEncoder();
|
|
9
32
|
const salt = (accountId || "").trim().toLowerCase();
|
|
@@ -54,6 +77,7 @@ var canonicalizeEmail, bytesToHex;
|
|
|
54
77
|
var init_EmailRecovery = require_rolldown_runtime.__esm({ "src/core/EmailRecovery/index.ts": (() => {
|
|
55
78
|
require_accountIds.init_accountIds();
|
|
56
79
|
require_index.init_IndexedDBManager();
|
|
80
|
+
require_base64.init_base64();
|
|
57
81
|
require_emailRecoveryPendingStore.init_emailRecoveryPendingStore();
|
|
58
82
|
canonicalizeEmail = (email) => {
|
|
59
83
|
const raw = String(email || "").trim();
|
|
@@ -85,5 +109,6 @@ Object.defineProperty(exports, 'init_EmailRecovery', {
|
|
|
85
109
|
return init_EmailRecovery;
|
|
86
110
|
}
|
|
87
111
|
});
|
|
112
|
+
exports.parseLinkDeviceRegisterUserResponse = parseLinkDeviceRegisterUserResponse;
|
|
88
113
|
exports.prepareRecoveryEmails = prepareRecoveryEmails;
|
|
89
114
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["hashed: number[][]","toAccountId","pairs: RecoveryEmailEntry[]","IndexedDBManager"],"sources":["../../../../src/core/EmailRecovery/index.ts"],"sourcesContent":["import type { AccountId } from '../types/accountIds';\nimport { toAccountId } from '../types/accountIds';\nimport { IndexedDBManager, type RecoveryEmailRecord } from '../IndexedDBManager';\nexport { EmailRecoveryPendingStore, type PendingStore } from './emailRecoveryPendingStore';\n\nexport type RecoveryEmailEntry = {\n hashHex: string;\n email: string;\n};\n\nexport { type RecoveryEmailRecord };\n\nexport const canonicalizeEmail = (email: string): string => {\n const raw = String(email || '').trim();\n if (!raw) return '';\n\n // Handle cases where a full header line is passed in (e.g. \"From: ...\").\n const withoutHeaderName = raw.replace(/^[a-z0-9-]+\\s*:\\s*/i, '').trim();\n\n const emailRegex =\n /([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*)/;\n\n // Prefer the common \"Name <email@domain>\" format when present, but still\n // validate/extract the actual address via regex.\n const angleMatch = withoutHeaderName.match(/<([^>]+)>/);\n const candidates = [\n angleMatch?.[1],\n withoutHeaderName,\n ].filter((v): v is string => typeof v === 'string' && v.length > 0);\n\n for (const candidate of candidates) {\n const cleaned = candidate.replace(/^mailto:\\s*/i, '');\n const match = cleaned.match(emailRegex);\n if (match?.[1]) {\n return match[1].trim().toLowerCase();\n }\n }\n\n return withoutHeaderName.toLowerCase();\n};\n\nexport const bytesToHex = (bytes: number[] | Uint8Array): string => {\n const arr = bytes instanceof Uint8Array ? bytes : Uint8Array.from(bytes);\n return `0x${Array.from(arr)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('')}`;\n};\n\nasync function hashRecoveryEmails(emails: string[], accountId: AccountId): Promise<number[][]> {\n const encoder = new TextEncoder();\n const salt = (accountId || '').trim().toLowerCase();\n const normalized = (emails || [])\n .map(e => e.trim())\n .filter(e => e.length > 0);\n\n const hashed: number[][] = [];\n\n for (const email of normalized) {\n try {\n const canonicalEmail = canonicalizeEmail(email);\n const input = `${canonicalEmail}|${salt}`;\n const data = encoder.encode(input);\n const digest = await crypto.subtle.digest('SHA-256', data);\n const bytes = new Uint8Array(digest);\n hashed.push(Array.from(bytes));\n } catch {\n const bytes = encoder.encode(email.toLowerCase());\n hashed.push(Array.from(bytes));\n }\n }\n\n return hashed;\n}\n\n/**\n * Canonicalize and hash recovery emails for an account, and persist the mapping\n * (hashHex → canonical email) in IndexedDB on a best-effort basis.\n */\nexport async function prepareRecoveryEmails(nearAccountId: AccountId, recoveryEmails: string[]): Promise<{\n hashes: number[][];\n pairs: RecoveryEmailEntry[];\n}> {\n const accountId = toAccountId(nearAccountId);\n\n const trimmedEmails = (recoveryEmails || []).map(e => e.trim()).filter(e => e.length > 0);\n const canonicalEmails = trimmedEmails.map(canonicalizeEmail);\n const recoveryEmailHashes = await hashRecoveryEmails(recoveryEmails, accountId);\n\n const pairs: RecoveryEmailEntry[] = recoveryEmailHashes.map((hashBytes, idx) => ({\n hashHex: bytesToHex(hashBytes),\n email: canonicalEmails[idx],\n }));\n\n void (async () => {\n try {\n await IndexedDBManager.upsertRecoveryEmails(accountId, pairs);\n } catch (error) {\n console.warn('[EmailRecovery] Failed to persist local recovery emails', error);\n }\n })();\n\n return { hashes: recoveryEmailHashes, pairs };\n}\n\nexport async function getLocalRecoveryEmails(nearAccountId: AccountId): Promise<RecoveryEmailRecord[]> {\n return IndexedDBManager.getRecoveryEmails(nearAccountId);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["base64Decode","hashed: number[][]","toAccountId","pairs: RecoveryEmailEntry[]","IndexedDBManager"],"sources":["../../../../src/core/EmailRecovery/index.ts"],"sourcesContent":["import type { AccountId } from '../types/accountIds';\nimport { toAccountId } from '../types/accountIds';\nimport { IndexedDBManager, type RecoveryEmailRecord } from '../IndexedDBManager';\nimport type { FinalExecutionOutcome } from '@near-js/types';\nimport { base64Decode } from '../../utils/base64';\nexport { EmailRecoveryPendingStore, type PendingStore } from './emailRecoveryPendingStore';\n\nexport type RecoveryEmailEntry = {\n hashHex: string;\n email: string;\n};\n\nexport { type RecoveryEmailRecord };\n\nexport type LinkDeviceRegisterUserResponse = {\n verified?: boolean;\n registration_info?: unknown;\n registrationInfo?: unknown;\n error?: unknown;\n};\n\nfunction getTxSuccessValueBase64(outcome: FinalExecutionOutcome): string | null {\n const status = outcome.status;\n if (!status || typeof status !== 'object') return null;\n if (!('SuccessValue' in status)) return null;\n const value = status.SuccessValue;\n return typeof value === 'string' && value.length > 0 ? value : null;\n}\n\nexport function parseLinkDeviceRegisterUserResponse(\n outcome: FinalExecutionOutcome\n): LinkDeviceRegisterUserResponse | null {\n try {\n const successValueB64 = getTxSuccessValueBase64(outcome);\n if (!successValueB64) return null;\n\n const bytes = base64Decode(successValueB64);\n const text = new TextDecoder().decode(bytes);\n if (!text.trim()) return null;\n\n const parsed = JSON.parse(text) as unknown;\n if (!parsed || typeof parsed !== 'object') return null;\n const candidate = parsed as LinkDeviceRegisterUserResponse;\n return typeof candidate.verified === 'boolean' ? candidate : null;\n } catch {\n return null;\n }\n}\n\nexport const canonicalizeEmail = (email: string): string => {\n const raw = String(email || '').trim();\n if (!raw) return '';\n\n // Handle cases where a full header line is passed in (e.g. \"From: ...\").\n const withoutHeaderName = raw.replace(/^[a-z0-9-]+\\s*:\\s*/i, '').trim();\n\n const emailRegex =\n /([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*)/;\n\n // Prefer the common \"Name <email@domain>\" format when present, but still\n // validate/extract the actual address via regex.\n const angleMatch = withoutHeaderName.match(/<([^>]+)>/);\n const candidates = [\n angleMatch?.[1],\n withoutHeaderName,\n ].filter((v): v is string => typeof v === 'string' && v.length > 0);\n\n for (const candidate of candidates) {\n const cleaned = candidate.replace(/^mailto:\\s*/i, '');\n const match = cleaned.match(emailRegex);\n if (match?.[1]) {\n return match[1].trim().toLowerCase();\n }\n }\n\n return withoutHeaderName.toLowerCase();\n};\n\nexport const bytesToHex = (bytes: number[] | Uint8Array): string => {\n const arr = bytes instanceof Uint8Array ? bytes : Uint8Array.from(bytes);\n return `0x${Array.from(arr)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('')}`;\n};\n\nasync function hashRecoveryEmails(emails: string[], accountId: AccountId): Promise<number[][]> {\n const encoder = new TextEncoder();\n const salt = (accountId || '').trim().toLowerCase();\n const normalized = (emails || [])\n .map(e => e.trim())\n .filter(e => e.length > 0);\n\n const hashed: number[][] = [];\n\n for (const email of normalized) {\n try {\n const canonicalEmail = canonicalizeEmail(email);\n const input = `${canonicalEmail}|${salt}`;\n const data = encoder.encode(input);\n const digest = await crypto.subtle.digest('SHA-256', data);\n const bytes = new Uint8Array(digest);\n hashed.push(Array.from(bytes));\n } catch {\n const bytes = encoder.encode(email.toLowerCase());\n hashed.push(Array.from(bytes));\n }\n }\n\n return hashed;\n}\n\n/**\n * Canonicalize and hash recovery emails for an account, and persist the mapping\n * (hashHex → canonical email) in IndexedDB on a best-effort basis.\n */\nexport async function prepareRecoveryEmails(nearAccountId: AccountId, recoveryEmails: string[]): Promise<{\n hashes: number[][];\n pairs: RecoveryEmailEntry[];\n}> {\n const accountId = toAccountId(nearAccountId);\n\n const trimmedEmails = (recoveryEmails || []).map(e => e.trim()).filter(e => e.length > 0);\n const canonicalEmails = trimmedEmails.map(canonicalizeEmail);\n const recoveryEmailHashes = await hashRecoveryEmails(recoveryEmails, accountId);\n\n const pairs: RecoveryEmailEntry[] = recoveryEmailHashes.map((hashBytes, idx) => ({\n hashHex: bytesToHex(hashBytes),\n email: canonicalEmails[idx],\n }));\n\n void (async () => {\n try {\n await IndexedDBManager.upsertRecoveryEmails(accountId, pairs);\n } catch (error) {\n console.warn('[EmailRecovery] Failed to persist local recovery emails', error);\n }\n })();\n\n return { hashes: recoveryEmailHashes, pairs };\n}\n\nexport async function getLocalRecoveryEmails(nearAccountId: AccountId): Promise<RecoveryEmailRecord[]> {\n return IndexedDBManager.getRecoveryEmails(nearAccountId);\n}\n"],"mappings":";;;;;;;AAqBA,SAAS,wBAAwB,SAA+C;CAC9E,MAAM,SAAS,QAAQ;AACvB,KAAI,CAAC,UAAU,OAAO,WAAW,SAAU,QAAO;AAClD,KAAI,EAAE,kBAAkB,QAAS,QAAO;CACxC,MAAM,QAAQ,OAAO;AACrB,QAAO,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ;;AAGjE,SAAgB,oC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AAMC,+BAAiB,qBAAqB,WAAW;WAChD,OAAO;AACd,WAAQ,KAAK,2DAA2D;;;AAI5E,QAAO;EAAE,QAAQ;EAAqB;;;AAGxC,eAAsB,uBAAuB,eAA0D;AACrG,QAAOA,+BAAiB,kBAAkB;;;;;;;;CA7F/B,qBAAqB,UAA0B;EAC1D,MAAM,MAAM,OAAO,SAAS,IAAI;AAChC,MAAI,CAAC,IAAK,QAAO;EAGjB,MAAM,oBAAoB,IAAI,QAAQ,uBAAuB,IAAI;EAEjE,MAAM,aACJ;EAIF,MAAM,aAAa,kBAAkB,MAAM;EAC3C,MAAM,aAAa,CACjB,aAAa,IACb,mBACA,QAAQ,MAAmB,OAAO,MAAM,YAAY,EAAE,SAAS;AAEjE,OAAK,MAAM,aAAa,YAAY;GAClC,MAAM,UAAU,UAAU,QAAQ,gBAAgB;GAClD,MAAM,QAAQ,QAAQ,MAAM;AAC5B,OAAI,QAAQ,GACV,QAAO,MAAM,GAAG,OAAO;;AAI3B,SAAO,kBAAkB;;CAGd,cAAc,UAAyC;EAClE,MAAM,MAAM,iBAAiB,aAAa,QAAQ,WAAW,KAAK;AAClE,SAAO,KAAK,MAAM,KAAK,KACpB,KAAI,MAAK,EAAE,SAAS,IAAI,SAAS,GAAG,MACpC,KAAK"}
|
|
@@ -3,12 +3,14 @@ const require_validation = require('../../utils/validation.js');
|
|
|
3
3
|
const require_accountIds = require('../types/accountIds.js');
|
|
4
4
|
const require_index = require('../IndexedDBManager/index.js');
|
|
5
5
|
const require_vrf_worker = require('../types/vrf-worker.js');
|
|
6
|
+
const require_errors = require('../../utils/errors.js');
|
|
6
7
|
const require_sdkSentEvents = require('../types/sdkSentEvents.js');
|
|
7
8
|
const require_rpc = require('../types/rpc.js');
|
|
8
9
|
const require_getDeviceNumber = require('../WebAuthnManager/SignerWorkerManager/getDeviceNumber.js');
|
|
9
10
|
const require_login = require('./login.js');
|
|
10
11
|
const require_emailRecoveryPendingStore = require('../EmailRecovery/emailRecoveryPendingStore.js');
|
|
11
12
|
const require_index$1 = require('../EmailRecovery/index.js');
|
|
13
|
+
const require_emailRecovery = require('../types/emailRecovery.js');
|
|
12
14
|
|
|
13
15
|
//#region src/core/TatchiPasskey/emailRecovery.ts
|
|
14
16
|
var emailRecovery_exports = {};
|
|
@@ -48,6 +50,7 @@ var EmailRecoveryFlow;
|
|
|
48
50
|
var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasskey/emailRecovery.ts": (() => {
|
|
49
51
|
require_index.init_IndexedDBManager();
|
|
50
52
|
require_validation.init_validation();
|
|
53
|
+
require_errors.init_errors();
|
|
51
54
|
require_accountIds.init_accountIds();
|
|
52
55
|
require_sdkSentEvents.init_sdkSentEvents();
|
|
53
56
|
require_vrf_worker.init_vrf_worker();
|
|
@@ -55,6 +58,7 @@ var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasske
|
|
|
55
58
|
require_getDeviceNumber.init_getDeviceNumber();
|
|
56
59
|
require_login.init_login();
|
|
57
60
|
require_index$1.init_EmailRecovery();
|
|
61
|
+
require_emailRecovery.init_emailRecovery();
|
|
58
62
|
EmailRecoveryFlow = class {
|
|
59
63
|
context;
|
|
60
64
|
options;
|
|
@@ -82,8 +86,9 @@ var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasske
|
|
|
82
86
|
emit(event) {
|
|
83
87
|
this.options?.onEvent?.(event);
|
|
84
88
|
}
|
|
85
|
-
emitError(step,
|
|
86
|
-
const err = new Error(
|
|
89
|
+
emitError(step, messageOrError) {
|
|
90
|
+
const err = typeof messageOrError === "string" ? new Error(messageOrError) : messageOrError;
|
|
91
|
+
const message = err.message || (typeof messageOrError === "string" ? messageOrError : "Unknown error");
|
|
87
92
|
this.phase = require_sdkSentEvents.EmailRecoveryPhase.ERROR;
|
|
88
93
|
this.error = err;
|
|
89
94
|
this.emit({
|
|
@@ -142,8 +147,8 @@ var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasske
|
|
|
142
147
|
const accountView = await this.context.nearClient.viewAccount(nearAccountId);
|
|
143
148
|
const available = this.computeAvailableBalance(accountView);
|
|
144
149
|
if (available < BigInt(minBalanceYocto)) await this.fail(1, `This account does not have enough NEAR to finalize recovery. Available: ${available.toString()} yocto; required: ${String(minBalanceYocto)}. Please top up and try again.`);
|
|
145
|
-
} catch (
|
|
146
|
-
await this.fail(1,
|
|
150
|
+
} catch (err) {
|
|
151
|
+
await this.fail(1, require_errors.errorMessage(err) || "Failed to fetch account balance for recovery");
|
|
147
152
|
}
|
|
148
153
|
}
|
|
149
154
|
async getCanonicalRecoveryEmailOrFail(recoveryEmail) {
|
|
@@ -155,7 +160,7 @@ var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasske
|
|
|
155
160
|
try {
|
|
156
161
|
const { syncAuthenticatorsContractCall } = await Promise.resolve().then(() => require("../rpcCalls.js"));
|
|
157
162
|
const authenticators = await syncAuthenticatorsContractCall(this.context.nearClient, this.context.configs.contractId, nearAccountId);
|
|
158
|
-
const numbers = authenticators.map((
|
|
163
|
+
const numbers = authenticators.map(({ authenticator }) => authenticator.deviceNumber).filter((n) => typeof n === "number" && Number.isFinite(n));
|
|
159
164
|
const max = numbers.length > 0 ? Math.max(...numbers) : 0;
|
|
160
165
|
return max + 1;
|
|
161
166
|
} catch {
|
|
@@ -234,11 +239,11 @@ var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasske
|
|
|
234
239
|
success: false
|
|
235
240
|
};
|
|
236
241
|
if (!result.verified) {
|
|
237
|
-
const errorMessage = result.error_message || result.error_code || "Email verification failed on relayer/contract";
|
|
242
|
+
const errorMessage$1 = result.error_message || result.error_code || "Email verification failed on relayer/contract";
|
|
238
243
|
return {
|
|
239
244
|
completed: true,
|
|
240
245
|
success: false,
|
|
241
|
-
errorMessage,
|
|
246
|
+
errorMessage: errorMessage$1,
|
|
242
247
|
transactionHash: result.transaction_hash
|
|
243
248
|
};
|
|
244
249
|
}
|
|
@@ -403,7 +408,7 @@ var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasske
|
|
|
403
408
|
nearPublicKey: rec.nearPublicKey
|
|
404
409
|
};
|
|
405
410
|
} catch (e) {
|
|
406
|
-
const err = this.emitError(2, e
|
|
411
|
+
const err = this.emitError(2, require_errors.errorMessage(e) || "Email recovery TouchID/derivation failed");
|
|
407
412
|
await this.options?.afterCall?.(false);
|
|
408
413
|
throw err;
|
|
409
414
|
}
|
|
@@ -573,7 +578,7 @@ var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasske
|
|
|
573
578
|
accountId
|
|
574
579
|
};
|
|
575
580
|
}
|
|
576
|
-
async
|
|
581
|
+
async signNewDevice2RegistrationTx(rec, accountId) {
|
|
577
582
|
const vrfChallenge = rec.vrfChallenge;
|
|
578
583
|
if (!vrfChallenge) return this.fail(5, "Missing VRF challenge for email recovery registration");
|
|
579
584
|
const registrationResult = await this.context.webAuthnManager.signDevice2RegistrationWithStoredKey({
|
|
@@ -587,28 +592,56 @@ var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasske
|
|
|
587
592
|
return registrationResult.signedTransaction;
|
|
588
593
|
}
|
|
589
594
|
async broadcastRegistrationTxAndWaitFinal(rec, signedTx) {
|
|
595
|
+
let txResult;
|
|
590
596
|
try {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
597
|
+
txResult = await this.context.nearClient.sendTransaction(signedTx, require_rpc.DEFAULT_WAIT_STATUS.linkDeviceRegistration);
|
|
598
|
+
} catch (err) {
|
|
599
|
+
const msg = require_errors.errorMessage(err) || "Failed to broadcast email recovery registration transaction (insufficient funds or RPC error)";
|
|
600
|
+
throw new Error(msg);
|
|
601
|
+
}
|
|
602
|
+
const txHash = this.getTxHash(txResult);
|
|
603
|
+
const linkDeviceResult = require_index$1.parseLinkDeviceRegisterUserResponse(txResult);
|
|
604
|
+
if (linkDeviceResult?.verified === false) {
|
|
605
|
+
const logs = this.extractNearExecutionLogs(txResult);
|
|
606
|
+
const isStaleChallenge = logs.some((log) => /StaleChallenge|freshness validation failed/i.test(log));
|
|
607
|
+
const txHint = txHash ? ` (tx: ${txHash})` : "";
|
|
608
|
+
const code = isStaleChallenge ? require_emailRecovery.EmailRecoveryErrorCode.VRF_CHALLENGE_EXPIRED : require_emailRecovery.EmailRecoveryErrorCode.REGISTRATION_NOT_VERIFIED;
|
|
609
|
+
const message = isStaleChallenge ? `Timed out finalizing registration (VRF challenge expired). Please restart email recovery and try again${txHint}.` : `Registration did not verify on-chain. Please try again${txHint}.`;
|
|
610
|
+
throw new require_emailRecovery.EmailRecoveryError(message, code, {
|
|
611
|
+
accountId: rec.accountId,
|
|
612
|
+
nearPublicKey: rec.nearPublicKey,
|
|
613
|
+
transactionHash: txHash,
|
|
614
|
+
logs,
|
|
615
|
+
result: linkDeviceResult
|
|
616
|
+
});
|
|
610
617
|
}
|
|
611
|
-
|
|
618
|
+
if (txHash) this.emit({
|
|
619
|
+
step: 5,
|
|
620
|
+
phase: require_sdkSentEvents.EmailRecoveryPhase.STEP_5_FINALIZING_REGISTRATION,
|
|
621
|
+
status: require_sdkSentEvents.EmailRecoveryStatus.PROGRESS,
|
|
622
|
+
message: "Registration transaction confirmed",
|
|
623
|
+
data: {
|
|
624
|
+
accountId: rec.accountId,
|
|
625
|
+
nearPublicKey: rec.nearPublicKey,
|
|
626
|
+
transactionHash: txHash
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
return txHash;
|
|
630
|
+
}
|
|
631
|
+
getTxHash(outcome) {
|
|
632
|
+
const txUnknown = outcome.transaction;
|
|
633
|
+
if (txUnknown && typeof txUnknown === "object") {
|
|
634
|
+
const hash = txUnknown.hash;
|
|
635
|
+
if (typeof hash === "string" && hash.length > 0) return hash;
|
|
636
|
+
}
|
|
637
|
+
const fallback = outcome.transaction_hash;
|
|
638
|
+
return typeof fallback === "string" && fallback.length > 0 ? fallback : void 0;
|
|
639
|
+
}
|
|
640
|
+
extractNearExecutionLogs(outcome) {
|
|
641
|
+
const logs = [];
|
|
642
|
+
for (const entry of outcome.transaction_outcome.outcome.logs) logs.push(String(entry));
|
|
643
|
+
for (const receipt of outcome.receipts_outcome) for (const entry of receipt.outcome.logs) logs.push(String(entry));
|
|
644
|
+
return logs;
|
|
612
645
|
}
|
|
613
646
|
mapAuthenticatorsFromContract(authenticators) {
|
|
614
647
|
return authenticators.map(({ authenticator }) => ({
|
|
@@ -644,7 +677,7 @@ var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasske
|
|
|
644
677
|
}
|
|
645
678
|
async updateNonceBestEffort(nonceManager, signedTx) {
|
|
646
679
|
try {
|
|
647
|
-
const txNonce = signedTx.transaction
|
|
680
|
+
const txNonce = signedTx.transaction.nonce;
|
|
648
681
|
if (txNonce != null) await nonceManager.updateNonceFromBlockchain(this.context.nearClient, String(txNonce));
|
|
649
682
|
} catch {}
|
|
650
683
|
}
|
|
@@ -760,7 +793,7 @@ var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasske
|
|
|
760
793
|
} catch (err) {
|
|
761
794
|
return {
|
|
762
795
|
success: false,
|
|
763
|
-
reason: err
|
|
796
|
+
reason: require_errors.errorMessage(err) || String(err)
|
|
764
797
|
};
|
|
765
798
|
}
|
|
766
799
|
}
|
|
@@ -788,7 +821,7 @@ var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasske
|
|
|
788
821
|
});
|
|
789
822
|
try {
|
|
790
823
|
const { nonceManager, accountId } = this.initializeNonceManager(rec);
|
|
791
|
-
const signedTx = await this.
|
|
824
|
+
const signedTx = await this.signNewDevice2RegistrationTx(rec, accountId);
|
|
792
825
|
const txHash = await this.broadcastRegistrationTxAndWaitFinal(rec, signedTx);
|
|
793
826
|
if (!txHash) console.warn("[EmailRecoveryFlow] Registration transaction confirmed without hash; continuing local persistence");
|
|
794
827
|
await this.persistRecoveredUserData(rec, accountId);
|
|
@@ -816,7 +849,10 @@ var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasske
|
|
|
816
849
|
}
|
|
817
850
|
});
|
|
818
851
|
} catch (e) {
|
|
819
|
-
|
|
852
|
+
rec.status = "error";
|
|
853
|
+
await this.savePending(rec).catch(() => {});
|
|
854
|
+
const original = e instanceof Error ? e : new Error(require_errors.errorMessage(e) || "Email recovery finalization failed");
|
|
855
|
+
const err = this.emitError(5, original);
|
|
820
856
|
await this.options?.afterCall?.(false);
|
|
821
857
|
throw err;
|
|
822
858
|
}
|
|
@@ -838,7 +874,7 @@ var init_emailRecovery = require_rolldown_runtime.__esm({ "src/core/TatchiPasske
|
|
|
838
874
|
};
|
|
839
875
|
return this.handleAutoLoginFailure(touchIdResult.reason || "Auto-login failed");
|
|
840
876
|
} catch (err) {
|
|
841
|
-
return this.handleAutoLoginFailure(err
|
|
877
|
+
return this.handleAutoLoginFailure(require_errors.errorMessage(err) || String(err), err);
|
|
842
878
|
}
|
|
843
879
|
}
|
|
844
880
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emailRecovery.js","names":["EmailRecoveryPhase","EmailRecoveryPendingStore","EmailRecoveryStatus","validateNearAccountId","toAccountId","e: any","elapsedMs","rec: PendingEmailRecovery","err","DEFAULT_WAIT_STATUS","IndexedDBManager","payload: StoreUserDataPayload","getLoginSession","createRandomVRFChallenge","err: any","parseDeviceNumber"],"sources":["../../../../src/core/TatchiPasskey/emailRecovery.ts"],"sourcesContent":["import type { PasskeyManagerContext } from './index';\nimport { IndexedDBManager } from '../IndexedDBManager';\nimport { validateNearAccountId } from '../../utils/validation';\nimport { toAccountId, type AccountId } from '../types/accountIds';\nimport {\n EmailRecoveryPhase,\n EmailRecoveryStatus,\n type EmailRecoverySSEEvent,\n type EventCallback,\n type AfterCall,\n} from '../types/sdkSentEvents';\nimport type { TatchiConfigs } from '../types/tatchi';\nimport {\n createRandomVRFChallenge,\n type EncryptedVRFKeypair,\n type ServerEncryptedVrfKeypair,\n type VRFChallenge,\n} from '../types/vrf-worker';\nimport type { WebAuthnRegistrationCredential } from '../types';\nimport type { ConfirmationConfig } from '../types/signer-worker';\nimport { DEFAULT_WAIT_STATUS } from '../types/rpc';\nimport { parseDeviceNumber } from '../WebAuthnManager/SignerWorkerManager/getDeviceNumber';\nimport { getLoginSession } from './login';\nimport type { SignedTransaction } from '../NearClient';\nimport { EmailRecoveryPendingStore, type PendingStore } from '../EmailRecovery';\n\nexport type PendingEmailRecoveryStatus =\n | 'awaiting-email'\n | 'awaiting-add-key'\n | 'finalizing'\n | 'complete'\n | 'error';\n\nexport type PendingEmailRecovery = {\n accountId: AccountId;\n recoveryEmail: string;\n deviceNumber: number;\n nearPublicKey: string;\n requestId: string;\n encryptedVrfKeypair: EncryptedVRFKeypair;\n serverEncryptedVrfKeypair: ServerEncryptedVrfKeypair | null;\n vrfPublicKey: string;\n credential: WebAuthnRegistrationCredential;\n vrfChallenge?: VRFChallenge;\n createdAt: number;\n status: PendingEmailRecoveryStatus;\n};\n\ntype PollTickResult<T> = { done: false } | { done: true; value: T };\n\ntype PollUntilResult<T> =\n | { status: 'completed'; value: T; elapsedMs: number; pollCount: number }\n | { status: 'timedOut'; elapsedMs: number; pollCount: number }\n | { status: 'cancelled'; elapsedMs: number; pollCount: number };\n\ntype VerificationOutcome =\n | { outcome: 'verified' }\n | { outcome: 'failed'; errorMessage: string };\n\ntype AutoLoginResult =\n | { success: true; method: 'shamir' | 'touchid' }\n | { success: false; reason: string };\n\ntype StoreUserDataPayload = Parameters<PasskeyManagerContext['webAuthnManager']['storeUserData']>[0];\n\ntype AccountViewLike = {\n amount: bigint | string;\n locked: bigint | string;\n storage_usage: number | bigint;\n};\n\ntype CollectedRecoveryCredential = {\n credential: WebAuthnRegistrationCredential;\n vrfChallenge?: VRFChallenge;\n};\n\ntype DerivedRecoveryKeys = {\n encryptedVrfKeypair: EncryptedVRFKeypair;\n serverEncryptedVrfKeypair: ServerEncryptedVrfKeypair | null;\n vrfPublicKey: string;\n nearPublicKey: string;\n};\n\nexport interface EmailRecoveryFlowOptions {\n onEvent?: EventCallback<EmailRecoverySSEEvent>;\n onError?: (error: Error) => void;\n afterCall?: AfterCall<void>;\n pendingStore?: PendingStore;\n confirmerText?: { title?: string; body?: string };\n confirmationConfig?: Partial<ConfirmationConfig>;\n}\n\nfunction getEmailRecoveryConfig(configs: TatchiConfigs): {\n minBalanceYocto: string;\n pollingIntervalMs: number;\n maxPollingDurationMs: number;\n pendingTtlMs: number;\n mailtoAddress: string;\n dkimVerifierAccountId: string;\n verificationViewMethod: string;\n} {\n const relayerEmailCfg = configs.relayer.emailRecovery;\n const minBalanceYocto = String(relayerEmailCfg.minBalanceYocto);\n const pollingIntervalMs = Number(relayerEmailCfg.pollingIntervalMs);\n const maxPollingDurationMs = Number(relayerEmailCfg.maxPollingDurationMs);\n const pendingTtlMs = Number(relayerEmailCfg.pendingTtlMs);\n const mailtoAddress = String(relayerEmailCfg.mailtoAddress);\n const dkimVerifierAccountId = String(relayerEmailCfg.dkimVerifierAccountId);\n const verificationViewMethod = String(relayerEmailCfg.verificationViewMethod);\n return {\n minBalanceYocto,\n pollingIntervalMs,\n maxPollingDurationMs,\n pendingTtlMs,\n mailtoAddress,\n dkimVerifierAccountId,\n verificationViewMethod,\n };\n}\n\nexport function generateEmailRecoveryRequestId(): string {\n // 6-character A–Z0–9 identifier, suitable for short-lived correlation.\n const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';\n const length = 6;\n const bytes = new Uint8Array(length);\n (globalThis.crypto || window.crypto).getRandomValues(bytes);\n let out = '';\n for (let i = 0; i < length; i++) {\n out += alphabet[bytes[i] % alphabet.length];\n }\n return out;\n}\n\nexport class EmailRecoveryFlow {\n private context: PasskeyManagerContext;\n private options?: EmailRecoveryFlowOptions;\n private pendingStore: PendingStore;\n private pending: PendingEmailRecovery | null = null;\n private phase: EmailRecoveryPhase = EmailRecoveryPhase.STEP_1_PREPARATION;\n private pollingTimer: any;\n private pollIntervalResolver?: (value?: void | PromiseLike<void>) => void;\n private pollingStartedAt: number | null = null;\n private cancelled = false;\n private error?: Error;\n\n constructor(context: PasskeyManagerContext, options?: EmailRecoveryFlowOptions) {\n this.context = context;\n this.options = options;\n this.pendingStore = options?.pendingStore ?? new EmailRecoveryPendingStore({\n getPendingTtlMs: () => this.getConfig().pendingTtlMs,\n });\n }\n\n setOptions(options?: EmailRecoveryFlowOptions) {\n if (!options) return;\n this.options = { ...(this.options || {}), ...options };\n if (options.pendingStore) {\n this.pendingStore = options.pendingStore;\n }\n }\n private emit(event: EmailRecoverySSEEvent) {\n this.options?.onEvent?.(event);\n }\n\n private emitError(step: number, message: string): Error {\n const err = new Error(message);\n this.phase = EmailRecoveryPhase.ERROR;\n this.error = err;\n this.emit({\n step,\n phase: EmailRecoveryPhase.ERROR,\n status: EmailRecoveryStatus.ERROR,\n message,\n error: message,\n } as EmailRecoverySSEEvent & { error: string });\n this.options?.onError?.(err);\n return err;\n }\n\n private async fail(step: number, message: string): Promise<never> {\n const err = this.emitError(step, message);\n await this.options?.afterCall?.(false);\n throw err;\n }\n\n private async assertValidAccountIdOrFail(step: number, accountId: string): Promise<AccountId> {\n const validation = validateNearAccountId(accountId as AccountId);\n if (!validation.valid) {\n await this.fail(step, `Invalid NEAR account ID: ${validation.error}`);\n }\n return toAccountId(accountId as string);\n }\n\n private async resolvePendingOrFail(\n step: number,\n args: { accountId: AccountId; nearPublicKey?: string },\n options?: {\n allowErrorStatus?: boolean;\n missingMessage?: string;\n errorStatusMessage?: string;\n }\n ): Promise<PendingEmailRecovery> {\n const {\n allowErrorStatus = true,\n missingMessage = 'No pending email recovery record found for this account',\n errorStatusMessage = 'Pending email recovery is in an error state; please restart the flow',\n } = options ?? {};\n\n let rec = this.pending;\n if (!rec || rec.accountId !== args.accountId || (args.nearPublicKey && rec.nearPublicKey !== args.nearPublicKey)) {\n rec = await this.loadPending(args.accountId, args.nearPublicKey);\n this.pending = rec;\n }\n\n if (!rec) {\n await this.fail(step, missingMessage);\n }\n\n const resolved = rec as PendingEmailRecovery;\n if (!allowErrorStatus && resolved.status === 'error') {\n await this.fail(step, errorStatusMessage);\n }\n\n return resolved;\n }\n\n private getConfig() {\n return getEmailRecoveryConfig(this.context.configs);\n }\n\n private toBigInt(value: bigint | number | string | null | undefined): bigint {\n if (typeof value === 'bigint') return value;\n if (typeof value === 'number') return BigInt(value);\n if (typeof value === 'string' && value.length > 0) return BigInt(value);\n return BigInt(0);\n }\n\n private computeAvailableBalance(accountView: AccountViewLike): bigint {\n const STORAGE_PRICE_PER_BYTE = BigInt('10000000000000000000'); // 1e19 yocto NEAR per byte\n const amount = this.toBigInt(accountView.amount);\n const locked = this.toBigInt(accountView.locked);\n const storageUsage = this.toBigInt(accountView.storage_usage);\n const storageCost = storageUsage * STORAGE_PRICE_PER_BYTE;\n const rawAvailable = amount - locked - storageCost;\n return rawAvailable > 0 ? rawAvailable : BigInt(0);\n }\n\n private async assertSufficientBalance(nearAccountId: AccountId): Promise<void> {\n const { minBalanceYocto } = this.getConfig();\n\n try {\n const accountView = await this.context.nearClient.viewAccount(nearAccountId);\n const available = this.computeAvailableBalance(accountView);\n if (available < BigInt(minBalanceYocto)) {\n await this.fail(\n 1,\n `This account does not have enough NEAR to finalize recovery. Available: ${available.toString()} yocto; required: ${String(minBalanceYocto)}. Please top up and try again.`\n );\n }\n } catch (e: any) {\n await this.fail(1, e?.message || 'Failed to fetch account balance for recovery');\n }\n }\n\n private async getCanonicalRecoveryEmailOrFail(recoveryEmail: string): Promise<string> {\n const canonicalEmail = String(recoveryEmail || '').trim().toLowerCase();\n if (!canonicalEmail) {\n await this.fail(1, 'Recovery email is required for email-based account recovery');\n }\n return canonicalEmail;\n }\n\n private async getNextDeviceNumberFromContract(nearAccountId: AccountId): Promise<number> {\n try {\n const { syncAuthenticatorsContractCall } = await import('../rpcCalls');\n const authenticators = await syncAuthenticatorsContractCall(\n this.context.nearClient,\n this.context.configs.contractId,\n nearAccountId\n );\n const numbers = authenticators\n .map((a: any) => a?.authenticator?.deviceNumber)\n .filter((n: any) => typeof n === 'number' && Number.isFinite(n)) as number[];\n const max = numbers.length > 0 ? Math.max(...numbers) : 0;\n return max + 1;\n } catch {\n return 1;\n }\n }\n\n private async collectRecoveryCredentialOrFail(\n nearAccountId: AccountId,\n deviceNumber: number\n ): Promise<CollectedRecoveryCredential> {\n const confirmerText = {\n title: this.options?.confirmerText?.title ?? 'Register New Recovery Account',\n body: this.options?.confirmerText?.body ?? 'Create a recovery account and send an encrypted email to recover your account.',\n };\n const confirm = await this.context.webAuthnManager.requestRegistrationCredentialConfirmation({\n nearAccountId,\n deviceNumber,\n confirmerText,\n confirmationConfigOverride: this.options?.confirmationConfig,\n });\n\n if (!confirm.confirmed || !confirm.credential) {\n await this.fail(2, 'User cancelled email recovery TouchID confirmation');\n }\n\n return {\n credential: confirm.credential,\n vrfChallenge: confirm.vrfChallenge || undefined,\n };\n }\n\n private async deriveRecoveryKeysOrFail(\n nearAccountId: AccountId,\n deviceNumber: number,\n credential: WebAuthnRegistrationCredential\n ): Promise<DerivedRecoveryKeys> {\n const vrfDerivationResult = await this.context.webAuthnManager.deriveVrfKeypair({\n credential,\n nearAccountId,\n });\n\n if (!vrfDerivationResult.success || !vrfDerivationResult.encryptedVrfKeypair) {\n await this.fail(2, 'Failed to derive VRF keypair from PRF for email recovery');\n }\n\n const nearKeyResult = await this.context.webAuthnManager.deriveNearKeypairAndEncryptFromSerialized({\n nearAccountId,\n credential,\n options: { deviceNumber },\n });\n\n if (!nearKeyResult.success || !nearKeyResult.publicKey) {\n await this.fail(2, 'Failed to derive NEAR keypair for email recovery');\n }\n\n return {\n encryptedVrfKeypair: vrfDerivationResult.encryptedVrfKeypair,\n serverEncryptedVrfKeypair: vrfDerivationResult.serverEncryptedVrfKeypair || null,\n vrfPublicKey: vrfDerivationResult.vrfPublicKey,\n nearPublicKey: nearKeyResult.publicKey,\n };\n }\n\n private emitAwaitEmail(rec: PendingEmailRecovery, mailtoUrl: string): void {\n this.phase = EmailRecoveryPhase.STEP_3_AWAIT_EMAIL;\n this.emit({\n step: 3,\n phase: EmailRecoveryPhase.STEP_3_AWAIT_EMAIL,\n status: EmailRecoveryStatus.PROGRESS,\n message: 'New device key created; please send the recovery email from your registered address.',\n data: {\n accountId: rec.accountId,\n recoveryEmail: rec.recoveryEmail,\n nearPublicKey: rec.nearPublicKey,\n requestId: rec.requestId,\n mailtoUrl,\n },\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n }\n\n private emitAutoLoginEvent(\n status: EmailRecoveryStatus,\n message: string,\n data: Record<string, unknown>\n ): void {\n this.emit({\n step: 5,\n phase: EmailRecoveryPhase.STEP_5_FINALIZING_REGISTRATION,\n status,\n message,\n data,\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n }\n\n private async checkViaDkimViewMethod(\n rec: PendingEmailRecovery\n ): Promise<{ completed: boolean; success: boolean; errorMessage?: string; transactionHash?: string } | null> {\n const { dkimVerifierAccountId, verificationViewMethod } = this.getConfig();\n if (!dkimVerifierAccountId) return null;\n\n try {\n const { getEmailRecoveryVerificationResult } = await import('../rpcCalls');\n const result = await getEmailRecoveryVerificationResult(\n this.context.nearClient,\n dkimVerifierAccountId,\n verificationViewMethod,\n rec.requestId\n );\n\n if (!result) {\n return { completed: false, success: false };\n }\n\n if (!result.verified) {\n const errorMessage = result.error_message || result.error_code || 'Email verification failed on relayer/contract';\n return {\n completed: true,\n success: false,\n errorMessage,\n transactionHash: result.transaction_hash,\n };\n }\n\n // Optional safety checks: ensure the bound account/key match expectations when available.\n if (result.account_id && result.account_id !== rec.accountId) {\n return {\n completed: true,\n success: false,\n errorMessage: 'Email verification account_id does not match requested account.',\n transactionHash: result.transaction_hash,\n };\n }\n if (result.new_public_key && result.new_public_key !== rec.nearPublicKey) {\n return {\n completed: true,\n success: false,\n errorMessage: 'Email verification new_public_key does not match expected recovery key.',\n transactionHash: result.transaction_hash,\n };\n }\n\n return {\n completed: true,\n success: true,\n transactionHash: result.transaction_hash\n };\n } catch (err) {\n // Treat view errors as retryable; keep polling the view method.\n // eslint-disable-next-line no-console\n console.warn('[EmailRecoveryFlow] get_verification_result view failed; will retry', err);\n return null;\n }\n }\n\n private buildPollingEventData(\n rec: PendingEmailRecovery,\n details: { transactionHash?: string; elapsedMs: number; pollCount: number }\n ): Record<string, unknown> {\n return {\n accountId: rec.accountId,\n requestId: rec.requestId,\n nearPublicKey: rec.nearPublicKey,\n transactionHash: details.transactionHash,\n elapsedMs: details.elapsedMs,\n pollCount: details.pollCount,\n };\n }\n\n private async sleepForPollInterval(ms: number): Promise<void> {\n await new Promise<void>(resolve => {\n this.pollIntervalResolver = resolve;\n this.pollingTimer = setTimeout(() => {\n this.pollIntervalResolver = undefined;\n this.pollingTimer = undefined;\n resolve();\n }, ms);\n }).finally(() => {\n this.pollIntervalResolver = undefined;\n });\n }\n\n private async pollUntil<T>(args: {\n intervalMs: number;\n timeoutMs: number;\n isCancelled: () => boolean;\n tick: (ctx: { elapsedMs: number; pollCount: number }) => Promise<PollTickResult<T>>;\n sleep?: (ms: number) => Promise<void>;\n now?: () => number;\n }): Promise<PollUntilResult<T>> {\n const now = args.now ?? Date.now;\n const sleep = args.sleep ?? this.sleepForPollInterval.bind(this);\n const startedAt = now();\n let pollCount = 0;\n\n while (!args.isCancelled()) {\n pollCount += 1;\n const elapsedMs = now() - startedAt;\n if (elapsedMs > args.timeoutMs) {\n return { status: 'timedOut', elapsedMs, pollCount };\n }\n\n const result = await args.tick({ elapsedMs, pollCount });\n if (result.done) {\n return { status: 'completed', value: result.value, elapsedMs, pollCount };\n }\n\n if (args.isCancelled()) {\n return { status: 'cancelled', elapsedMs, pollCount };\n }\n\n await sleep(args.intervalMs);\n }\n\n const elapsedMs = now() - startedAt;\n return { status: 'cancelled', elapsedMs, pollCount };\n }\n\n private async loadPending(\n accountId: AccountId,\n nearPublicKey?: string\n ): Promise<PendingEmailRecovery | null> {\n return this.pendingStore.get(accountId, nearPublicKey);\n }\n\n private async savePending(rec: PendingEmailRecovery): Promise<void> {\n await this.pendingStore.set(rec);\n this.pending = rec;\n }\n\n private async clearPending(accountId: AccountId, nearPublicKey?: string): Promise<void> {\n await this.pendingStore.clear(accountId, nearPublicKey);\n\n if (\n this.pending\n && this.pending.accountId === accountId\n && (!nearPublicKey || this.pending.nearPublicKey === nearPublicKey)\n ) {\n this.pending = null;\n }\n }\n\n getState() {\n return {\n phase: this.phase,\n pending: this.pending,\n error: this.error,\n };\n }\n\n async buildMailtoUrl(args: { accountId: string; nearPublicKey?: string }): Promise<string> {\n const { accountId, nearPublicKey } = args;\n this.cancelled = false;\n this.error = undefined;\n\n const nearAccountId = await this.assertValidAccountIdOrFail(3, accountId);\n const rec = await this.resolvePendingOrFail(\n 3,\n { accountId: nearAccountId, nearPublicKey },\n { allowErrorStatus: false }\n );\n\n if (rec.status === 'finalizing' || rec.status === 'complete') {\n await this.fail(3, 'Recovery email has already been processed on-chain for this request');\n }\n\n const mailtoUrl =\n rec.status === 'awaiting-email'\n ? await this.buildMailtoUrlAndUpdateStatus(rec)\n : this.buildMailtoUrlInternal(rec);\n this.emitAwaitEmail(rec, mailtoUrl);\n await this.options?.afterCall?.(true, undefined);\n return mailtoUrl;\n }\n\n async start(args: { accountId: string; recoveryEmail: string }): Promise<{ mailtoUrl: string; nearPublicKey: string }> {\n const { accountId, recoveryEmail } = args;\n this.cancelled = false;\n this.error = undefined;\n this.phase = EmailRecoveryPhase.STEP_1_PREPARATION;\n\n this.emit({\n step: 1,\n phase: EmailRecoveryPhase.STEP_1_PREPARATION,\n status: EmailRecoveryStatus.PROGRESS,\n message: 'Preparing email recovery...',\n });\n\n const nearAccountId = await this.assertValidAccountIdOrFail(1, accountId);\n await this.assertSufficientBalance(nearAccountId);\n const canonicalEmail = await this.getCanonicalRecoveryEmailOrFail(recoveryEmail);\n\n // Determine deviceNumber from on-chain authenticators\n const deviceNumber = await this.getNextDeviceNumberFromContract(nearAccountId);\n\n this.phase = EmailRecoveryPhase.STEP_2_TOUCH_ID_REGISTRATION;\n this.emit({\n step: 2,\n phase: EmailRecoveryPhase.STEP_2_TOUCH_ID_REGISTRATION,\n status: EmailRecoveryStatus.PROGRESS,\n message: 'Collecting passkey for email recovery...',\n });\n\n try {\n const confirm = await this.collectRecoveryCredentialOrFail(nearAccountId, deviceNumber);\n const derivedKeys = await this.deriveRecoveryKeysOrFail(nearAccountId, deviceNumber, confirm.credential);\n\n const rec: PendingEmailRecovery = {\n accountId: nearAccountId,\n recoveryEmail: canonicalEmail,\n deviceNumber,\n nearPublicKey: derivedKeys.nearPublicKey,\n requestId: generateEmailRecoveryRequestId(),\n encryptedVrfKeypair: derivedKeys.encryptedVrfKeypair,\n serverEncryptedVrfKeypair: derivedKeys.serverEncryptedVrfKeypair,\n vrfPublicKey: derivedKeys.vrfPublicKey,\n credential: confirm.credential,\n vrfChallenge: confirm.vrfChallenge || undefined,\n createdAt: Date.now(),\n status: 'awaiting-email',\n };\n\n const mailtoUrl = await this.buildMailtoUrlAndUpdateStatus(rec);\n\n this.emitAwaitEmail(rec, mailtoUrl);\n\n await this.options?.afterCall?.(true, undefined);\n\n return { mailtoUrl, nearPublicKey: rec.nearPublicKey };\n } catch (e: any) {\n const err = this.emitError(2, e?.message || 'Email recovery TouchID/derivation failed');\n await this.options?.afterCall?.(false);\n throw err;\n }\n }\n\n private buildMailtoUrlInternal(rec: PendingEmailRecovery): string {\n const { mailtoAddress } = this.getConfig();\n const to = encodeURIComponent(mailtoAddress);\n const subject = encodeURIComponent(`recover-${rec.requestId} ${rec.accountId} ${rec.nearPublicKey}`);\n const body = encodeURIComponent(`Recovering account ${rec.accountId} with a new passkey.`);\n return `mailto:${to}?subject=${subject}&body=${body}`;\n }\n\n private async buildMailtoUrlAndUpdateStatus(rec: PendingEmailRecovery): Promise<string> {\n rec.status = 'awaiting-add-key';\n await this.savePending(rec);\n return this.buildMailtoUrlInternal(rec);\n }\n\n async startPolling(args: { accountId: string; nearPublicKey?: string }): Promise<void> {\n const { accountId, nearPublicKey } = args;\n this.cancelled = false;\n this.error = undefined;\n\n const nearAccountId = await this.assertValidAccountIdOrFail(4, accountId);\n const rec = await this.resolvePendingOrFail(\n 4,\n { accountId: nearAccountId, nearPublicKey },\n { allowErrorStatus: false }\n );\n if (rec.status === 'complete' || rec.status === 'finalizing') {\n await this.options?.afterCall?.(true, undefined);\n return;\n }\n if (rec.status === 'awaiting-email') {\n await this.buildMailtoUrlAndUpdateStatus(rec);\n }\n\n await this.pollUntilAddKey(rec);\n await this.options?.afterCall?.(true, undefined);\n }\n\n stopPolling(): void {\n this.cancelled = true;\n if (this.pollingTimer) {\n clearTimeout(this.pollingTimer);\n this.pollingTimer = undefined;\n }\n if (this.pollIntervalResolver) {\n this.pollIntervalResolver();\n this.pollIntervalResolver = undefined;\n }\n }\n\n /**\n * Best-effort cancellation and local state reset so callers can retry.\n * This does not remove any passkey created in the browser/OS (WebAuthn has no delete API),\n * but it will stop polling and clear the pending IndexedDB record for the given key.\n */\n async cancelAndReset(args?: { accountId?: string; nearPublicKey?: string }): Promise<void> {\n this.stopPolling();\n\n const normalizedAccountId = (args?.accountId || this.pending?.accountId || '').toString().trim();\n const nearPublicKey = (args?.nearPublicKey || this.pending?.nearPublicKey || '').toString().trim();\n\n if (normalizedAccountId) {\n try {\n await this.clearPending(toAccountId(normalizedAccountId), nearPublicKey);\n } catch {\n // best-effort\n }\n }\n\n this.pending = null;\n this.error = undefined;\n this.phase = EmailRecoveryPhase.STEP_1_PREPARATION;\n }\n\n async finalize(args: { accountId: string; nearPublicKey?: string }): Promise<void> {\n const { accountId, nearPublicKey } = args;\n this.cancelled = false;\n this.error = undefined;\n\n const nearAccountId = await this.assertValidAccountIdOrFail(4, accountId);\n const rec = await this.resolvePendingOrFail(\n 4,\n { accountId: nearAccountId, nearPublicKey },\n { allowErrorStatus: true }\n );\n\n this.emit({\n step: 0,\n phase: EmailRecoveryPhase.RESUMED_FROM_PENDING,\n status: EmailRecoveryStatus.PROGRESS,\n message: 'Resuming email recovery from pending state...',\n data: {\n accountId: rec.accountId,\n nearPublicKey: rec.nearPublicKey,\n status: rec.status,\n },\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n\n if (rec.status === 'complete') {\n this.phase = EmailRecoveryPhase.STEP_6_COMPLETE;\n this.emit({\n step: 6,\n phase: EmailRecoveryPhase.STEP_6_COMPLETE,\n status: EmailRecoveryStatus.SUCCESS,\n message: 'Email recovery already completed for this key.',\n });\n await this.options?.afterCall?.(true, undefined);\n return;\n }\n\n // Ensure verification has completed successfully before finalizing registration.\n await this.pollUntilAddKey(rec);\n await this.finalizeRegistration(rec);\n await this.options?.afterCall?.(true, undefined);\n }\n\n private async pollUntilAddKey(rec: PendingEmailRecovery): Promise<void> {\n const { pollingIntervalMs, maxPollingDurationMs, dkimVerifierAccountId } = this.getConfig();\n if (!dkimVerifierAccountId) {\n const err = this.emitError(4, 'Email recovery verification contract (dkimVerifierAccountId) is not configured');\n await this.options?.afterCall?.(false);\n throw err;\n }\n this.phase = EmailRecoveryPhase.STEP_4_POLLING_VERIFICATION_RESULT;\n this.pollingStartedAt = Date.now();\n\n const pollResult = await this.pollUntil<VerificationOutcome>({\n intervalMs: pollingIntervalMs,\n timeoutMs: maxPollingDurationMs,\n isCancelled: () => this.cancelled,\n tick: async ({ elapsedMs, pollCount }) => {\n const verification = await this.checkViaDkimViewMethod(rec);\n const completed = verification?.completed === true;\n const success = verification?.success === true;\n\n this.emit({\n step: 4,\n phase: EmailRecoveryPhase.STEP_4_POLLING_VERIFICATION_RESULT,\n status: EmailRecoveryStatus.PROGRESS,\n message: completed && success\n ? `Email verified for request ${rec.requestId}; finalizing registration`\n : `Waiting for email verification for request ${rec.requestId}`,\n data: this.buildPollingEventData(rec, {\n transactionHash: verification?.transactionHash,\n elapsedMs,\n pollCount,\n }),\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n\n if (!completed) {\n return { done: false };\n }\n\n if (!success) {\n return {\n done: true,\n value: {\n outcome: 'failed',\n errorMessage: verification?.errorMessage || 'Email verification failed',\n },\n };\n }\n\n return { done: true, value: { outcome: 'verified' } };\n },\n });\n\n if (pollResult.status === 'completed') {\n if (pollResult.value.outcome === 'failed') {\n const err = this.emitError(4, pollResult.value.errorMessage);\n rec.status = 'error';\n await this.savePending(rec);\n await this.options?.afterCall?.(false);\n throw err;\n }\n\n rec.status = 'finalizing';\n await this.savePending(rec);\n return;\n }\n\n if (pollResult.status === 'timedOut') {\n const err = this.emitError(4, 'Timed out waiting for recovery email to be processed on-chain');\n rec.status = 'error';\n await this.savePending(rec);\n await this.options?.afterCall?.(false);\n throw err;\n }\n\n const err = this.emitError(4, 'Email recovery polling was cancelled');\n await this.options?.afterCall?.(false);\n throw err;\n }\n\n private initializeNonceManager(\n rec: PendingEmailRecovery\n ): {\n nonceManager: ReturnType<PasskeyManagerContext['webAuthnManager']['getNonceManager']>;\n accountId: AccountId;\n } {\n const nonceManager = this.context.webAuthnManager.getNonceManager();\n const accountId = toAccountId(rec.accountId);\n nonceManager.initializeUser(accountId, rec.nearPublicKey);\n return { nonceManager, accountId };\n }\n\n private async signRegistrationTx(rec: PendingEmailRecovery, accountId: AccountId): Promise<SignedTransaction> {\n const vrfChallenge = rec.vrfChallenge;\n if (!vrfChallenge) {\n return this.fail(5, 'Missing VRF challenge for email recovery registration');\n }\n\n const registrationResult = await this.context.webAuthnManager.signDevice2RegistrationWithStoredKey({\n nearAccountId: accountId,\n credential: rec.credential,\n vrfChallenge,\n deterministicVrfPublicKey: rec.vrfPublicKey,\n deviceNumber: rec.deviceNumber,\n });\n\n if (!registrationResult.success || !registrationResult.signedTransaction) {\n await this.fail(5, registrationResult.error || 'Failed to sign email recovery registration transaction');\n }\n\n return registrationResult.signedTransaction;\n }\n\n private async broadcastRegistrationTxAndWaitFinal(\n rec: PendingEmailRecovery,\n signedTx: SignedTransaction\n ): Promise<string | undefined> {\n try {\n const txResult = await this.context.nearClient.sendTransaction(\n signedTx,\n DEFAULT_WAIT_STATUS.linkDeviceRegistration\n );\n\n try {\n const txHash = (txResult as any)?.transaction?.hash || (txResult as any)?.transaction_hash;\n if (txHash) {\n this.emit({\n step: 5,\n phase: EmailRecoveryPhase.STEP_5_FINALIZING_REGISTRATION,\n status: EmailRecoveryStatus.PROGRESS,\n message: 'Registration transaction confirmed',\n data: {\n accountId: rec.accountId,\n nearPublicKey: rec.nearPublicKey,\n transactionHash: txHash,\n },\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n }\n return txHash;\n } catch {\n // best-effort; do not fail flow\n }\n } catch (e: any) {\n const msg = String(e?.message || '');\n await this.fail(\n 5,\n msg || 'Failed to broadcast email recovery registration transaction (insufficient funds or RPC error)'\n );\n }\n\n return undefined;\n }\n\n private mapAuthenticatorsFromContract(authenticators: Array<{ authenticator: any }>) {\n return authenticators.map(({ authenticator }) => ({\n credentialId: authenticator.credentialId,\n credentialPublicKey: authenticator.credentialPublicKey,\n transports: authenticator.transports,\n name: authenticator.name,\n registered: authenticator.registered.toISOString(),\n vrfPublicKey: authenticator.vrfPublicKeys?.[0] || '',\n deviceNumber: authenticator.deviceNumber,\n }));\n }\n\n private async syncAuthenticatorsBestEffort(accountId: AccountId): Promise<boolean> {\n try {\n const { syncAuthenticatorsContractCall } = await import('../rpcCalls');\n const authenticators = await syncAuthenticatorsContractCall(\n this.context.nearClient,\n this.context.configs.contractId,\n accountId\n );\n\n const mappedAuthenticators = this.mapAuthenticatorsFromContract(authenticators);\n await IndexedDBManager.clientDB.syncAuthenticatorsFromContract(accountId, mappedAuthenticators);\n return true;\n } catch (err) {\n console.warn('[EmailRecoveryFlow] Failed to sync authenticators after recovery:', err);\n return false;\n }\n }\n\n private async setLastUserBestEffort(accountId: AccountId, deviceNumber: number): Promise<boolean> {\n try {\n await IndexedDBManager.clientDB.setLastUser(accountId, deviceNumber);\n return true;\n } catch (err) {\n console.warn('[EmailRecoveryFlow] Failed to set last user after recovery:', err);\n return false;\n }\n }\n\n private async updateNonceBestEffort(\n nonceManager: ReturnType<PasskeyManagerContext['webAuthnManager']['getNonceManager']>,\n signedTx: SignedTransaction\n ): Promise<void> {\n try {\n const txNonce = (signedTx.transaction as any)?.nonce;\n if (txNonce != null) {\n await nonceManager.updateNonceFromBlockchain(\n this.context.nearClient,\n String(txNonce)\n );\n }\n } catch {\n // best-effort; do not fail flow\n }\n }\n\n private async persistRecoveredUserData(rec: PendingEmailRecovery, accountId: AccountId): Promise<void> {\n const { webAuthnManager } = this.context;\n\n const payload: StoreUserDataPayload = {\n nearAccountId: accountId,\n deviceNumber: rec.deviceNumber,\n clientNearPublicKey: rec.nearPublicKey,\n lastUpdated: Date.now(),\n passkeyCredential: {\n id: rec.credential.id,\n rawId: rec.credential.rawId,\n },\n encryptedVrfKeypair: {\n encryptedVrfDataB64u: rec.encryptedVrfKeypair.encryptedVrfDataB64u,\n chacha20NonceB64u: rec.encryptedVrfKeypair.chacha20NonceB64u,\n },\n serverEncryptedVrfKeypair: rec.serverEncryptedVrfKeypair || undefined,\n };\n\n await webAuthnManager.storeUserData(payload);\n }\n\n /**\n * Explicitly persist the authenticator from the recovery record into the local cache.\n * This ensures the key is available immediately, bridging the gap before RPC sync sees it.\n */\n private async persistAuthenticatorBestEffort(rec: PendingEmailRecovery, accountId: AccountId): Promise<void> {\n try {\n const { webAuthnManager } = this.context;\n const attestationB64u = rec.credential.response.attestationObject;\n const credentialPublicKey = await webAuthnManager.extractCosePublicKey(attestationB64u);\n\n await webAuthnManager.storeAuthenticator({\n nearAccountId: accountId,\n deviceNumber: rec.deviceNumber,\n credentialId: rec.credential.rawId,\n credentialPublicKey,\n transports: ['internal'],\n name: `Device ${rec.deviceNumber} Passkey for ${rec.accountId.split('.')[0]}`,\n registered: new Date().toISOString(),\n syncedAt: new Date().toISOString(), // Local truth is fresh\n vrfPublicKey: rec.vrfPublicKey,\n });\n console.log('[EmailRecoveryFlow] Locally persisted recovered authenticator for immediate use.');\n } catch (e) {\n console.error('[EmailRecoveryFlow] Failed to locally persist authenticator (critical for immediate export):', e);\n // We log error but don't rethrow to avoid crashing the final success UI.\n }\n }\n\n private async markCompleteAndClearPending(rec: PendingEmailRecovery): Promise<void> {\n rec.status = 'complete';\n await this.savePending(rec);\n await this.clearPending(rec.accountId, rec.nearPublicKey);\n }\n\n private async assertVrfActiveForAccount(accountId: AccountId, message: string): Promise<void> {\n const vrfStatus = await this.context.webAuthnManager.checkVrfStatus();\n const vrfActiveForAccount =\n vrfStatus.active\n && vrfStatus.nearAccountId\n && String(vrfStatus.nearAccountId) === String(accountId);\n if (!vrfActiveForAccount) {\n throw new Error(message);\n }\n }\n\n private async finalizeLocalLoginState(accountId: AccountId, deviceNumber: number): Promise<void> {\n const { webAuthnManager } = this.context;\n await webAuthnManager.setLastUser(accountId, deviceNumber);\n await webAuthnManager.initializeCurrentUser(accountId, this.context.nearClient);\n try { await getLoginSession(this.context, accountId); } catch { }\n }\n\n private async tryShamirUnlock(\n rec: PendingEmailRecovery,\n accountId: AccountId,\n deviceNumber: number\n ): Promise<boolean> {\n if (\n !rec.serverEncryptedVrfKeypair\n || !rec.serverEncryptedVrfKeypair.serverKeyId\n || !this.context.configs.vrfWorkerConfigs?.shamir3pass?.relayServerUrl\n ) {\n return false;\n }\n\n try {\n const { webAuthnManager } = this.context;\n const unlockResult = await webAuthnManager.shamir3PassDecryptVrfKeypair({\n nearAccountId: accountId,\n kek_s_b64u: rec.serverEncryptedVrfKeypair.kek_s_b64u,\n ciphertextVrfB64u: rec.serverEncryptedVrfKeypair.ciphertextVrfB64u,\n serverKeyId: rec.serverEncryptedVrfKeypair.serverKeyId,\n });\n\n if (!unlockResult.success) {\n return false;\n }\n\n await this.assertVrfActiveForAccount(accountId, 'VRF session inactive after Shamir3Pass unlock');\n await this.finalizeLocalLoginState(accountId, deviceNumber);\n return true;\n } catch (err) {\n console.warn('[EmailRecoveryFlow] Shamir 3-pass unlock failed, falling back to TouchID', err);\n return false;\n }\n }\n\n private async tryTouchIdUnlock(\n rec: PendingEmailRecovery,\n accountId: AccountId,\n deviceNumber: number\n ): Promise<{ success: boolean; reason?: string }> {\n try {\n const { webAuthnManager } = this.context;\n const authChallenge = createRandomVRFChallenge() as VRFChallenge;\n\n const storedCredentialId = String(rec.credential?.rawId || rec.credential?.id || '').trim();\n const credentialIds = storedCredentialId ? [storedCredentialId] : [];\n const authenticators = credentialIds.length > 0\n ? []\n : await webAuthnManager.getAuthenticatorsByUser(accountId);\n const authCredential = await webAuthnManager.getAuthenticationCredentialsSerializedDualPrf({\n nearAccountId: accountId,\n challenge: authChallenge,\n credentialIds: credentialIds.length > 0 ? credentialIds : authenticators.map((a) => a.credentialId),\n });\n\n if (storedCredentialId && authCredential.rawId !== storedCredentialId) {\n return {\n success: false,\n reason: 'Wrong passkey selected during recovery auto-login; please use the newly recovered passkey.',\n };\n }\n\n const vrfUnlockResult = await webAuthnManager.unlockVRFKeypair({\n nearAccountId: accountId,\n encryptedVrfKeypair: rec.encryptedVrfKeypair,\n credential: authCredential,\n });\n\n if (!vrfUnlockResult.success) {\n return { success: false, reason: vrfUnlockResult.error || 'VRF unlock failed during auto-login' };\n }\n\n await this.assertVrfActiveForAccount(accountId, 'VRF session inactive after TouchID unlock');\n await this.finalizeLocalLoginState(accountId, deviceNumber);\n return { success: true };\n } catch (err: any) {\n return { success: false, reason: err?.message || String(err) };\n }\n }\n\n private async handleAutoLoginFailure(reason: string, err?: unknown): Promise<AutoLoginResult> {\n console.warn('[EmailRecoveryFlow] Auto-login failed after recovery', err ?? reason);\n try {\n await this.context.webAuthnManager.clearVrfSession();\n } catch { }\n return { success: false, reason };\n }\n\n private async finalizeRegistration(rec: PendingEmailRecovery): Promise<void> {\n this.phase = EmailRecoveryPhase.STEP_5_FINALIZING_REGISTRATION;\n this.emit({\n step: 5,\n phase: EmailRecoveryPhase.STEP_5_FINALIZING_REGISTRATION,\n status: EmailRecoveryStatus.PROGRESS,\n message: 'Finalizing email recovery registration...',\n data: {\n accountId: rec.accountId,\n nearPublicKey: rec.nearPublicKey,\n },\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n\n try {\n const { nonceManager, accountId } = this.initializeNonceManager(rec);\n const signedTx = await this.signRegistrationTx(rec, accountId);\n const txHash = await this.broadcastRegistrationTxAndWaitFinal(rec, signedTx);\n if (!txHash) {\n console.warn('[EmailRecoveryFlow] Registration transaction confirmed without hash; continuing local persistence');\n }\n\n // CRITICAL: Persist local state immediately.\n // 1. Store the new user record (Device N) so that `getLastUser()` finds it.\n await this.persistRecoveredUserData(rec, accountId);\n\n // 2. Sync authenticators (RPC might be stale, but we try).\n await this.syncAuthenticatorsBestEffort(accountId);\n\n // 3. FORCE-SAVE the local authenticator from our recovery record.\n // This is crucial because RPC sync might be slow/empty immediately after TX.\n // We must ensure the new key is in the DB so `ensureCurrentPasskey` finds it.\n // We do this AFTER sync to ensure it's not wiped by a stale sync.\n await this.persistAuthenticatorBestEffort(rec, accountId);\n\n // 4. Set as active user to ensure immediate subsequent calls use this identity.\n await this.setLastUserBestEffort(accountId, rec.deviceNumber);\n\n await this.updateNonceBestEffort(nonceManager, signedTx);\n\n this.emitAutoLoginEvent(EmailRecoveryStatus.PROGRESS, 'Attempting auto-login with recovered device...', {\n autoLogin: 'progress',\n });\n\n const autoLoginResult = await this.attemptAutoLogin(rec);\n if (autoLoginResult.success) {\n this.emitAutoLoginEvent(EmailRecoveryStatus.SUCCESS, `Welcome ${accountId}`, {\n autoLogin: 'success',\n });\n } else {\n this.emitAutoLoginEvent(EmailRecoveryStatus.ERROR, 'Auto-login failed; please log in manually on this device.', {\n error: autoLoginResult.reason,\n autoLogin: 'error',\n });\n }\n\n await this.markCompleteAndClearPending(rec);\n\n this.phase = EmailRecoveryPhase.STEP_6_COMPLETE;\n this.emit({\n step: 6,\n phase: EmailRecoveryPhase.STEP_6_COMPLETE,\n status: EmailRecoveryStatus.SUCCESS,\n message: 'Email recovery completed successfully',\n data: {\n accountId: rec.accountId,\n nearPublicKey: rec.nearPublicKey,\n },\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n } catch (e: any) {\n const err = this.emitError(5, e?.message || 'Email recovery finalization failed');\n await this.options?.afterCall?.(false);\n throw err;\n }\n }\n\n private async attemptAutoLogin(rec: PendingEmailRecovery): Promise<AutoLoginResult> {\n try {\n const accountId = toAccountId(rec.accountId);\n const deviceNumber = parseDeviceNumber(rec.deviceNumber, { min: 1 });\n if (deviceNumber === null) {\n return this.handleAutoLoginFailure(\n `Invalid deviceNumber for auto-login: ${String(rec.deviceNumber)}`\n );\n }\n\n const shamirUnlocked = await this.tryShamirUnlock(rec, accountId, deviceNumber);\n if (shamirUnlocked) {\n return { success: true, method: 'shamir' };\n }\n\n const touchIdResult = await this.tryTouchIdUnlock(rec, accountId, deviceNumber);\n if (touchIdResult.success) {\n return { success: true, method: 'touchid' };\n }\n\n return this.handleAutoLoginFailure(touchIdResult.reason || 'Auto-login failed');\n } catch (err: any) {\n return this.handleAutoLoginFailure(err?.message || String(err), err);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4FA,SAAS,uBAAuB,SAQ9B;CACA,MAAM,kBAAkB,QAAQ,QAAQ;CACxC,MAAM,kBAAkB,OAAO,gBAAgB;CAC/C,MAAM,oBAAoB,OAAO,gBAAgB;CACjD,MAAM,uBAAuB,OAAO,gBAAgB;CACpD,MAAM,eAAe,OAAO,gBAAgB;CAC5C,MAAM,gBAAgB,OAAO,gBAAgB;CAC7C,MAAM,wBAAwB,OAAO,gBAAgB;CACrD,MAAM,yBAAyB,OAAO,gBAAgB;AACtD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;;;AAIJ,SAAgB,iCAAyC;CAEvD,MAAM,WAAW;CACjB,MAAM,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UAAM,KAAK,sBAAsB,cAAc;AAE/C,SAAK,mBAAmBA,0CAAoB,UAAU,kDAAkD,EACtG,WAAW;IAGb,MAAM,kBAAkB,MAAM,KAAK,iBAAiB;AACpD,QAAI,gBAAgB,QAClB,MAAK,mBAAmBA,0CAAoB,SAAS,WAAW,aAAa,EAC3E,WAAW;QAGb,MAAK,mBAAmBA,0CAAoB,OAAO,6DAA6D;KAC9G,OAAO,gBAAgB;KACvB,WAAW;;AAIf,UAAM,KAAK,4BAA4B;AAEvC,SAAK,QAAQF,yCAAmB;AAChC,SAAK,KAAK;KACR,MAAM;KACN,OAAOA,yCAAmB;KAC1B,QAAQE,0CAAoB;KAC5B,SAAS;KACT,MAAM;MACJ,WAAW,IAAI;MACf,eAAe,IAAI;;;YAGhBG,GAAQ;IACf,MAAM,MAAM,KAAK,UAAU,GAAG,GAAG,WAAW;AAC5C,UAAM,KAAK,SAAS,YAAY;AAChC,UAAM;;;EAIV,MAAc,iBAAiB,KAAqD;AAClF,OAAI;IACF,MAAM,YAAYD,+BAAY,IAAI;IAClC,MAAM,eAAeW,0CAAkB,IAAI,cAAc,EAAE,KAAK;AAChE,QAAI,iBAAiB,KACnB,QAAO,KAAK,uBACV,wCAAwC,OAAO,IAAI;IAIvD,MAAM,iBAAiB,MAAM,KAAK,gBAAgB,KAAK,WAAW;AAClE,QAAI,eACF,QAAO;KAAE,SAAS;KAAM,QAAQ;;IAGlC,MAAM,gBAAgB,MAAM,KAAK,iBAAiB,KAAK,WAAW;AAClE,QAAI,cAAc,QAChB,QAAO;KAAE,SAAS;KAAM,QAAQ;;AAGlC,WAAO,KAAK,uBAAuB,cAAc,UAAU;YACpDD,KAAU;AACjB,WAAO,KAAK,uBAAuB,KAAK,WAAW,OAAO,MAAM"}
|
|
1
|
+
{"version":3,"file":"emailRecovery.js","names":["EmailRecoveryPhase","EmailRecoveryPendingStore","EmailRecoveryStatus","validateNearAccountId","toAccountId","err: unknown","errorMessage","elapsedMs","rec: PendingEmailRecovery","e: unknown","err","txResult: FinalExecutionOutcome","DEFAULT_WAIT_STATUS","parseLinkDeviceRegisterUserResponse","EmailRecoveryErrorCode","EmailRecoveryError","txUnknown: unknown","logs: string[]","IndexedDBManager","payload: StoreUserDataPayload","getLoginSession","createRandomVRFChallenge","parseDeviceNumber"],"sources":["../../../../src/core/TatchiPasskey/emailRecovery.ts"],"sourcesContent":["import type { PasskeyManagerContext } from './index';\nimport { IndexedDBManager } from '../IndexedDBManager';\nimport { validateNearAccountId } from '../../utils/validation';\nimport { errorMessage } from '../../utils/errors';\nimport { toAccountId, type AccountId } from '../types/accountIds';\nimport {\n EmailRecoveryPhase,\n EmailRecoveryStatus,\n type EmailRecoverySSEEvent,\n type EventCallback,\n type AfterCall,\n} from '../types/sdkSentEvents';\nimport type { TatchiConfigs } from '../types/tatchi';\nimport {\n createRandomVRFChallenge,\n type EncryptedVRFKeypair,\n type ServerEncryptedVrfKeypair,\n type VRFChallenge,\n} from '../types/vrf-worker';\nimport type { FinalExecutionOutcome } from '@near-js/types';\nimport type { StoredAuthenticator, WebAuthnRegistrationCredential } from '../types';\nimport type { ConfirmationConfig } from '../types/signer-worker';\nimport { DEFAULT_WAIT_STATUS } from '../types/rpc';\nimport { parseDeviceNumber } from '../WebAuthnManager/SignerWorkerManager/getDeviceNumber';\nimport { getLoginSession } from './login';\nimport type { SignedTransaction } from '../NearClient';\nimport {\n EmailRecoveryPendingStore,\n parseLinkDeviceRegisterUserResponse,\n type PendingStore,\n} from '../EmailRecovery';\nimport { EmailRecoveryError, EmailRecoveryErrorCode } from '../types/emailRecovery';\n\nexport type PendingEmailRecoveryStatus =\n | 'awaiting-email'\n | 'awaiting-add-key'\n | 'finalizing'\n | 'complete'\n | 'error';\n\nexport type PendingEmailRecovery = {\n accountId: AccountId;\n recoveryEmail: string;\n deviceNumber: number;\n nearPublicKey: string;\n requestId: string;\n encryptedVrfKeypair: EncryptedVRFKeypair;\n serverEncryptedVrfKeypair: ServerEncryptedVrfKeypair | null;\n vrfPublicKey: string;\n credential: WebAuthnRegistrationCredential;\n vrfChallenge?: VRFChallenge;\n createdAt: number;\n status: PendingEmailRecoveryStatus;\n};\n\ntype PollTickResult<T> = { done: false } | { done: true; value: T };\n\ntype PollUntilResult<T> =\n | { status: 'completed'; value: T; elapsedMs: number; pollCount: number }\n | { status: 'timedOut'; elapsedMs: number; pollCount: number }\n | { status: 'cancelled'; elapsedMs: number; pollCount: number };\n\ntype VerificationOutcome =\n | { outcome: 'verified' }\n | { outcome: 'failed'; errorMessage: string };\n\ntype AutoLoginResult =\n | { success: true; method: 'shamir' | 'touchid' }\n | { success: false; reason: string };\n\ntype StoreUserDataPayload = Parameters<PasskeyManagerContext['webAuthnManager']['storeUserData']>[0];\n\ntype AccountViewLike = {\n amount: bigint | string;\n locked: bigint | string;\n storage_usage: number | bigint;\n};\n\ntype CollectedRecoveryCredential = {\n credential: WebAuthnRegistrationCredential;\n vrfChallenge?: VRFChallenge;\n};\n\ntype DerivedRecoveryKeys = {\n encryptedVrfKeypair: EncryptedVRFKeypair;\n serverEncryptedVrfKeypair: ServerEncryptedVrfKeypair | null;\n vrfPublicKey: string;\n nearPublicKey: string;\n};\n\nexport interface EmailRecoveryFlowOptions {\n onEvent?: EventCallback<EmailRecoverySSEEvent>;\n onError?: (error: Error) => void;\n afterCall?: AfterCall<void>;\n pendingStore?: PendingStore;\n confirmerText?: { title?: string; body?: string };\n confirmationConfig?: Partial<ConfirmationConfig>;\n}\n\nfunction getEmailRecoveryConfig(configs: TatchiConfigs): {\n minBalanceYocto: string;\n pollingIntervalMs: number;\n maxPollingDurationMs: number;\n pendingTtlMs: number;\n mailtoAddress: string;\n dkimVerifierAccountId: string;\n verificationViewMethod: string;\n} {\n const relayerEmailCfg = configs.relayer.emailRecovery;\n const minBalanceYocto = String(relayerEmailCfg.minBalanceYocto);\n const pollingIntervalMs = Number(relayerEmailCfg.pollingIntervalMs);\n const maxPollingDurationMs = Number(relayerEmailCfg.maxPollingDurationMs);\n const pendingTtlMs = Number(relayerEmailCfg.pendingTtlMs);\n const mailtoAddress = String(relayerEmailCfg.mailtoAddress);\n const dkimVerifierAccountId = String(relayerEmailCfg.dkimVerifierAccountId);\n const verificationViewMethod = String(relayerEmailCfg.verificationViewMethod);\n return {\n minBalanceYocto,\n pollingIntervalMs,\n maxPollingDurationMs,\n pendingTtlMs,\n mailtoAddress,\n dkimVerifierAccountId,\n verificationViewMethod,\n };\n}\n\nexport function generateEmailRecoveryRequestId(): string {\n // 6-character A–Z0–9 identifier, suitable for short-lived correlation.\n const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';\n const length = 6;\n const bytes = new Uint8Array(length);\n (globalThis.crypto || window.crypto).getRandomValues(bytes);\n let out = '';\n for (let i = 0; i < length; i++) {\n out += alphabet[bytes[i] % alphabet.length];\n }\n return out;\n}\n\nexport class EmailRecoveryFlow {\n private context: PasskeyManagerContext;\n private options?: EmailRecoveryFlowOptions;\n private pendingStore: PendingStore;\n private pending: PendingEmailRecovery | null = null;\n private phase: EmailRecoveryPhase = EmailRecoveryPhase.STEP_1_PREPARATION;\n private pollingTimer: ReturnType<typeof setTimeout> | undefined;\n private pollIntervalResolver?: () => void;\n private pollingStartedAt: number | null = null;\n private cancelled = false;\n private error?: Error;\n\n constructor(context: PasskeyManagerContext, options?: EmailRecoveryFlowOptions) {\n this.context = context;\n this.options = options;\n this.pendingStore = options?.pendingStore ?? new EmailRecoveryPendingStore({\n getPendingTtlMs: () => this.getConfig().pendingTtlMs,\n });\n }\n\n setOptions(options?: EmailRecoveryFlowOptions) {\n if (!options) return;\n this.options = { ...(this.options || {}), ...options };\n if (options.pendingStore) {\n this.pendingStore = options.pendingStore;\n }\n }\n private emit(event: EmailRecoverySSEEvent) {\n this.options?.onEvent?.(event);\n }\n\n private emitError(step: number, messageOrError: string | Error): Error {\n const err = typeof messageOrError === 'string' ? new Error(messageOrError) : messageOrError;\n const message = err.message || (typeof messageOrError === 'string' ? messageOrError : 'Unknown error');\n this.phase = EmailRecoveryPhase.ERROR;\n this.error = err;\n this.emit({\n step,\n phase: EmailRecoveryPhase.ERROR,\n status: EmailRecoveryStatus.ERROR,\n message,\n error: message,\n } as EmailRecoverySSEEvent & { error: string });\n this.options?.onError?.(err);\n return err;\n }\n\n private async fail(step: number, message: string): Promise<never> {\n const err = this.emitError(step, message);\n await this.options?.afterCall?.(false);\n throw err;\n }\n\n private async assertValidAccountIdOrFail(step: number, accountId: string): Promise<AccountId> {\n const validation = validateNearAccountId(accountId as AccountId);\n if (!validation.valid) {\n await this.fail(step, `Invalid NEAR account ID: ${validation.error}`);\n }\n return toAccountId(accountId as string);\n }\n\n private async resolvePendingOrFail(\n step: number,\n args: { accountId: AccountId; nearPublicKey?: string },\n options?: {\n allowErrorStatus?: boolean;\n missingMessage?: string;\n errorStatusMessage?: string;\n }\n ): Promise<PendingEmailRecovery> {\n const {\n allowErrorStatus = true,\n missingMessage = 'No pending email recovery record found for this account',\n errorStatusMessage = 'Pending email recovery is in an error state; please restart the flow',\n } = options ?? {};\n\n let rec = this.pending;\n if (!rec || rec.accountId !== args.accountId || (args.nearPublicKey && rec.nearPublicKey !== args.nearPublicKey)) {\n rec = await this.loadPending(args.accountId, args.nearPublicKey);\n this.pending = rec;\n }\n\n if (!rec) {\n await this.fail(step, missingMessage);\n }\n\n const resolved = rec as PendingEmailRecovery;\n if (!allowErrorStatus && resolved.status === 'error') {\n await this.fail(step, errorStatusMessage);\n }\n\n return resolved;\n }\n\n private getConfig() {\n return getEmailRecoveryConfig(this.context.configs);\n }\n\n private toBigInt(value: bigint | number | string | null | undefined): bigint {\n if (typeof value === 'bigint') return value;\n if (typeof value === 'number') return BigInt(value);\n if (typeof value === 'string' && value.length > 0) return BigInt(value);\n return BigInt(0);\n }\n\n private computeAvailableBalance(accountView: AccountViewLike): bigint {\n const STORAGE_PRICE_PER_BYTE = BigInt('10000000000000000000'); // 1e19 yocto NEAR per byte\n const amount = this.toBigInt(accountView.amount);\n const locked = this.toBigInt(accountView.locked);\n const storageUsage = this.toBigInt(accountView.storage_usage);\n const storageCost = storageUsage * STORAGE_PRICE_PER_BYTE;\n const rawAvailable = amount - locked - storageCost;\n return rawAvailable > 0 ? rawAvailable : BigInt(0);\n }\n\n private async assertSufficientBalance(nearAccountId: AccountId): Promise<void> {\n const { minBalanceYocto } = this.getConfig();\n\n try {\n const accountView = await this.context.nearClient.viewAccount(nearAccountId);\n const available = this.computeAvailableBalance(accountView);\n if (available < BigInt(minBalanceYocto)) {\n await this.fail(\n 1,\n `This account does not have enough NEAR to finalize recovery. Available: ${available.toString()} yocto; required: ${String(minBalanceYocto)}. Please top up and try again.`\n );\n }\n } catch (err: unknown) {\n await this.fail(1, errorMessage(err) || 'Failed to fetch account balance for recovery');\n }\n }\n\n private async getCanonicalRecoveryEmailOrFail(recoveryEmail: string): Promise<string> {\n const canonicalEmail = String(recoveryEmail || '').trim().toLowerCase();\n if (!canonicalEmail) {\n await this.fail(1, 'Recovery email is required for email-based account recovery');\n }\n return canonicalEmail;\n }\n\n private async getNextDeviceNumberFromContract(nearAccountId: AccountId): Promise<number> {\n try {\n const { syncAuthenticatorsContractCall } = await import('../rpcCalls');\n const authenticators = await syncAuthenticatorsContractCall(\n this.context.nearClient,\n this.context.configs.contractId,\n nearAccountId\n );\n const numbers = authenticators\n .map(({ authenticator }) => authenticator.deviceNumber)\n .filter((n): n is number => typeof n === 'number' && Number.isFinite(n));\n const max = numbers.length > 0 ? Math.max(...numbers) : 0;\n return max + 1;\n } catch {\n return 1;\n }\n }\n\n private async collectRecoveryCredentialOrFail(\n nearAccountId: AccountId,\n deviceNumber: number\n ): Promise<CollectedRecoveryCredential> {\n const confirmerText = {\n title: this.options?.confirmerText?.title ?? 'Register New Recovery Account',\n body: this.options?.confirmerText?.body ?? 'Create a recovery account and send an encrypted email to recover your account.',\n };\n const confirm = await this.context.webAuthnManager.requestRegistrationCredentialConfirmation({\n nearAccountId,\n deviceNumber,\n confirmerText,\n confirmationConfigOverride: this.options?.confirmationConfig,\n });\n\n if (!confirm.confirmed || !confirm.credential) {\n await this.fail(2, 'User cancelled email recovery TouchID confirmation');\n }\n\n return {\n credential: confirm.credential,\n vrfChallenge: confirm.vrfChallenge || undefined,\n };\n }\n\n private async deriveRecoveryKeysOrFail(\n nearAccountId: AccountId,\n deviceNumber: number,\n credential: WebAuthnRegistrationCredential\n ): Promise<DerivedRecoveryKeys> {\n const vrfDerivationResult = await this.context.webAuthnManager.deriveVrfKeypair({\n credential,\n nearAccountId,\n });\n\n if (!vrfDerivationResult.success || !vrfDerivationResult.encryptedVrfKeypair) {\n await this.fail(2, 'Failed to derive VRF keypair from PRF for email recovery');\n }\n\n const nearKeyResult = await this.context.webAuthnManager.deriveNearKeypairAndEncryptFromSerialized({\n nearAccountId,\n credential,\n options: { deviceNumber },\n });\n\n if (!nearKeyResult.success || !nearKeyResult.publicKey) {\n await this.fail(2, 'Failed to derive NEAR keypair for email recovery');\n }\n\n return {\n encryptedVrfKeypair: vrfDerivationResult.encryptedVrfKeypair,\n serverEncryptedVrfKeypair: vrfDerivationResult.serverEncryptedVrfKeypair || null,\n vrfPublicKey: vrfDerivationResult.vrfPublicKey,\n nearPublicKey: nearKeyResult.publicKey,\n };\n }\n\n private emitAwaitEmail(rec: PendingEmailRecovery, mailtoUrl: string): void {\n this.phase = EmailRecoveryPhase.STEP_3_AWAIT_EMAIL;\n this.emit({\n step: 3,\n phase: EmailRecoveryPhase.STEP_3_AWAIT_EMAIL,\n status: EmailRecoveryStatus.PROGRESS,\n message: 'New device key created; please send the recovery email from your registered address.',\n data: {\n accountId: rec.accountId,\n recoveryEmail: rec.recoveryEmail,\n nearPublicKey: rec.nearPublicKey,\n requestId: rec.requestId,\n mailtoUrl,\n },\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n }\n\n private emitAutoLoginEvent(\n status: EmailRecoveryStatus,\n message: string,\n data: Record<string, unknown>\n ): void {\n this.emit({\n step: 5,\n phase: EmailRecoveryPhase.STEP_5_FINALIZING_REGISTRATION,\n status,\n message,\n data,\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n }\n\n private async checkViaDkimViewMethod(\n rec: PendingEmailRecovery\n ): Promise<{ completed: boolean; success: boolean; errorMessage?: string; transactionHash?: string } | null> {\n const { dkimVerifierAccountId, verificationViewMethod } = this.getConfig();\n if (!dkimVerifierAccountId) return null;\n\n try {\n const { getEmailRecoveryVerificationResult } = await import('../rpcCalls');\n const result = await getEmailRecoveryVerificationResult(\n this.context.nearClient,\n dkimVerifierAccountId,\n verificationViewMethod,\n rec.requestId\n );\n\n if (!result) {\n return { completed: false, success: false };\n }\n\n if (!result.verified) {\n const errorMessage = result.error_message || result.error_code || 'Email verification failed on relayer/contract';\n return {\n completed: true,\n success: false,\n errorMessage,\n transactionHash: result.transaction_hash,\n };\n }\n\n // Optional safety checks: ensure the bound account/key match expectations when available.\n if (result.account_id && result.account_id !== rec.accountId) {\n return {\n completed: true,\n success: false,\n errorMessage: 'Email verification account_id does not match requested account.',\n transactionHash: result.transaction_hash,\n };\n }\n if (result.new_public_key && result.new_public_key !== rec.nearPublicKey) {\n return {\n completed: true,\n success: false,\n errorMessage: 'Email verification new_public_key does not match expected recovery key.',\n transactionHash: result.transaction_hash,\n };\n }\n\n return {\n completed: true,\n success: true,\n transactionHash: result.transaction_hash\n };\n } catch (err) {\n // Treat view errors as retryable; keep polling the view method.\n // eslint-disable-next-line no-console\n console.warn('[EmailRecoveryFlow] get_verification_result view failed; will retry', err);\n return null;\n }\n }\n\n private buildPollingEventData(\n rec: PendingEmailRecovery,\n details: { transactionHash?: string; elapsedMs: number; pollCount: number }\n ): Record<string, unknown> {\n return {\n accountId: rec.accountId,\n requestId: rec.requestId,\n nearPublicKey: rec.nearPublicKey,\n transactionHash: details.transactionHash,\n elapsedMs: details.elapsedMs,\n pollCount: details.pollCount,\n };\n }\n\n private async sleepForPollInterval(ms: number): Promise<void> {\n await new Promise<void>(resolve => {\n this.pollIntervalResolver = resolve;\n this.pollingTimer = setTimeout(() => {\n this.pollIntervalResolver = undefined;\n this.pollingTimer = undefined;\n resolve();\n }, ms);\n }).finally(() => {\n this.pollIntervalResolver = undefined;\n });\n }\n\n private async pollUntil<T>(args: {\n intervalMs: number;\n timeoutMs: number;\n isCancelled: () => boolean;\n tick: (ctx: { elapsedMs: number; pollCount: number }) => Promise<PollTickResult<T>>;\n sleep?: (ms: number) => Promise<void>;\n now?: () => number;\n }): Promise<PollUntilResult<T>> {\n const now = args.now ?? Date.now;\n const sleep = args.sleep ?? this.sleepForPollInterval.bind(this);\n const startedAt = now();\n let pollCount = 0;\n\n while (!args.isCancelled()) {\n pollCount += 1;\n const elapsedMs = now() - startedAt;\n if (elapsedMs > args.timeoutMs) {\n return { status: 'timedOut', elapsedMs, pollCount };\n }\n\n const result = await args.tick({ elapsedMs, pollCount });\n if (result.done) {\n return { status: 'completed', value: result.value, elapsedMs, pollCount };\n }\n\n if (args.isCancelled()) {\n return { status: 'cancelled', elapsedMs, pollCount };\n }\n\n await sleep(args.intervalMs);\n }\n\n const elapsedMs = now() - startedAt;\n return { status: 'cancelled', elapsedMs, pollCount };\n }\n\n private async loadPending(\n accountId: AccountId,\n nearPublicKey?: string\n ): Promise<PendingEmailRecovery | null> {\n return this.pendingStore.get(accountId, nearPublicKey);\n }\n\n private async savePending(rec: PendingEmailRecovery): Promise<void> {\n await this.pendingStore.set(rec);\n this.pending = rec;\n }\n\n private async clearPending(accountId: AccountId, nearPublicKey?: string): Promise<void> {\n await this.pendingStore.clear(accountId, nearPublicKey);\n\n if (\n this.pending\n && this.pending.accountId === accountId\n && (!nearPublicKey || this.pending.nearPublicKey === nearPublicKey)\n ) {\n this.pending = null;\n }\n }\n\n getState() {\n return {\n phase: this.phase,\n pending: this.pending,\n error: this.error,\n };\n }\n\n async buildMailtoUrl(args: { accountId: string; nearPublicKey?: string }): Promise<string> {\n const { accountId, nearPublicKey } = args;\n this.cancelled = false;\n this.error = undefined;\n\n const nearAccountId = await this.assertValidAccountIdOrFail(3, accountId);\n const rec = await this.resolvePendingOrFail(\n 3,\n { accountId: nearAccountId, nearPublicKey },\n { allowErrorStatus: false }\n );\n\n if (rec.status === 'finalizing' || rec.status === 'complete') {\n await this.fail(3, 'Recovery email has already been processed on-chain for this request');\n }\n\n const mailtoUrl =\n rec.status === 'awaiting-email'\n ? await this.buildMailtoUrlAndUpdateStatus(rec)\n : this.buildMailtoUrlInternal(rec);\n this.emitAwaitEmail(rec, mailtoUrl);\n await this.options?.afterCall?.(true, undefined);\n return mailtoUrl;\n }\n\n async start(args: { accountId: string; recoveryEmail: string }): Promise<{ mailtoUrl: string; nearPublicKey: string }> {\n const { accountId, recoveryEmail } = args;\n this.cancelled = false;\n this.error = undefined;\n this.phase = EmailRecoveryPhase.STEP_1_PREPARATION;\n\n this.emit({\n step: 1,\n phase: EmailRecoveryPhase.STEP_1_PREPARATION,\n status: EmailRecoveryStatus.PROGRESS,\n message: 'Preparing email recovery...',\n });\n\n const nearAccountId = await this.assertValidAccountIdOrFail(1, accountId);\n await this.assertSufficientBalance(nearAccountId);\n const canonicalEmail = await this.getCanonicalRecoveryEmailOrFail(recoveryEmail);\n\n // Determine deviceNumber from on-chain authenticators\n const deviceNumber = await this.getNextDeviceNumberFromContract(nearAccountId);\n\n this.phase = EmailRecoveryPhase.STEP_2_TOUCH_ID_REGISTRATION;\n this.emit({\n step: 2,\n phase: EmailRecoveryPhase.STEP_2_TOUCH_ID_REGISTRATION,\n status: EmailRecoveryStatus.PROGRESS,\n message: 'Collecting passkey for email recovery...',\n });\n\n try {\n const confirm = await this.collectRecoveryCredentialOrFail(nearAccountId, deviceNumber);\n const derivedKeys = await this.deriveRecoveryKeysOrFail(nearAccountId, deviceNumber, confirm.credential);\n\n const rec: PendingEmailRecovery = {\n accountId: nearAccountId,\n recoveryEmail: canonicalEmail,\n deviceNumber,\n nearPublicKey: derivedKeys.nearPublicKey,\n requestId: generateEmailRecoveryRequestId(),\n encryptedVrfKeypair: derivedKeys.encryptedVrfKeypair,\n serverEncryptedVrfKeypair: derivedKeys.serverEncryptedVrfKeypair,\n vrfPublicKey: derivedKeys.vrfPublicKey,\n credential: confirm.credential,\n vrfChallenge: confirm.vrfChallenge || undefined,\n createdAt: Date.now(),\n status: 'awaiting-email',\n };\n\n const mailtoUrl = await this.buildMailtoUrlAndUpdateStatus(rec);\n\n this.emitAwaitEmail(rec, mailtoUrl);\n\n await this.options?.afterCall?.(true, undefined);\n\n return { mailtoUrl, nearPublicKey: rec.nearPublicKey };\n } catch (e: unknown) {\n const err = this.emitError(2, errorMessage(e) || 'Email recovery TouchID/derivation failed');\n await this.options?.afterCall?.(false);\n throw err;\n }\n }\n\n private buildMailtoUrlInternal(rec: PendingEmailRecovery): string {\n const { mailtoAddress } = this.getConfig();\n const to = encodeURIComponent(mailtoAddress);\n const subject = encodeURIComponent(`recover-${rec.requestId} ${rec.accountId} ${rec.nearPublicKey}`);\n const body = encodeURIComponent(`Recovering account ${rec.accountId} with a new passkey.`);\n return `mailto:${to}?subject=${subject}&body=${body}`;\n }\n\n private async buildMailtoUrlAndUpdateStatus(rec: PendingEmailRecovery): Promise<string> {\n rec.status = 'awaiting-add-key';\n await this.savePending(rec);\n return this.buildMailtoUrlInternal(rec);\n }\n\n async startPolling(args: { accountId: string; nearPublicKey?: string }): Promise<void> {\n const { accountId, nearPublicKey } = args;\n this.cancelled = false;\n this.error = undefined;\n\n const nearAccountId = await this.assertValidAccountIdOrFail(4, accountId);\n const rec = await this.resolvePendingOrFail(\n 4,\n { accountId: nearAccountId, nearPublicKey },\n { allowErrorStatus: false }\n );\n if (rec.status === 'complete' || rec.status === 'finalizing') {\n await this.options?.afterCall?.(true, undefined);\n return;\n }\n if (rec.status === 'awaiting-email') {\n await this.buildMailtoUrlAndUpdateStatus(rec);\n }\n\n await this.pollUntilAddKey(rec);\n await this.options?.afterCall?.(true, undefined);\n }\n\n stopPolling(): void {\n this.cancelled = true;\n if (this.pollingTimer) {\n clearTimeout(this.pollingTimer);\n this.pollingTimer = undefined;\n }\n if (this.pollIntervalResolver) {\n this.pollIntervalResolver();\n this.pollIntervalResolver = undefined;\n }\n }\n\n /**\n * Best-effort cancellation and local state reset so callers can retry.\n * This does not remove any passkey created in the browser/OS (WebAuthn has no delete API),\n * but it will stop polling and clear the pending IndexedDB record for the given key.\n */\n async cancelAndReset(args?: { accountId?: string; nearPublicKey?: string }): Promise<void> {\n this.stopPolling();\n\n const normalizedAccountId = (args?.accountId || this.pending?.accountId || '').toString().trim();\n const nearPublicKey = (args?.nearPublicKey || this.pending?.nearPublicKey || '').toString().trim();\n\n if (normalizedAccountId) {\n try {\n await this.clearPending(toAccountId(normalizedAccountId), nearPublicKey);\n } catch {\n // best-effort\n }\n }\n\n this.pending = null;\n this.error = undefined;\n this.phase = EmailRecoveryPhase.STEP_1_PREPARATION;\n }\n\n async finalize(args: { accountId: string; nearPublicKey?: string }): Promise<void> {\n const { accountId, nearPublicKey } = args;\n this.cancelled = false;\n this.error = undefined;\n\n const nearAccountId = await this.assertValidAccountIdOrFail(4, accountId);\n const rec = await this.resolvePendingOrFail(\n 4,\n { accountId: nearAccountId, nearPublicKey },\n { allowErrorStatus: true }\n );\n\n this.emit({\n step: 0,\n phase: EmailRecoveryPhase.RESUMED_FROM_PENDING,\n status: EmailRecoveryStatus.PROGRESS,\n message: 'Resuming email recovery from pending state...',\n data: {\n accountId: rec.accountId,\n nearPublicKey: rec.nearPublicKey,\n status: rec.status,\n },\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n\n if (rec.status === 'complete') {\n this.phase = EmailRecoveryPhase.STEP_6_COMPLETE;\n this.emit({\n step: 6,\n phase: EmailRecoveryPhase.STEP_6_COMPLETE,\n status: EmailRecoveryStatus.SUCCESS,\n message: 'Email recovery already completed for this key.',\n });\n await this.options?.afterCall?.(true, undefined);\n return;\n }\n\n // Ensure verification has completed successfully before finalizing registration.\n await this.pollUntilAddKey(rec);\n await this.finalizeRegistration(rec);\n await this.options?.afterCall?.(true, undefined);\n }\n\n private async pollUntilAddKey(rec: PendingEmailRecovery): Promise<void> {\n const { pollingIntervalMs, maxPollingDurationMs, dkimVerifierAccountId } = this.getConfig();\n if (!dkimVerifierAccountId) {\n const err = this.emitError(4, 'Email recovery verification contract (dkimVerifierAccountId) is not configured');\n await this.options?.afterCall?.(false);\n throw err;\n }\n this.phase = EmailRecoveryPhase.STEP_4_POLLING_VERIFICATION_RESULT;\n this.pollingStartedAt = Date.now();\n\n const pollResult = await this.pollUntil<VerificationOutcome>({\n intervalMs: pollingIntervalMs,\n timeoutMs: maxPollingDurationMs,\n isCancelled: () => this.cancelled,\n tick: async ({ elapsedMs, pollCount }) => {\n const verification = await this.checkViaDkimViewMethod(rec);\n const completed = verification?.completed === true;\n const success = verification?.success === true;\n\n this.emit({\n step: 4,\n phase: EmailRecoveryPhase.STEP_4_POLLING_VERIFICATION_RESULT,\n status: EmailRecoveryStatus.PROGRESS,\n message: completed && success\n ? `Email verified for request ${rec.requestId}; finalizing registration`\n : `Waiting for email verification for request ${rec.requestId}`,\n data: this.buildPollingEventData(rec, {\n transactionHash: verification?.transactionHash,\n elapsedMs,\n pollCount,\n }),\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n\n if (!completed) {\n return { done: false };\n }\n\n if (!success) {\n return {\n done: true,\n value: {\n outcome: 'failed',\n errorMessage: verification?.errorMessage || 'Email verification failed',\n },\n };\n }\n\n return { done: true, value: { outcome: 'verified' } };\n },\n });\n\n if (pollResult.status === 'completed') {\n if (pollResult.value.outcome === 'failed') {\n const err = this.emitError(4, pollResult.value.errorMessage);\n rec.status = 'error';\n await this.savePending(rec);\n await this.options?.afterCall?.(false);\n throw err;\n }\n\n rec.status = 'finalizing';\n await this.savePending(rec);\n return;\n }\n\n if (pollResult.status === 'timedOut') {\n const err = this.emitError(4, 'Timed out waiting for recovery email to be processed on-chain');\n rec.status = 'error';\n await this.savePending(rec);\n await this.options?.afterCall?.(false);\n throw err;\n }\n\n const err = this.emitError(4, 'Email recovery polling was cancelled');\n await this.options?.afterCall?.(false);\n throw err;\n }\n\n private initializeNonceManager(\n rec: PendingEmailRecovery\n ): {\n nonceManager: ReturnType<PasskeyManagerContext['webAuthnManager']['getNonceManager']>;\n accountId: AccountId;\n } {\n const nonceManager = this.context.webAuthnManager.getNonceManager();\n const accountId = toAccountId(rec.accountId);\n nonceManager.initializeUser(accountId, rec.nearPublicKey);\n return { nonceManager, accountId };\n }\n\n /*\n * Signs a `link_device_register_user` contract call\n */\n private async signNewDevice2RegistrationTx(rec: PendingEmailRecovery, accountId: AccountId): Promise<SignedTransaction> {\n const vrfChallenge = rec.vrfChallenge;\n if (!vrfChallenge) {\n return this.fail(5, 'Missing VRF challenge for email recovery registration');\n }\n\n const registrationResult = await this.context.webAuthnManager.signDevice2RegistrationWithStoredKey({\n nearAccountId: accountId,\n credential: rec.credential,\n vrfChallenge,\n deterministicVrfPublicKey: rec.vrfPublicKey,\n deviceNumber: rec.deviceNumber,\n });\n\n if (!registrationResult.success || !registrationResult.signedTransaction) {\n await this.fail(5, registrationResult.error || 'Failed to sign email recovery registration transaction');\n }\n\n return registrationResult.signedTransaction;\n }\n\n private async broadcastRegistrationTxAndWaitFinal(\n rec: PendingEmailRecovery,\n signedTx: SignedTransaction\n ): Promise<string | undefined> {\n let txResult: FinalExecutionOutcome;\n try {\n txResult = await this.context.nearClient.sendTransaction(\n signedTx,\n DEFAULT_WAIT_STATUS.linkDeviceRegistration\n );\n } catch (err: unknown) {\n const msg = errorMessage(err) || 'Failed to broadcast email recovery registration transaction (insufficient funds or RPC error)';\n throw new Error(msg);\n }\n\n const txHash = this.getTxHash(txResult);\n\n // Contract can return `{ verified: false, registration_info: null }` without failing the tx.\n // When that happens, the authenticator was NOT registered on-chain, so we must not proceed\n // with local persistence + auto-login.\n const linkDeviceResult = parseLinkDeviceRegisterUserResponse(txResult);\n if (linkDeviceResult?.verified === false) {\n const logs = this.extractNearExecutionLogs(txResult);\n const isStaleChallenge = logs.some((log) => /StaleChallenge|freshness validation failed/i.test(log));\n const txHint = txHash ? ` (tx: ${txHash})` : '';\n const code = isStaleChallenge\n ? EmailRecoveryErrorCode.VRF_CHALLENGE_EXPIRED\n : EmailRecoveryErrorCode.REGISTRATION_NOT_VERIFIED;\n const message = isStaleChallenge\n ? `Timed out finalizing registration (VRF challenge expired). Please restart email recovery and try again${txHint}.`\n : `Registration did not verify on-chain. Please try again${txHint}.`;\n throw new EmailRecoveryError(message, code, {\n accountId: rec.accountId,\n nearPublicKey: rec.nearPublicKey,\n transactionHash: txHash,\n logs,\n result: linkDeviceResult,\n });\n }\n\n if (txHash) {\n this.emit({\n step: 5,\n phase: EmailRecoveryPhase.STEP_5_FINALIZING_REGISTRATION,\n status: EmailRecoveryStatus.PROGRESS,\n message: 'Registration transaction confirmed',\n data: {\n accountId: rec.accountId,\n nearPublicKey: rec.nearPublicKey,\n transactionHash: txHash,\n },\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n }\n\n return txHash;\n }\n\n private getTxHash(outcome: FinalExecutionOutcome): string | undefined {\n const txUnknown: unknown = outcome.transaction;\n if (txUnknown && typeof txUnknown === 'object') {\n const hash = (txUnknown as Record<string, unknown>).hash;\n if (typeof hash === 'string' && hash.length > 0) return hash;\n }\n\n const fallback = (outcome as unknown as Record<string, unknown>).transaction_hash;\n return typeof fallback === 'string' && fallback.length > 0 ? fallback : undefined;\n }\n\n private extractNearExecutionLogs(outcome: FinalExecutionOutcome): string[] {\n const logs: string[] = [];\n for (const entry of outcome.transaction_outcome.outcome.logs) {\n logs.push(String(entry));\n }\n for (const receipt of outcome.receipts_outcome) {\n for (const entry of receipt.outcome.logs) {\n logs.push(String(entry));\n }\n }\n return logs;\n }\n\n private mapAuthenticatorsFromContract(\n authenticators: Array<{ credentialId: string; authenticator: StoredAuthenticator }>\n ) {\n return authenticators.map(({ authenticator }) => ({\n credentialId: authenticator.credentialId,\n credentialPublicKey: authenticator.credentialPublicKey,\n transports: authenticator.transports,\n name: authenticator.name,\n registered: authenticator.registered.toISOString(),\n vrfPublicKey: authenticator.vrfPublicKeys?.[0] || '',\n deviceNumber: authenticator.deviceNumber,\n }));\n }\n\n private async syncAuthenticatorsBestEffort(accountId: AccountId): Promise<boolean> {\n try {\n const { syncAuthenticatorsContractCall } = await import('../rpcCalls');\n const authenticators = await syncAuthenticatorsContractCall(\n this.context.nearClient,\n this.context.configs.contractId,\n accountId\n );\n\n const mappedAuthenticators = this.mapAuthenticatorsFromContract(authenticators);\n await IndexedDBManager.clientDB.syncAuthenticatorsFromContract(accountId, mappedAuthenticators);\n return true;\n } catch (err) {\n console.warn('[EmailRecoveryFlow] Failed to sync authenticators after recovery:', err);\n return false;\n }\n }\n\n private async setLastUserBestEffort(accountId: AccountId, deviceNumber: number): Promise<boolean> {\n try {\n await IndexedDBManager.clientDB.setLastUser(accountId, deviceNumber);\n return true;\n } catch (err) {\n console.warn('[EmailRecoveryFlow] Failed to set last user after recovery:', err);\n return false;\n }\n }\n\n private async updateNonceBestEffort(\n nonceManager: ReturnType<PasskeyManagerContext['webAuthnManager']['getNonceManager']>,\n signedTx: SignedTransaction\n ): Promise<void> {\n try {\n const txNonce = signedTx.transaction.nonce;\n if (txNonce != null) {\n await nonceManager.updateNonceFromBlockchain(\n this.context.nearClient,\n String(txNonce)\n );\n }\n } catch {\n // best-effort; do not fail flow\n }\n }\n\n private async persistRecoveredUserData(rec: PendingEmailRecovery, accountId: AccountId): Promise<void> {\n const { webAuthnManager } = this.context;\n\n const payload: StoreUserDataPayload = {\n nearAccountId: accountId,\n deviceNumber: rec.deviceNumber,\n clientNearPublicKey: rec.nearPublicKey,\n lastUpdated: Date.now(),\n passkeyCredential: {\n id: rec.credential.id,\n rawId: rec.credential.rawId,\n },\n encryptedVrfKeypair: {\n encryptedVrfDataB64u: rec.encryptedVrfKeypair.encryptedVrfDataB64u,\n chacha20NonceB64u: rec.encryptedVrfKeypair.chacha20NonceB64u,\n },\n serverEncryptedVrfKeypair: rec.serverEncryptedVrfKeypair || undefined,\n };\n\n await webAuthnManager.storeUserData(payload);\n }\n\n /**\n * Explicitly persist the authenticator from the recovery record into the local cache.\n * This ensures the key is available immediately, bridging the gap before RPC sync sees it.\n */\n private async persistAuthenticatorBestEffort(rec: PendingEmailRecovery, accountId: AccountId): Promise<void> {\n try {\n const { webAuthnManager } = this.context;\n const attestationB64u = rec.credential.response.attestationObject;\n const credentialPublicKey = await webAuthnManager.extractCosePublicKey(attestationB64u);\n\n await webAuthnManager.storeAuthenticator({\n nearAccountId: accountId,\n deviceNumber: rec.deviceNumber,\n credentialId: rec.credential.rawId,\n credentialPublicKey,\n transports: ['internal'],\n name: `Device ${rec.deviceNumber} Passkey for ${rec.accountId.split('.')[0]}`,\n registered: new Date().toISOString(),\n syncedAt: new Date().toISOString(), // Local truth is fresh\n vrfPublicKey: rec.vrfPublicKey,\n });\n console.log('[EmailRecoveryFlow] Locally persisted recovered authenticator for immediate use.');\n } catch (e) {\n console.error('[EmailRecoveryFlow] Failed to locally persist authenticator (critical for immediate export):', e);\n // We log error but don't rethrow to avoid crashing the final success UI.\n }\n }\n\n private async markCompleteAndClearPending(rec: PendingEmailRecovery): Promise<void> {\n rec.status = 'complete';\n await this.savePending(rec);\n await this.clearPending(rec.accountId, rec.nearPublicKey);\n }\n\n private async assertVrfActiveForAccount(accountId: AccountId, message: string): Promise<void> {\n const vrfStatus = await this.context.webAuthnManager.checkVrfStatus();\n const vrfActiveForAccount =\n vrfStatus.active\n && vrfStatus.nearAccountId\n && String(vrfStatus.nearAccountId) === String(accountId);\n if (!vrfActiveForAccount) {\n throw new Error(message);\n }\n }\n\n private async finalizeLocalLoginState(accountId: AccountId, deviceNumber: number): Promise<void> {\n const { webAuthnManager } = this.context;\n await webAuthnManager.setLastUser(accountId, deviceNumber);\n await webAuthnManager.initializeCurrentUser(accountId, this.context.nearClient);\n try { await getLoginSession(this.context, accountId); } catch { }\n }\n\n private async tryShamirUnlock(\n rec: PendingEmailRecovery,\n accountId: AccountId,\n deviceNumber: number\n ): Promise<boolean> {\n if (\n !rec.serverEncryptedVrfKeypair\n || !rec.serverEncryptedVrfKeypair.serverKeyId\n || !this.context.configs.vrfWorkerConfigs?.shamir3pass?.relayServerUrl\n ) {\n return false;\n }\n\n try {\n const { webAuthnManager } = this.context;\n const unlockResult = await webAuthnManager.shamir3PassDecryptVrfKeypair({\n nearAccountId: accountId,\n kek_s_b64u: rec.serverEncryptedVrfKeypair.kek_s_b64u,\n ciphertextVrfB64u: rec.serverEncryptedVrfKeypair.ciphertextVrfB64u,\n serverKeyId: rec.serverEncryptedVrfKeypair.serverKeyId,\n });\n\n if (!unlockResult.success) {\n return false;\n }\n\n await this.assertVrfActiveForAccount(accountId, 'VRF session inactive after Shamir3Pass unlock');\n await this.finalizeLocalLoginState(accountId, deviceNumber);\n return true;\n } catch (err) {\n console.warn('[EmailRecoveryFlow] Shamir 3-pass unlock failed, falling back to TouchID', err);\n return false;\n }\n }\n\n private async tryTouchIdUnlock(\n rec: PendingEmailRecovery,\n accountId: AccountId,\n deviceNumber: number\n ): Promise<{ success: boolean; reason?: string }> {\n try {\n const { webAuthnManager } = this.context;\n const authChallenge = createRandomVRFChallenge() as VRFChallenge;\n\n const storedCredentialId = String(rec.credential?.rawId || rec.credential?.id || '').trim();\n const credentialIds = storedCredentialId ? [storedCredentialId] : [];\n const authenticators = credentialIds.length > 0\n ? []\n : await webAuthnManager.getAuthenticatorsByUser(accountId);\n const authCredential = await webAuthnManager.getAuthenticationCredentialsSerializedDualPrf({\n nearAccountId: accountId,\n challenge: authChallenge,\n credentialIds: credentialIds.length > 0 ? credentialIds : authenticators.map((a) => a.credentialId),\n });\n\n if (storedCredentialId && authCredential.rawId !== storedCredentialId) {\n return {\n success: false,\n reason: 'Wrong passkey selected during recovery auto-login; please use the newly recovered passkey.',\n };\n }\n\n const vrfUnlockResult = await webAuthnManager.unlockVRFKeypair({\n nearAccountId: accountId,\n encryptedVrfKeypair: rec.encryptedVrfKeypair,\n credential: authCredential,\n });\n\n if (!vrfUnlockResult.success) {\n return { success: false, reason: vrfUnlockResult.error || 'VRF unlock failed during auto-login' };\n }\n\n await this.assertVrfActiveForAccount(accountId, 'VRF session inactive after TouchID unlock');\n await this.finalizeLocalLoginState(accountId, deviceNumber);\n return { success: true };\n } catch (err: unknown) {\n return { success: false, reason: errorMessage(err) || String(err) };\n }\n }\n\n private async handleAutoLoginFailure(reason: string, err?: unknown): Promise<AutoLoginResult> {\n console.warn('[EmailRecoveryFlow] Auto-login failed after recovery', err ?? reason);\n try {\n await this.context.webAuthnManager.clearVrfSession();\n } catch { }\n return { success: false, reason };\n }\n\n private async finalizeRegistration(rec: PendingEmailRecovery): Promise<void> {\n this.phase = EmailRecoveryPhase.STEP_5_FINALIZING_REGISTRATION;\n this.emit({\n step: 5,\n phase: EmailRecoveryPhase.STEP_5_FINALIZING_REGISTRATION,\n status: EmailRecoveryStatus.PROGRESS,\n message: 'Finalizing email recovery registration...',\n data: {\n accountId: rec.accountId,\n nearPublicKey: rec.nearPublicKey,\n },\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n\n try {\n const { nonceManager, accountId } = this.initializeNonceManager(rec);\n const signedTx = await this.signNewDevice2RegistrationTx(rec, accountId);\n const txHash = await this.broadcastRegistrationTxAndWaitFinal(rec, signedTx);\n if (!txHash) {\n console.warn('[EmailRecoveryFlow] Registration transaction confirmed without hash; continuing local persistence');\n }\n\n // CRITICAL: Persist local state immediately.\n // 1. Store the new user record (Device N) so that `getLastUser()` finds it.\n await this.persistRecoveredUserData(rec, accountId);\n\n // 2. Sync authenticators (RPC might be stale, but we try).\n await this.syncAuthenticatorsBestEffort(accountId);\n\n // 3. FORCE-SAVE the local authenticator from our recovery record.\n // This is crucial because RPC sync might be slow/empty immediately after TX.\n // We must ensure the new key is in the DB so `ensureCurrentPasskey` finds it.\n // We do this AFTER sync to ensure it's not wiped by a stale sync.\n await this.persistAuthenticatorBestEffort(rec, accountId);\n\n // 4. Set as active user to ensure immediate subsequent calls use this identity.\n await this.setLastUserBestEffort(accountId, rec.deviceNumber);\n\n await this.updateNonceBestEffort(nonceManager, signedTx);\n\n this.emitAutoLoginEvent(EmailRecoveryStatus.PROGRESS, 'Attempting auto-login with recovered device...', {\n autoLogin: 'progress',\n });\n\n const autoLoginResult = await this.attemptAutoLogin(rec);\n if (autoLoginResult.success) {\n this.emitAutoLoginEvent(EmailRecoveryStatus.SUCCESS, `Welcome ${accountId}`, {\n autoLogin: 'success',\n });\n } else {\n this.emitAutoLoginEvent(EmailRecoveryStatus.ERROR, 'Auto-login failed; please log in manually on this device.', {\n error: autoLoginResult.reason,\n autoLogin: 'error',\n });\n }\n\n await this.markCompleteAndClearPending(rec);\n\n this.phase = EmailRecoveryPhase.STEP_6_COMPLETE;\n this.emit({\n step: 6,\n phase: EmailRecoveryPhase.STEP_6_COMPLETE,\n status: EmailRecoveryStatus.SUCCESS,\n message: 'Email recovery completed successfully',\n data: {\n accountId: rec.accountId,\n nearPublicKey: rec.nearPublicKey,\n },\n } as EmailRecoverySSEEvent & { data: Record<string, unknown> });\n } catch (e: unknown) {\n rec.status = 'error';\n await this.savePending(rec).catch(() => { });\n const original = e instanceof Error\n ? e\n : new Error(errorMessage(e) || 'Email recovery finalization failed');\n const err = this.emitError(5, original);\n await this.options?.afterCall?.(false);\n throw err;\n }\n }\n\n private async attemptAutoLogin(rec: PendingEmailRecovery): Promise<AutoLoginResult> {\n try {\n const accountId = toAccountId(rec.accountId);\n const deviceNumber = parseDeviceNumber(rec.deviceNumber, { min: 1 });\n if (deviceNumber === null) {\n return this.handleAutoLoginFailure(\n `Invalid deviceNumber for auto-login: ${String(rec.deviceNumber)}`\n );\n }\n\n const shamirUnlocked = await this.tryShamirUnlock(rec, accountId, deviceNumber);\n if (shamirUnlocked) {\n return { success: true, method: 'shamir' };\n }\n\n const touchIdResult = await this.tryTouchIdUnlock(rec, accountId, deviceNumber);\n if (touchIdResult.success) {\n return { success: true, method: 'touchid' };\n }\n\n return this.handleAutoLoginFailure(touchIdResult.reason || 'Auto-login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