js-spectre @main -
refs -
log -
-
https://git.jolheiser.com/js-spectre.git
JS implementation for spectre/masterpassword
update build process
Signed-off-by: jolheiser <git@jolheiser.com>
Signature
-----BEGIN SSH SIGNATURE-----
U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgBTEvCQk6VqUAdN2RuH6bj1dNkY
oOpbPWj+jw4ua1B1cAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5
AAAAQDULVDISLjQavF1F7YvkXV5BvJYi6cq0it+Z9buOaH8RQ1WGeVx1KfbgSOWLjd2td5
WVs6xhxocvSb9dB9pmlwA=
-----END SSH SIGNATURE-----
15 changed files, 231 additions(+), 26 deletions(-)
diff --git a/example/index.html b/example/index.html
index 0fade851bbc4c830f553a9a29bbe0e62d5a7840a..3ab21e2179ed366528688f412fada6f923b8c2c5 100644
--- a/example/index.html
+++ b/example/index.html
@@ -1,7 +1,7 @@
<!doctype html>
<head>
- <script src="../spectre.js"></script>
+ <script type="module" src="../lib/spectre.js"></script>
<link rel="stylesheet" href="sakura.css" />
<style>
input {
@@ -12,11 +12,7 @@ </head>
<body>
<input id="userKey" type="text" placeholder="Robert Lee Mitchell" /><br />
- <input
- id="userSecret"
- type="text"
- placeholder="banana colored duckling"
- /><br />
+ <input id="userSecret" type="text" placeholder="banana colored duckling" /><br />
<input id="siteKey" type="text" placeholder="masterpasswordapp.com" /><br />
<strong id="result"></strong>
</body>
@@ -43,4 +39,4 @@ if (s === null || $siteKey.value === "") return;
const pw = s.site($siteKey.value);
$result.innerText = pw;
}
-</script>
+</script>
\ No newline at end of file
diff --git a/lib/scope.d.ts b/lib/scope.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..56f8d16d13003e4ae49ef3255d2b78219818ce1a
--- /dev/null
+++ b/lib/scope.d.ts
@@ -0,0 +1,16 @@
+import { Template } from "./template.js";
+export declare enum Scope {
+ AUTHENTICATION = "Authentication",
+ IDENTIFICATION = "Identification",
+ RECOVERY = "Recovery"
+}
+export declare function defaultTemplate(s: Scope): Template;
+export interface Scoper {
+ scope(s: Scope): string;
+}
+export declare class SimpleScoper implements Scoper {
+ private key;
+ constructor(key: string);
+ scope(s: Scope): string;
+}
+export declare const defaultScoper: Scoper;
diff --git a/lib/scope.js b/lib/scope.js
new file mode 100644
index 0000000000000000000000000000000000000000..4564155e585ba8f4d1c053f54d50163f779234cc
--- /dev/null
+++ b/lib/scope.js
@@ -0,0 +1,34 @@
+import { Template } from "./template.js";
+export var Scope;
+(function (Scope) {
+ Scope["AUTHENTICATION"] = "Authentication";
+ Scope["IDENTIFICATION"] = "Identification";
+ Scope["RECOVERY"] = "Recovery";
+})(Scope || (Scope = {}));
+export function defaultTemplate(s) {
+ switch (s) {
+ case Scope.AUTHENTICATION:
+ return Template.LONG;
+ case Scope.IDENTIFICATION:
+ return Template.NAME;
+ case Scope.RECOVERY:
+ return Template.MAXIMUM;
+ }
+}
+export class SimpleScoper {
+ key;
+ constructor(key) {
+ this.key = key;
+ }
+ scope(s) {
+ switch (s) {
+ case Scope.AUTHENTICATION:
+ return this.key;
+ case Scope.IDENTIFICATION:
+ return `${this.key}.login`;
+ case Scope.RECOVERY:
+ return `${this.key}.answer`;
+ }
+ }
+}
+export const defaultScoper = new SimpleScoper("com.lyndir.masterpassword");
diff --git a/lib/scope.ts b/src/scope.ts
rename from lib/scope.ts
rename to src/scope.ts
diff --git a/lib/spectre.d.ts b/lib/spectre.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..958197b66b661778ecd0fee5a218a5f5a45ee137
--- /dev/null
+++ b/lib/spectre.d.ts
@@ -0,0 +1,14 @@
+export * from './template.js';
+export * from './scope.js';
+import { Scope, Scoper } from "./scope.js";
+import { Template } from "./template.js";
+export declare class Spectre {
+ private readonly name;
+ private readonly secret;
+ private readonly scoper;
+ private readonly key;
+ constructor(name: string, secret: string, scoper?: Scoper);
+ private userKey;
+ private siteKey;
+ site(siteName: string, templateType?: Template, counter?: number, scope?: Scope): string;
+}
diff --git a/lib/spectre.js b/lib/spectre.js
new file mode 100644
index 0000000000000000000000000000000000000000..10e78985ae00d08a7ae7004cd52b61abbd3b6fd6
--- /dev/null
+++ b/lib/spectre.js
@@ -0,0 +1,72 @@
+export * from './template.js';
+export * from './scope.js';
+import { scrypt } from "@noble/hashes/scrypt";
+import { defaultScoper, defaultTemplate, Scope } from "./scope.js";
+import { HMAC } from "@noble/hashes/hmac";
+import { sha256 } from "@noble/hashes/sha256";
+import { characters, templates } from "./template.js";
+export class Spectre {
+ name;
+ secret;
+ scoper;
+ key;
+ constructor(name, secret, scoper = defaultScoper) {
+ this.name = name;
+ this.secret = secret;
+ this.scoper = scoper;
+ this.key = this.userKey();
+ }
+ userKey() {
+ const enc = new TextEncoder();
+ const nameBytes = enc.encode(this.name);
+ const secretBytes = enc.encode(this.secret);
+ const keyScope = enc.encode(this.scoper.scope(Scope.AUTHENTICATION));
+ const nameBytesLen = nameBytes.length;
+ const keySalt = new Uint8Array([
+ ...keyScope,
+ ...bigEndian(nameBytesLen),
+ ...nameBytes,
+ ]);
+ const N = 32768;
+ const r = 8;
+ const p = 2;
+ const maxmem = 128 * r * (N + p + 2);
+ return scrypt(secretBytes, keySalt, { N, r, p, maxmem, dkLen: 64 });
+ }
+ siteKey(name, counter, scope) {
+ const enc = new TextEncoder();
+ const nameBytes = enc.encode(name);
+ const scopeBytes = enc.encode(this.scoper.scope(scope));
+ const nameBytesLen = nameBytes.length;
+ const keySalt = new Uint8Array([
+ ...scopeBytes,
+ ...bigEndian(nameBytesLen),
+ ...nameBytes,
+ ...bigEndian(counter),
+ ]);
+ const sign = new HMAC(sha256, this.key);
+ sign.update(keySalt);
+ return sign.digest();
+ }
+ site(siteName, templateType, counter = 1, scope = Scope.AUTHENTICATION) {
+ if (templateType === undefined)
+ templateType = defaultTemplate(scope);
+ const siteKey = this.siteKey(siteName, counter, scope);
+ const templateSet = templates[templateType];
+ const template = templateSet[siteKey[0] % templateSet.length];
+ let out = "";
+ for (let i = 0; i < template.length; i++) {
+ const b = template[i];
+ const chars = characters[b];
+ const char = chars[siteKey[i + 1] % chars.length];
+ out += char;
+ }
+ return out;
+ }
+}
+function bigEndian(n) {
+ const buffer = new ArrayBuffer(4);
+ const view = new DataView(buffer);
+ view.setInt32(0, n, false);
+ return new Uint8Array(buffer);
+}
diff --git a/lib/spectre.min.js b/lib/spectre.min.js
new file mode 100644
index 0000000000000000000000000000000000000000..d64af7fbb5e93041861bc997360db8495ec5a720
--- /dev/null
+++ b/lib/spectre.min.js
@@ -0,0 +1,6 @@
+"use strict";var spectre=(()=>{var et=Object.defineProperty;var At=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var Lt=Object.prototype.hasOwnProperty;var It=(e,t)=>{for(var n in t)et(e,n,{get:t[n],enumerable:!0})},Et=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of kt(t))!Lt.call(e,r)&&r!==n&&et(e,r,{get:()=>t[r],enumerable:!(o=At(t,r))||o.enumerable});return e};var Ut=e=>Et(et({},"__esModule",{value:!0}),e);var Vt={};It(Vt,{Scope:()=>st,SimpleScoper:()=>J,Spectre:()=>dt,Template:()=>nt,characters:()=>rt,defaultScoper:()=>it,defaultTemplate:()=>ct,templates:()=>ot});var nt=(a=>(a.MAXIMUM="Maximum",a.LONG="Long",a.MEDIUM="Medium",a.SHORT="Short",a.PIN="PIN",a.NAME="Name",a.PHRASE="Phrase",a.BASIC="Basic",a))(nt||{}),ot={Maximum:["anoxxxxxxxxxxxxxxxxx","axxxxxxxxxxxxxxxxxno"],Long:["CvcvnoCvcvCvcv","CvcvCvcvnoCvcv","CvcvCvcvCvcvno","CvccnoCvcvCvcv","CvccCvcvnoCvcv","CvccCvcvCvcvno","CvcvnoCvccCvcv","CvcvCvccnoCvcv","CvcvCvccCvcvno","CvcvnoCvcvCvcc","CvcvCvcvnoCvcc","CvcvCvcvCvccno","CvccnoCvccCvcv","CvccCvccnoCvcv","CvccCvccCvcvno","CvcvnoCvccCvcc","CvcvCvccnoCvcc","CvcvCvccCvccno","CvccnoCvcvCvcc","CvccCvcvnoCvcc","CvccCvcvCvccno"],Medium:["CvcnoCvc","CvcCvcno"],Short:["Cvcn"],PIN:["nnnn"],Name:["cvccvcvcv"],Phrase:["cvcc cvc cvccvcv cvc","cvc cvccvcvcv cvcv","cv cvccv cvc cvcvccv"],Basic:["aaanaaan","aannaaan","aaannaaa"]},rt={V:"AEIOU",C:"BCDFGHJKLMNPQRSTVWXYZ",v:"aeiou",c:"bcdfghjklmnpqrstvwxyz",A:"AEIOUBCDFGHJKLMNPQRSTVWXYZ",a:"AEIOUaeiouBCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz",n:"0123456789",o:"@&%?,=[]_:-+*$#!'^~;()/.",x:"AEIOUaeiouBCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz0123456789!@#$%^&*()"," ":" "};var st=(o=>(o.AUTHENTICATION="Authentication",o.IDENTIFICATION="Identification",o.RECOVERY="Recovery",o))(st||{});function ct(e){switch(e){case"Authentication":return"Long";case"Identification":return"Name";case"Recovery":return"Maximum"}}var J=class{key;constructor(t){this.key=t}scope(t){switch(t){case"Authentication":return this.key;case"Identification":return`${this.key}.login`;case"Recovery":return`${this.key}.answer`}}},it=new J("com.lyndir.masterpassword");function v(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Bt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function z(e,...t){if(!Bt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Q(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");v(e.outputLen),v(e.blockLen)}function K(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function bt(e,t){z(e);let n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Z(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function G(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function g(e,t){return e<<32-t|e>>>t}function u(e,t){return e<<t|e>>>32-t>>>0}var at=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function St(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function ft(e){for(let t=0;t<e.length;t++)e[t]=St(e[t])}function Ht(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function w(e){return typeof e=="string"&&(e=Ht(e)),z(e),e}var j=class{clone(){return this._cloneInto()}};function $(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(e,t)}function vt(e){let t=o=>e().update(w(o)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}var W=class extends j{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Q(t);let o=w(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let r=this.blockLen,s=new Uint8Array(r);s.set(o.length>r?t.create().update(o).digest():o);for(let c=0;c<s.length;c++)s[c]^=54;this.iHash.update(s),this.oHash=t.create();for(let c=0;c<s.length;c++)s[c]^=106;this.oHash.update(s),s.fill(0)}update(t){return K(this),this.iHash.update(t),this}digestInto(t){K(this),z(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:n,iHash:o,finished:r,destroyed:s,blockLen:c,outputLen:i}=this;return t=t,t.finished=r,t.destroyed=s,t.blockLen=c,t.outputLen=i,t.oHash=n._cloneInto(t.oHash),t.iHash=o._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ht=(e,t,n)=>new W(e,t).update(n).digest();ht.create=(e,t)=>new W(e,t);function Nt(e,t,n,o){Q(e);let r=$({dkLen:32,asyncTick:10},o),{c:s,dkLen:c,asyncTick:i}=r;if(v(s),v(c),v(i),s<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let a=w(t),h=w(n),x=new Uint8Array(c),f=ht.create(e,a),l=f._cloneInto().update(h);return{c:s,dkLen:c,asyncTick:i,DK:x,PRF:f,PRFSalt:l}}function Ot(e,t,n,o,r){return e.destroy(),t.destroy(),o&&o.destroy(),r.fill(0),n}function ut(e,t,n,o){let{c:r,dkLen:s,DK:c,PRF:i,PRFSalt:a}=Nt(e,t,n,o),h,x=new Uint8Array(4),f=G(x),l=new Uint8Array(i.outputLen);for(let y=1,d=0;d<s;y++,d+=i.outputLen){let p=c.subarray(d,d+i.outputLen);f.setInt32(0,y,!1),(h=a._cloneInto(h)).update(x).digestInto(l),p.set(l.subarray(0,p.length));for(let m=1;m<r;m++){i._cloneInto(h).update(l).digestInto(l);for(let b=0;b<p.length;b++)p[b]^=l[b]}}return Ot(i,a,c,h,l)}function Mt(e,t,n,o){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,o);let r=BigInt(32),s=BigInt(4294967295),c=Number(n>>r&s),i=Number(n&s),a=o?4:0,h=o?0:4;e.setUint32(t+a,c,o),e.setUint32(t+h,i,o)}function mt(e,t,n){return e&t^~e&n}function gt(e,t,n){return e&t^e&n^t&n}var tt=class extends j{constructor(t,n,o,r){super(),this.blockLen=t,this.outputLen=n,this.padOffset=o,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=G(this.buffer)}update(t){K(this);let{view:n,buffer:o,blockLen:r}=this;t=w(t);let s=t.length;for(let c=0;c<s;){let i=Math.min(r-this.pos,s-c);if(i===r){let a=G(t);for(;r<=s-c;c+=r)this.process(a,c);continue}o.set(t.subarray(c,c+i),this.pos),this.pos+=i,c+=i,this.pos===r&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){K(this),bt(t,this),this.finished=!0;let{buffer:n,view:o,blockLen:r,isLE:s}=this,{pos:c}=this;n[c++]=128,this.buffer.subarray(c).fill(0),this.padOffset>r-c&&(this.process(o,0),c=0);for(let f=c;f<r;f++)n[f]=0;Mt(o,r-8,BigInt(this.length*8),s),this.process(o,0);let i=G(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let h=a/4,x=this.get();if(h>x.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<h;f++)i.setUint32(4*f,x[f],s)}digest(){let{buffer:t,outputLen:n}=this;this.digestInto(t);let o=t.slice(0,n);return this.destroy(),o}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:n,buffer:o,length:r,finished:s,destroyed:c,pos:i}=this;return t.length=r,t.pos=i,t.finished=s,t.destroyed=c,r%n&&t.buffer.set(o),t}};var _t=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),C=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),A=new Uint32Array(64),xt=class extends tt{constructor(){super(64,32,8,!1),this.A=C[0]|0,this.B=C[1]|0,this.C=C[2]|0,this.D=C[3]|0,this.E=C[4]|0,this.F=C[5]|0,this.G=C[6]|0,this.H=C[7]|0}get(){let{A:t,B:n,C:o,D:r,E:s,F:c,G:i,H:a}=this;return[t,n,o,r,s,c,i,a]}set(t,n,o,r,s,c,i,a){this.A=t|0,this.B=n|0,this.C=o|0,this.D=r|0,this.E=s|0,this.F=c|0,this.G=i|0,this.H=a|0}process(t,n){for(let f=0;f<16;f++,n+=4)A[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){let l=A[f-15],y=A[f-2],d=g(l,7)^g(l,18)^l>>>3,p=g(y,17)^g(y,19)^y>>>10;A[f]=p+A[f-7]+d+A[f-16]|0}let{A:o,B:r,C:s,D:c,E:i,F:a,G:h,H:x}=this;for(let f=0;f<64;f++){let l=g(i,6)^g(i,11)^g(i,25),y=x+l+mt(i,a,h)+_t[f]+A[f]|0,p=(g(o,2)^g(o,13)^g(o,22))+gt(o,r,s)|0;x=h,h=a,a=i,i=c+y|0,c=s,s=r,r=o,o=y+p|0}o=o+this.A|0,r=r+this.B|0,s=s+this.C|0,c=c+this.D|0,i=i+this.E|0,a=a+this.F|0,h=h+this.G|0,x=x+this.H|0,this.set(o,r,s,c,i,a,h,x)}roundClean(){A.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Y=vt(()=>new xt);function wt(e,t,n,o,r,s){let c=e[t++]^n[o++],i=e[t++]^n[o++],a=e[t++]^n[o++],h=e[t++]^n[o++],x=e[t++]^n[o++],f=e[t++]^n[o++],l=e[t++]^n[o++],y=e[t++]^n[o++],d=e[t++]^n[o++],p=e[t++]^n[o++],m=e[t++]^n[o++],b=e[t++]^n[o++],X=e[t++]^n[o++],P=e[t++]^n[o++],q=e[t++]^n[o++],k=e[t++]^n[o++],L=c,I=i,E=a,U=h,B=x,S=f,H=l,T=y,N=d,O=p,M=m,_=b,R=X,F=P,V=q,D=k;for(let yt=0;yt<8;yt+=2)B^=u(L+R|0,7),N^=u(B+L|0,9),R^=u(N+B|0,13),L^=u(R+N|0,18),O^=u(S+I|0,7),F^=u(O+S|0,9),I^=u(F+O|0,13),S^=u(I+F|0,18),V^=u(M+H|0,7),E^=u(V+M|0,9),H^=u(E+V|0,13),M^=u(H+E|0,18),U^=u(D+_|0,7),T^=u(U+D|0,9),_^=u(T+U|0,13),D^=u(_+T|0,18),I^=u(L+U|0,7),E^=u(I+L|0,9),U^=u(E+I|0,13),L^=u(U+E|0,18),H^=u(S+B|0,7),T^=u(H+S|0,9),B^=u(T+H|0,13),S^=u(B+T|0,18),_^=u(M+O|0,7),N^=u(_+M|0,9),O^=u(N+_|0,13),M^=u(O+N|0,18),R^=u(D+V|0,7),F^=u(R+D|0,9),V^=u(F+R|0,13),D^=u(V+F|0,18);r[s++]=c+L|0,r[s++]=i+I|0,r[s++]=a+E|0,r[s++]=h+U|0,r[s++]=x+B|0,r[s++]=f+S|0,r[s++]=l+H|0,r[s++]=y+T|0,r[s++]=d+N|0,r[s++]=p+O|0,r[s++]=m+M|0,r[s++]=b+_|0,r[s++]=X+R|0,r[s++]=P+F|0,r[s++]=q+V|0,r[s++]=k+D|0}function lt(e,t,n,o,r){let s=o+0,c=o+16*r;for(let i=0;i<16;i++)n[c+i]=e[t+(2*r-1)*16+i];for(let i=0;i<r;i++,s+=16,t+=16)wt(n,c,e,t,n,s),i>0&&(c+=16),wt(n,s,e,t+=16,n,c)}function Rt(e,t,n){let o=$({dkLen:32,asyncTick:10,maxmem:1073742848},n),{N:r,r:s,p:c,dkLen:i,asyncTick:a,maxmem:h,onProgress:x}=o;if(v(r),v(s),v(c),v(i),v(a),v(h),x!==void 0&&typeof x!="function")throw new Error("progressCb should be function");let f=128*s,l=f/4;if(r<=1||r&r-1||r>2**32)throw new Error("Scrypt: N must be larger than 1, a power of 2, and less than 2^32");if(c<0||c>(2**32-1)*32/f)throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");if(i<0||i>(2**32-1)*32)throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");if(f*(r+c)>h)throw new Error("Scrypt: memused is bigger than maxMem. Expected 128 * r * (N + p) > maxmem of "+h);let d=ut(Y,e,t,{c:1,dkLen:f*c}),p=Z(d),m=Z(new Uint8Array(f*r)),b=Z(new Uint8Array(f)),X=()=>{};if(x){let P=2*r*c,q=Math.max(Math.floor(P/1e4),1),k=0;X=()=>{k++,x&&(!(k%q)||k===P)&&x(k/P)}}return{N:r,r:s,p:c,dkLen:i,blockSize32:l,V:m,B32:p,B:d,tmp:b,blockMixCb:X,asyncTick:a}}function Ft(e,t,n,o,r){let s=ut(Y,e,n,{c:1,dkLen:t});return n.fill(0),o.fill(0),r.fill(0),s}function Ct(e,t,n){let{N:o,r,p:s,dkLen:c,blockSize32:i,V:a,B32:h,B:x,tmp:f,blockMixCb:l}=Rt(e,t,n);at||ft(h);for(let y=0;y<s;y++){let d=i*y;for(let p=0;p<i;p++)a[p]=h[d+p];for(let p=0,m=0;p<o-1;p++)lt(a,m,a,m+=i,r),l();lt(a,(o-1)*i,h,d,r),l();for(let p=0;p<o;p++){let m=h[d+i-16]%o;for(let b=0;b<i;b++)f[b]=h[d+b]^a[m*i+b];lt(f,0,h,d,r),l()}}return at||ft(h),Ft(e,c,x,a,f)}var dt=class{name;secret;scoper;key;constructor(t,n,o=it){this.name=t,this.secret=n,this.scoper=o,this.key=this.userKey()}userKey(){let t=new TextEncoder,n=t.encode(this.name),o=t.encode(this.secret),r=t.encode(this.scoper.scope("Authentication")),s=n.length,c=new Uint8Array([...r,...pt(s),...n]),i=32768,a=8,h=2,x=128*a*(i+h+2);return Ct(o,c,{N:i,r:a,p:h,maxmem:x,dkLen:64})}siteKey(t,n,o){let r=new TextEncoder,s=r.encode(t),c=r.encode(this.scoper.scope(o)),i=s.length,a=new Uint8Array([...c,...pt(i),...s,...pt(n)]),h=new W(Y,this.key);return h.update(a),h.digest()}site(t,n,o=1,r="Authentication"){n===void 0&&(n=ct(r));let s=this.siteKey(t,o,r),c=ot[n],i=c[s[0]%c.length],a="";for(let h=0;h<i.length;h++){let x=i[h],f=rt[x],l=f[s[h+1]%f.length];a+=l}return a}};function pt(e){let t=new ArrayBuffer(4);return new DataView(t).setInt32(0,e,!1),new Uint8Array(t)}return Ut(Vt);})();
+/*! Bundled license information:
+
+@noble/hashes/esm/utils.js:
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
+*/
diff --git a/lib/spectre.ts b/src/spectre.ts
rename from lib/spectre.ts
rename to src/spectre.ts
index ac27e48871ed64b6686e0980a1bef7b413e049af..4f767debb8675e76f775be23b0a9a637c5746b64 100644
--- a/lib/spectre.ts
+++ b/src/spectre.ts
@@ -1,3 +1,6 @@
+export * from './template.js';
+export * from './scope.js';
+
import { scrypt } from "@noble/hashes/scrypt"
import { defaultScoper, defaultTemplate, Scope, Scoper } from "./scope.js"
import { HMAC } from "@noble/hashes/hmac"
diff --git a/lib/template.d.ts b/lib/template.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..47b2587f669b2e6c05af2b25aa8073ade0a3ea49
--- /dev/null
+++ b/lib/template.d.ts
@@ -0,0 +1,12 @@
+export declare enum Template {
+ MAXIMUM = "Maximum",
+ LONG = "Long",
+ MEDIUM = "Medium",
+ SHORT = "Short",
+ PIN = "PIN",
+ NAME = "Name",
+ PHRASE = "Phrase",
+ BASIC = "Basic"
+}
+export declare const templates: Record<Template, string[]>;
+export declare const characters: Record<string, string>;
diff --git a/lib/template.js b/lib/template.js
new file mode 100644
index 0000000000000000000000000000000000000000..0e5b5761bf9de8d3afd35038cee2fc2f27a37472
--- /dev/null
+++ b/lib/template.js
@@ -0,0 +1,59 @@
+export var Template;
+(function (Template) {
+ Template["MAXIMUM"] = "Maximum";
+ Template["LONG"] = "Long";
+ Template["MEDIUM"] = "Medium";
+ Template["SHORT"] = "Short";
+ Template["PIN"] = "PIN";
+ Template["NAME"] = "Name";
+ Template["PHRASE"] = "Phrase";
+ Template["BASIC"] = "Basic";
+})(Template || (Template = {}));
+export const templates = {
+ Maximum: ["anoxxxxxxxxxxxxxxxxx", "axxxxxxxxxxxxxxxxxno"],
+ Long: [
+ "CvcvnoCvcvCvcv",
+ "CvcvCvcvnoCvcv",
+ "CvcvCvcvCvcvno",
+ "CvccnoCvcvCvcv",
+ "CvccCvcvnoCvcv",
+ "CvccCvcvCvcvno",
+ "CvcvnoCvccCvcv",
+ "CvcvCvccnoCvcv",
+ "CvcvCvccCvcvno",
+ "CvcvnoCvcvCvcc",
+ "CvcvCvcvnoCvcc",
+ "CvcvCvcvCvccno",
+ "CvccnoCvccCvcv",
+ "CvccCvccnoCvcv",
+ "CvccCvccCvcvno",
+ "CvcvnoCvccCvcc",
+ "CvcvCvccnoCvcc",
+ "CvcvCvccCvccno",
+ "CvccnoCvcvCvcc",
+ "CvccCvcvnoCvcc",
+ "CvccCvcvCvccno",
+ ],
+ Medium: ["CvcnoCvc", "CvcCvcno"],
+ Short: ["Cvcn"],
+ PIN: ["nnnn"],
+ Name: ["cvccvcvcv"],
+ Phrase: [
+ "cvcc cvc cvccvcv cvc",
+ "cvc cvccvcvcv cvcv",
+ "cv cvccv cvc cvcvccv",
+ ],
+ Basic: ["aaanaaan", "aannaaan", "aaannaaa"],
+};
+export const characters = {
+ V: "AEIOU",
+ C: "BCDFGHJKLMNPQRSTVWXYZ",
+ v: "aeiou",
+ c: "bcdfghjklmnpqrstvwxyz",
+ A: "AEIOUBCDFGHJKLMNPQRSTVWXYZ",
+ a: "AEIOUaeiouBCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz",
+ n: "0123456789",
+ o: "@&%?,=[]_:-+*$#!'^~;()/.",
+ x: "AEIOUaeiouBCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz0123456789!@#$%^&*()",
+ " ": " ",
+};
diff --git a/lib/template.ts b/src/template.ts
rename from lib/template.ts
rename to src/template.ts
diff --git a/package.json b/package.json
index 2f68444c3ec405fbee20b93e4cc7c79e97463f22..7d9acfd34cfdb828605a78ec91542801af921eaf 100644
--- a/package.json
+++ b/package.json
@@ -2,21 +2,18 @@ {
"name": "spectre",
"version": "0.0.1",
"files": [
- "dist/"
+ "lib/"
],
"type": "module",
- "exports": {
- ".": "./spectre.js"
- },
- "main": "spectre.js",
- "types": "./dist/spectre.d.ts",
+ "main": "./lib/spectre.js",
+ "types": "./lib/spectre.d.ts",
"description": "JS implementation of Spectre",
"scripts": {
"test": "vitest --run",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
"build:tsc": "tsc -p tsconfig.build.json",
- "build:esbuild": "esbuild --target=es2022 --bundle --minify --outfile=spectre.js --global-name=spectre spectre",
+ "build:esbuild": "esbuild --target=es2022 --bundle --minify --allow-overwrite --outfile=lib/spectre.min.js --global-name=spectre ./src/spectre",
"build": "npm run build:tsc && npm run build:esbuild"
},
"repository": {
diff --git a/spectre.js b/spectre.js
deleted file mode 100644
index 35c56e3961ed4d1f497d29ab19d881f937f9edff..0000000000000000000000000000000000000000
--- a/spectre.js
+++ /dev/null
@@ -1,6 +0,0 @@
-"use strict";var spectre=(()=>{var nt=Object.defineProperty;var At=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var Lt=Object.prototype.hasOwnProperty;var It=(e,t)=>{for(var n in t)nt(e,n,{get:t[n],enumerable:!0})},Et=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of kt(t))!Lt.call(e,o)&&o!==n&&nt(e,o,{get:()=>t[o],enumerable:!(s=At(t,o))||s.enumerable});return e};var Bt=e=>Et(nt({},"__esModule",{value:!0}),e);var Dt={};It(Dt,{Spectre:()=>ut});function v(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Ut(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function q(e,...t){if(!Ut(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Z(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");v(e.outputLen),v(e.blockLen)}function j(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function lt(e,t){q(e);let n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function $(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function W(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function w(e,t){return e<<32-t|e>>>t}function u(e,t){return e<<t|e>>>32-t>>>0}var ot=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Ht(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function st(e){for(let t=0;t<e.length;t++)e[t]=Ht(e[t])}function Tt(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function C(e){return typeof e=="string"&&(e=Tt(e)),q(e),e}var G=class{clone(){return this._cloneInto()}};function tt(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(e,t)}function dt(e){let t=s=>e().update(C(s)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}var X=class extends G{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Z(t);let s=C(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,c=new Uint8Array(o);c.set(s.length>o?t.create().update(s).digest():s);for(let r=0;r<c.length;r++)c[r]^=54;this.iHash.update(c),this.oHash=t.create();for(let r=0;r<c.length;r++)c[r]^=106;this.oHash.update(c),c.fill(0)}update(t){return j(this),this.iHash.update(t),this}digestInto(t){j(this),q(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:n,iHash:s,finished:o,destroyed:c,blockLen:r,outputLen:i}=this;return t=t,t.finished=o,t.destroyed=c,t.blockLen=r,t.outputLen=i,t.oHash=n._cloneInto(t.oHash),t.iHash=s._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ct=(e,t,n)=>new X(e,t).update(n).digest();ct.create=(e,t)=>new X(e,t);function Ot(e,t,n,s){Z(e);let o=tt({dkLen:32,asyncTick:10},s),{c,dkLen:r,asyncTick:i}=o;if(v(c),v(r),v(i),c<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let h=C(t),f=C(n),x=new Uint8Array(r),a=ct.create(e,h),l=a._cloneInto().update(f);return{c,dkLen:r,asyncTick:i,DK:x,PRF:a,PRFSalt:l}}function St(e,t,n,s,o){return e.destroy(),t.destroy(),s&&s.destroy(),o.fill(0),n}function rt(e,t,n,s){let{c:o,dkLen:c,DK:r,PRF:i,PRFSalt:h}=Ot(e,t,n,s),f,x=new Uint8Array(4),a=W(x),l=new Uint8Array(i.outputLen);for(let y=1,p=0;p<c;y++,p+=i.outputLen){let d=r.subarray(p,p+i.outputLen);a.setInt32(0,y,!1),(f=h._cloneInto(f)).update(x).digestInto(l),d.set(l.subarray(0,d.length));for(let m=1;m<o;m++){i._cloneInto(f).update(l).digestInto(l);for(let b=0;b<d.length;b++)d[b]^=l[b]}}return St(i,h,r,f,l)}function Mt(e,t,n,s){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,s);let o=BigInt(32),c=BigInt(4294967295),r=Number(n>>o&c),i=Number(n&c),h=s?4:0,f=s?0:4;e.setUint32(t+h,r,s),e.setUint32(t+f,i,s)}function pt(e,t,n){return e&t^~e&n}function yt(e,t,n){return e&t^e&n^t&n}var et=class extends G{constructor(t,n,s,o){super(),this.blockLen=t,this.outputLen=n,this.padOffset=s,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=W(this.buffer)}update(t){j(this);let{view:n,buffer:s,blockLen:o}=this;t=C(t);let c=t.length;for(let r=0;r<c;){let i=Math.min(o-this.pos,c-r);if(i===o){let h=W(t);for(;o<=c-r;r+=o)this.process(h,r);continue}s.set(t.subarray(r,r+i),this.pos),this.pos+=i,r+=i,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){j(this),lt(t,this),this.finished=!0;let{buffer:n,view:s,blockLen:o,isLE:c}=this,{pos:r}=this;n[r++]=128,this.buffer.subarray(r).fill(0),this.padOffset>o-r&&(this.process(s,0),r=0);for(let a=r;a<o;a++)n[a]=0;Mt(s,o-8,BigInt(this.length*8),c),this.process(s,0);let i=W(t),h=this.outputLen;if(h%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=h/4,x=this.get();if(f>x.length)throw new Error("_sha2: outputLen bigger than state");for(let a=0;a<f;a++)i.setUint32(4*a,x[a],c)}digest(){let{buffer:t,outputLen:n}=this;this.digestInto(t);let s=t.slice(0,n);return this.destroy(),s}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:n,buffer:s,length:o,finished:c,destroyed:r,pos:i}=this;return t.length=o,t.pos=i,t.finished=c,t.destroyed=r,o%n&&t.buffer.set(s),t}};var _t=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),A=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),k=new Uint32Array(64),it=class extends et{constructor(){super(64,32,8,!1),this.A=A[0]|0,this.B=A[1]|0,this.C=A[2]|0,this.D=A[3]|0,this.E=A[4]|0,this.F=A[5]|0,this.G=A[6]|0,this.H=A[7]|0}get(){let{A:t,B:n,C:s,D:o,E:c,F:r,G:i,H:h}=this;return[t,n,s,o,c,r,i,h]}set(t,n,s,o,c,r,i,h){this.A=t|0,this.B=n|0,this.C=s|0,this.D=o|0,this.E=c|0,this.F=r|0,this.G=i|0,this.H=h|0}process(t,n){for(let a=0;a<16;a++,n+=4)k[a]=t.getUint32(n,!1);for(let a=16;a<64;a++){let l=k[a-15],y=k[a-2],p=w(l,7)^w(l,18)^l>>>3,d=w(y,17)^w(y,19)^y>>>10;k[a]=d+k[a-7]+p+k[a-16]|0}let{A:s,B:o,C:c,D:r,E:i,F:h,G:f,H:x}=this;for(let a=0;a<64;a++){let l=w(i,6)^w(i,11)^w(i,25),y=x+l+pt(i,h,f)+_t[a]+k[a]|0,d=(w(s,2)^w(s,13)^w(s,22))+yt(s,o,c)|0;x=f,f=h,h=i,i=r+y|0,r=c,c=o,o=s,s=y+d|0}s=s+this.A|0,o=o+this.B|0,c=c+this.C|0,r=r+this.D|0,i=i+this.E|0,h=h+this.F|0,f=f+this.G|0,x=x+this.H|0,this.set(s,o,c,r,i,h,f,x)}roundClean(){k.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var J=dt(()=>new it);function bt(e,t,n,s,o,c){let r=e[t++]^n[s++],i=e[t++]^n[s++],h=e[t++]^n[s++],f=e[t++]^n[s++],x=e[t++]^n[s++],a=e[t++]^n[s++],l=e[t++]^n[s++],y=e[t++]^n[s++],p=e[t++]^n[s++],d=e[t++]^n[s++],m=e[t++]^n[s++],b=e[t++]^n[s++],Y=e[t++]^n[s++],K=e[t++]^n[s++],Q=e[t++]^n[s++],L=e[t++]^n[s++],I=r,E=i,B=h,U=f,H=x,T=a,N=l,O=y,S=p,M=d,_=m,F=b,V=Y,D=K,P=Q,R=L;for(let xt=0;xt<8;xt+=2)H^=u(I+V|0,7),S^=u(H+I|0,9),V^=u(S+H|0,13),I^=u(V+S|0,18),M^=u(T+E|0,7),D^=u(M+T|0,9),E^=u(D+M|0,13),T^=u(E+D|0,18),P^=u(_+N|0,7),B^=u(P+_|0,9),N^=u(B+P|0,13),_^=u(N+B|0,18),U^=u(R+F|0,7),O^=u(U+R|0,9),F^=u(O+U|0,13),R^=u(F+O|0,18),E^=u(I+U|0,7),B^=u(E+I|0,9),U^=u(B+E|0,13),I^=u(U+B|0,18),N^=u(T+H|0,7),O^=u(N+T|0,9),H^=u(O+N|0,13),T^=u(H+O|0,18),F^=u(_+M|0,7),S^=u(F+_|0,9),M^=u(S+F|0,13),_^=u(M+S|0,18),V^=u(R+P|0,7),D^=u(V+R|0,9),P^=u(D+V|0,13),R^=u(P+D|0,18);o[c++]=r+I|0,o[c++]=i+E|0,o[c++]=h+B|0,o[c++]=f+U|0,o[c++]=x+H|0,o[c++]=a+T|0,o[c++]=l+N|0,o[c++]=y+O|0,o[c++]=p+S|0,o[c++]=d+M|0,o[c++]=m+_|0,o[c++]=b+F|0,o[c++]=Y+V|0,o[c++]=K+D|0,o[c++]=Q+P|0,o[c++]=L+R|0}function at(e,t,n,s,o){let c=s+0,r=s+16*o;for(let i=0;i<16;i++)n[r+i]=e[t+(2*o-1)*16+i];for(let i=0;i<o;i++,c+=16,t+=16)bt(n,r,e,t,n,c),i>0&&(r+=16),bt(n,c,e,t+=16,n,r)}function Ft(e,t,n){let s=tt({dkLen:32,asyncTick:10,maxmem:1073742848},n),{N:o,r:c,p:r,dkLen:i,asyncTick:h,maxmem:f,onProgress:x}=s;if(v(o),v(c),v(r),v(i),v(h),v(f),x!==void 0&&typeof x!="function")throw new Error("progressCb should be function");let a=128*c,l=a/4;if(o<=1||o&o-1||o>2**32)throw new Error("Scrypt: N must be larger than 1, a power of 2, and less than 2^32");if(r<0||r>(2**32-1)*32/a)throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");if(i<0||i>(2**32-1)*32)throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");if(a*(o+r)>f)throw new Error("Scrypt: memused is bigger than maxMem. Expected 128 * r * (N + p) > maxmem of "+f);let p=rt(J,e,t,{c:1,dkLen:a*r}),d=$(p),m=$(new Uint8Array(a*o)),b=$(new Uint8Array(a)),Y=()=>{};if(x){let K=2*o*r,Q=Math.max(Math.floor(K/1e4),1),L=0;Y=()=>{L++,x&&(!(L%Q)||L===K)&&x(L/K)}}return{N:o,r:c,p:r,dkLen:i,blockSize32:l,V:m,B32:d,B:p,tmp:b,blockMixCb:Y,asyncTick:h}}function Vt(e,t,n,s,o){let c=rt(J,e,n,{c:1,dkLen:t});return n.fill(0),s.fill(0),o.fill(0),c}function vt(e,t,n){let{N:s,r:o,p:c,dkLen:r,blockSize32:i,V:h,B32:f,B:x,tmp:a,blockMixCb:l}=Ft(e,t,n);ot||st(f);for(let y=0;y<c;y++){let p=i*y;for(let d=0;d<i;d++)h[d]=f[p+d];for(let d=0,m=0;d<s-1;d++)at(h,m,h,m+=i,o),l();at(h,(s-1)*i,f,p,o),l();for(let d=0;d<s;d++){let m=f[p+i-16]%s;for(let b=0;b<i;b++)a[b]=f[p+b]^h[m*i+b];at(a,0,f,p,o),l()}}return ot||st(f),Vt(e,r,x,h,a)}var z;(function(e){e.MAXIMUM="Maximum",e.LONG="Long",e.MEDIUM="Medium",e.SHORT="Short",e.PIN="PIN",e.NAME="Name",e.PHRASE="Phrase",e.BASIC="Basic"})(z||(z={}));var mt={Maximum:["anoxxxxxxxxxxxxxxxxx","axxxxxxxxxxxxxxxxxno"],Long:["CvcvnoCvcvCvcv","CvcvCvcvnoCvcv","CvcvCvcvCvcvno","CvccnoCvcvCvcv","CvccCvcvnoCvcv","CvccCvcvCvcvno","CvcvnoCvccCvcv","CvcvCvccnoCvcv","CvcvCvccCvcvno","CvcvnoCvcvCvcc","CvcvCvcvnoCvcc","CvcvCvcvCvccno","CvccnoCvccCvcv","CvccCvccnoCvcv","CvccCvccCvcvno","CvcvnoCvccCvcc","CvcvCvccnoCvcc","CvcvCvccCvccno","CvccnoCvcvCvcc","CvccCvcvnoCvcc","CvccCvcvCvccno"],Medium:["CvcnoCvc","CvcCvcno"],Short:["Cvcn"],PIN:["nnnn"],Name:["cvccvcvcv"],Phrase:["cvcc cvc cvccvcv cvc","cvc cvccvcvcv cvcv","cv cvccv cvc cvcvccv"],Basic:["aaanaaan","aannaaan","aaannaaa"]},wt={V:"AEIOU",C:"BCDFGHJKLMNPQRSTVWXYZ",v:"aeiou",c:"bcdfghjklmnpqrstvwxyz",A:"AEIOUBCDFGHJKLMNPQRSTVWXYZ",a:"AEIOUaeiouBCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz",n:"0123456789",o:"@&%?,=[]_:-+*$#!'^~;()/.",x:"AEIOUaeiouBCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz0123456789!@#$%^&*()"," ":" "};var g;(function(e){e.AUTHENTICATION="Authentication",e.IDENTIFICATION="Identification",e.RECOVERY="Recovery"})(g||(g={}));function gt(e){switch(e){case g.AUTHENTICATION:return z.LONG;case g.IDENTIFICATION:return z.NAME;case g.RECOVERY:return z.MAXIMUM}}var ft=class{key;constructor(t){this.key=t}scope(t){switch(t){case g.AUTHENTICATION:return this.key;case g.IDENTIFICATION:return`${this.key}.login`;case g.RECOVERY:return`${this.key}.answer`}}},Ct=new ft("com.lyndir.masterpassword");var ut=class{name;secret;scoper;key;constructor(t,n,s=Ct){this.name=t,this.secret=n,this.scoper=s,this.key=this.userKey()}userKey(){let t=new TextEncoder,n=t.encode(this.name),s=t.encode(this.secret),o=t.encode(this.scoper.scope(g.AUTHENTICATION)),c=n.length,r=new Uint8Array([...o,...ht(c),...n]),i=32768,h=8,f=2,x=128*h*(i+f+2);return vt(s,r,{N:i,r:h,p:f,maxmem:x,dkLen:64})}siteKey(t,n,s){let o=new TextEncoder,c=o.encode(t),r=o.encode(this.scoper.scope(s)),i=c.length,h=new Uint8Array([...r,...ht(i),...c,...ht(n)]),f=new X(J,this.key);return f.update(h),f.digest()}site(t,n,s=1,o=g.AUTHENTICATION){n===void 0&&(n=gt(o));let c=this.siteKey(t,s,o),r=mt[n],i=r[c[0]%r.length],h="";for(let f=0;f<i.length;f++){let x=i[f],a=wt[x],l=a[c[f+1]%a.length];h+=l}return h}};function ht(e){let t=new ArrayBuffer(4);return new DataView(t).setInt32(0,e,!1),new Uint8Array(t)}return Bt(Dt);})();
-/*! Bundled license information:
-
-@noble/hashes/esm/utils.js:
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
-*/
diff --git a/tests/index.test.ts b/tests/index.test.ts
index 41d23cbd55ac284380927c32f7307c57354efa51..44119e4d660177f000868b43beb05027c8282950 100644
--- a/tests/index.test.ts
+++ b/tests/index.test.ts
@@ -1,8 +1,8 @@
import { assert, describe, it } from "vitest"
import { DOMParser, Element } from "@xmldom/xmldom"
-import { Spectre } from "../lib/spectre.js"
-import { Scope, SimpleScoper } from "../lib/scope.js"
-import { Template } from "../lib/template.js"
+import { Spectre } from "../src/spectre.js"
+import { Scope, SimpleScoper } from "../src/scope.js"
+import { Template } from "../src/template.js"
import { readFileSync } from "node:fs"
import { join } from "node:path"
diff --git a/tsconfig.build.json b/tsconfig.build.json
index 9c71e1ef9b82e9ad37b1afb96fdb2da0de42b67a..4d2ecfe93f593d9e573961a7b9d91164ecd397d3 100644
--- a/tsconfig.build.json
+++ b/tsconfig.build.json
@@ -1,10 +1,12 @@
{
"extends": "./tsconfig.json",
- "include": ["lib"],
+ "include": [
+ "src"
+ ],
"compilerOptions": {
- "outDir": "dist",
+ "outDir": "lib",
"declaration": true,
"target": "ES2022",
"module": "Node16"
}
-}
+}
\ No newline at end of file