@seams/voiceid 0.43.0 → 0.45.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.
@@ -1 +0,0 @@
1
- import{s as e}from"./prompt-yshUSnwN.js";import{a as t,i as n}from"./verification-Ddj-M_EN.js";import{n as r}from"./deviceBridge-BKjLg0gA.js";async function i(e,r,i,o){let s=await e.prepareUnlock(r),c=s.scope;if(!await n(c))throw Error(`Unlock with a passkey, then open Manage voice to import or record your enrollment.`);await t(i,r,o),r.throwIfAborted();let l=await s.challenge(r),u={challenge:l,initiation:e.mountCapture?`hosted_menu`:`sdk_request`};return r.throwIfAborted(),{kind:`recording`,expiresAtMs:l.expiresAtMs,action:a.bind(null,o,u)}}async function a(t,n,i,a,s){switch(n.initiation){case`sdk_request`:e();break;case`hosted_menu`:break;default:return o(n.initiation)}return n.challenge.complete(r.bind(null,t,{onCapture:a,phrase:s}),i)}function o(e){throw Error(`Unexpected VoiceID initiation: ${String(e)}`)}export{i as prepareUnlockSurface};
@@ -1 +0,0 @@
1
- import{_ as e,a as t,f as n,g as r,p as i,u as a,v as o}from"./prompt-yshUSnwN.js";import{WorkerDeferred as s,isFiniteNumber as c,requireRecord as l,voiceEnrollmentStorage as u}from"../voiceid-host.js";const d=`e04dd7a6a1e23fc7b89e47682ea9d0a3946cf7bc59d07922c3db3efc52ae4269`,f=`redimnet-b1:${d}`,p=.45,m=new r({path:`/sdk/voiceid/redimnet-b1.onnx`,sha256:d,bytes:8859593,label:`Speaker verification`});async function h(e){let t=await m.prepare(),n=new(await(import(`./ort.wasm.bundle.min-7y-hlRN8.js`))).Tensor(`float32`,e,[1,e.length]);try{let e=await t.run({samples:n});try{let t=e.embedding;if(!t||!(t.data instanceof Float32Array))throw Error(`VoiceID model returned an invalid embedding.`);return g(Array.from(t.data))}finally{for(let t of Object.values(e))t.dispose()}}finally{n.dispose()}}function g(e){if(e.length!==192)throw Error(`VoiceID template dimensions are invalid.`);let t=0;for(let n of e){if(!Number.isFinite(n))throw Error(`VoiceID template is invalid.`);t+=n*n}if(t<1e-12)throw Error(`VoiceID template contains no signal.`);let n=Math.sqrt(t),r=[];for(let t of e)r.push(t/n);return r}function _(e,t){if(e.length!==192||t.length!==192)throw Error(`VoiceID templates are incompatible.`);let n=0;for(let r=0;r<e.length;r+=1)n+=e[r]*t[r];return n}function v(e){return e.asset}function y(e,t){return e+t.size}var b=class{element=document.createElement(`section`);status=document.createElement(`p`);meter=document.createElement(`progress`);retryButton=document.createElement(`button`);retry=null;cancelled=new s;reveal;received=new Map;models;assets;total;constructor(e,t,n){this.parent=e,this.signal=t,this.models=[m,i(n),a],this.assets=[o,...this.models.map(v)],this.total=this.assets.reduce(y,0),this.element.className=`seams-voiceid-model-download`,this.status.setAttribute(`role`,`status`),this.status.setAttribute(`aria-live`,`polite`),this.meter.setAttribute(`aria-label`,`VoiceID download`),this.meter.style.width=`100%`,this.retryButton.type=`button`,this.retryButton.className=`seams-voiceid-primary`,this.retryButton.textContent=`Retry loading`,this.retryButton.hidden=!0,this.retryButton.addEventListener(`click`,this.retryLoading),this.element.append(this.status,this.meter,this.retryButton),this.status.textContent=`Loading saved VoiceID…`,this.reveal=setTimeout(e.append.bind(e,this.element),300),t.addEventListener(`abort`,this.abort,{once:!0})}settle=()=>{clearTimeout(this.reveal),this.signal.removeEventListener(`abort`,this.abort),this.retryButton.removeEventListener(`click`,this.retryLoading)};abort=()=>{let e=new DOMException(`VoiceID preparation was cancelled.`,`AbortError`);this.cancelled.reject(e),this.retry?.reject(e)};retryLoading=()=>{this.retry?.resolve(),this.retry=null};async prepare(){this.signal.throwIfAborted(),await Promise.race([this.prepareUntilReady(),this.cancelled.promise])}async prepareUntilReady(){for(;;){this.signal.throwIfAborted(),this.retryButton.hidden=!0,this.meter.hidden=!1;try{for(let e of this.assets)await e.download(this.update.bind(this,e)),this.signal.throwIfAborted();this.preparing();for(let e of this.models)await e.prepare(),this.signal.throwIfAborted();this.ready();return}catch(t){if(this.signal.throwIfAborted(),!(t instanceof e))throw t;clearTimeout(this.reveal),this.parent.append(this.element),this.element.dataset.state=`failed`,this.meter.hidden=!0,this.status.textContent=t.message,this.retry=new s,this.retryButton.hidden=!1,this.retryButton.focus(),await this.retry.promise}}}update=(e,t)=>{switch(t.kind){case`checking_cache`:return;case`downloading`:this.received.set(e,t.received),this.element.dataset.state=`downloading`;break;case`ready`:this.received.set(e,e.size);break;default:}if(this.element.dataset.state!==`downloading`)return;let n=0;for(let e of this.received.values())n+=e;this.meter.max=this.total,this.meter.value=n,this.status.textContent=`Downloading VoiceID: ${(n/1e6).toFixed(1)} of ${(this.total/1e6).toFixed(1)} MB · ${Math.floor(n/this.total*100)}%`};preparing(){this.element.dataset.state=`preparing`,this.meter.removeAttribute(`value`),this.status.textContent=`Preparing VoiceID…`}ready(){this.element.dataset.state=`ready`,this.meter.hidden=!0,this.status.textContent=`VoiceID is ready.`}};async function x(e,t,n){let r=new b(e,t,n);try{await r.prepare()}finally{r.settle()}}const S=.2,C=u({model:f,parseEnrollment:T});function w(e){if(!Array.isArray(e)||!e.every(c))throw Error(`VoiceID template is invalid.`);let t=g(e);for(let n=0;n<e.length;n+=1)if(Math.abs(e[n]-t[n])>1e-6)throw Error(`VoiceID template is not normalized.`);return e.slice()}function T(e,t){if(e===void 0)return null;let n=l(e,`VoiceID enrollment`),r=l(n.scope,`VoiceID enrollment scope`);if(n.kind!==`browser_voiceid_enrollment_v2`||r.walletId!==t.walletId||r.authorityId!==t.authorityId||r.walletAuthMethodId!==t.walletAuthMethodId||r.deviceKeyId!==t.deviceKeyId||typeof n.generation!=`string`||!n.generation||typeof n.revision!=`number`||!Number.isSafeInteger(n.revision)||n.revision<0)throw Error(`VoiceID enrollment identity is invalid.`);if(n.model!==f)return null;let i=w(n.baseline),a={kind:`baseline`};try{let e=l(n.adaptation,`VoiceID improvements`);if(e.kind===`adapted`&&Array.isArray(e.samples)&&e.samples.length===3){let t=e.samples.map(w);D(i,t),a={kind:`adapted`,samples:t}}}catch{a={kind:`baseline`}}return{kind:`browser_voiceid_enrollment_v2`,scope:t,model:f,generation:n.generation,revision:n.revision,baseline:i,adaptation:a}}function E(e,t){let n=Array(192).fill(0);for(let e of t)for(let r=0;r<n.length;r+=1)n[r]+=e[r]/t.length;let r=g(n);for(let t=0;t<n.length;t+=1)n[t]=(1-S)*e[t]+S*r[t];return g(n)}function D(e,t){if(t.length!==3)throw Error(`Record three samples before saving voice improvements.`);for(let n of t)if(_(e,n)<.45)throw Error(`This sample differs from your original voice. Try again or re-record your enrollment.`);if(_(e,E(e,t))<.98)throw Error(`These samples differ too much from your original voice. Re-record your enrollment instead.`)}function O(e){return C.read(e)}async function k(e,t){let n=await C.readTemplate(e,t),r=n.adaptation;return{template:r.kind===`adapted`?E(n.baseline,r.samples):[...n.baseline],baseline:[...n.baseline],kind:r.kind}}async function A(){let e=await C.readImportable();if(e===void 0)return null;let t=l(e,`Previous VoiceID enrollment`);return t.kind!==`browser_voiceid_enrollment_v1`||t.model!==f?null:w(t.template)}async function j(e){let{scope:t,signal:n}=e;switch(e.kind){case`activate`:return C.commit({kind:`activate`,scope:t,signal:n,guard:e.guard,snapshot:e.snapshot,baseline:w(e.baseline)});case`import`:return C.commit({kind:`import`,scope:t,signal:n,guard:e.guard,snapshot:e.snapshot,confirmation:e.confirmation,baseline:w(e.baseline)});case`replace`:return C.commit({kind:`replace`,scope:t,signal:n,guard:e.guard,snapshot:e.snapshot,confirmation:e.confirmation,baseline:w(e.baseline)});case`improve`:return D(e.snapshot.enrollment.baseline,e.samples),C.commit({kind:`improve`,scope:t,signal:n,guard:e.guard,snapshot:e.snapshot,confirmation:e.confirmation,samples:e.samples});case`reset`:return C.commit({kind:`reset`,scope:t,signal:n,guard:e.guard,snapshot:e.snapshot,confirmation:e.confirmation});default:return M(e)}}function M(e){throw Error(`Unsupported VoiceID enrollment change.`)}async function N(e,r,i,a,o){let s=await t(r,i);if(s.kind===`insufficient_audio`)return r.throwIfAborted(),s;try{r.throwIfAborted();let t=await n(s.samples,a,o),i=await h(s.samples),c;try{r.throwIfAborted();let t=await k(e,r);try{c=_(i,t.template)}finally{t.template.fill(0),t.baseline.fill(0)}}finally{i.fill(0)}return c<.45?{kind:`mismatch`,quality:s.quality}:t.kind===`matched`?{kind:`matched`}:{kind:`phrase_mismatch`}}finally{s.samples.fill(0)}}export{x as a,h as c,O as i,_ as l,j as n,p as o,A as r,g as s,N as t};
@@ -1,27 +0,0 @@
1
- import { type VoiceIdReviewRequest, type VoiceIdTranscriptionModel, type AuthMethodApprovalResult } from '@seams/wallet/voiceid-host';
2
- export declare class VoiceIdApproval {
3
- private readonly reviewExpiresAtMs;
4
- private readonly operationHash;
5
- private readonly walletId;
6
- private readonly confirmation;
7
- private readonly model;
8
- private phrase;
9
- private readonly prompt;
10
- readonly surface: HTMLElement;
11
- get messages(): {
12
- confirm: string;
13
- approved: string;
14
- };
15
- private state;
16
- private constructor();
17
- static forReview(request: VoiceIdReviewRequest, model: VoiceIdTranscriptionModel): VoiceIdApproval;
18
- prepare(signal: AbortSignal): Promise<void>;
19
- approve(signal: AbortSignal): Promise<AuthMethodApprovalResult>;
20
- /** Binds one listening attempt to the operation and to what remains of the review. */
21
- private beginAttempt;
22
- /** Resolves when the person selects Try again; rejects when the review closes or expires. */
23
- private waitForRetry;
24
- consume(): void;
25
- private assertListening;
26
- }
27
- //# sourceMappingURL=approval.d.ts.map
@@ -1,13 +0,0 @@
1
- import type { VoiceIdTranscriptionModel } from '@seams/wallet/voiceid-host';
2
- import { type VoiceCaptureObserver } from '../browser/microphone';
3
- import { type SpokenPhrase } from '../browser/phrase';
4
- import type { AuthMethodApprovalResult } from '@seams/wallet/voiceid-host';
5
- import type { VoiceEnrollmentScope } from '@seams/wallet/voiceid-host';
6
- export type VoiceBinding = Readonly<{
7
- attemptId: string;
8
- operationHash: string;
9
- expiresAtMs: number;
10
- }>;
11
- export declare function sameVoiceBinding(left: VoiceBinding, right: VoiceBinding): boolean;
12
- export declare function listenForVoiceApproval(scope: VoiceEnrollmentScope, binding: VoiceBinding, timeoutMs: number, signal: AbortSignal, onCapture: VoiceCaptureObserver, phrase: SpokenPhrase, model: VoiceIdTranscriptionModel): Promise<AuthMethodApprovalResult>;
13
- //# sourceMappingURL=bridge.d.ts.map