You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tauri-plugins-workspace/plugins/stronghold/guest-js/dist/index.min.js

218 lines
7.0 KiB

var d=Object.defineProperty;var e=(c,a)=>{for(var b in a)d(c,b,{get:a[b],enumerable:!0});};
var f={};e(f,{convertFileSrc:()=>w,invoke:()=>c,transformCallback:()=>s});function u(){return window.crypto.getRandomValues(new Uint32Array(1))[0]}function s(e,r=!1){let n=u(),t=`_${n}`;return Object.defineProperty(window,t,{value:o=>(r&&Reflect.deleteProperty(window,t),e==null?void 0:e(o)),writable:!1,configurable:!0}),n}async function c(e,r={}){return new Promise((n,t)=>{let o=s(i=>{n(i),Reflect.deleteProperty(window,`_${a}`);},!0),a=s(i=>{t(i),Reflect.deleteProperty(window,`_${o}`);},!0);window.__TAURI_IPC__({cmd:e,callback:o,error:a,...r});})}function w(e,r="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${r}.localhost/${n}`:`${r}://localhost/${n}`}
function toBytesDto(v) {
if (typeof v === "string") {
return v;
}
return Array.from(v instanceof ArrayBuffer ? new Uint8Array(v) : v);
}
class Location {
constructor(type, payload) {
this.type = type;
this.payload = payload;
}
static generic(vault, record) {
return new Location("Generic", {
vault: toBytesDto(vault),
record: toBytesDto(record),
});
}
static counter(vault, counter) {
return new Location("Counter", {
vault: toBytesDto(vault),
counter,
});
}
}
class ProcedureExecutor {
constructor(procedureArgs) {
this.procedureArgs = procedureArgs;
}
async generateSLIP10Seed(outputLocation, sizeBytes) {
return await c("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "SLIP10Generate",
payload: {
output: outputLocation,
sizeBytes,
},
},
}).then((n) => Uint8Array.from(n));
}
async deriveSLIP10(chain, source, sourceLocation, outputLocation) {
return await c("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "SLIP10Derive",
payload: {
chain,
input: {
type: source,
payload: sourceLocation,
},
output: outputLocation,
},
},
}).then((n) => Uint8Array.from(n));
}
async recoverBIP39(mnemonic, outputLocation, passphrase) {
return await c("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "BIP39Recover",
payload: {
mnemonic,
passphrase,
output: outputLocation,
},
},
}).then((n) => Uint8Array.from(n));
}
async generateBIP39(outputLocation, passphrase) {
return await c("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "BIP39Generate",
payload: {
output: outputLocation,
passphrase,
},
},
}).then((n) => Uint8Array.from(n));
}
async getEd25519PublicKey(privateKeyLocation) {
return await c("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "PublicKey",
payload: {
type: "Ed25519",
privateKey: privateKeyLocation,
},
},
}).then((n) => Uint8Array.from(n));
}
async signEd25519(privateKeyLocation, msg) {
return await c("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "Ed25519Sign",
payload: {
privateKey: privateKeyLocation,
msg,
},
},
}).then((n) => Uint8Array.from(n));
}
}
class Client {
constructor(path, name) {
this.path = path;
this.name = toBytesDto(name);
}
getVault(name) {
return new Vault(this.path, this.name, toBytesDto(name));
}
getStore() {
return new Store(this.path, this.name);
}
}
class Store {
constructor(path, client) {
this.path = path;
this.client = client;
}
async get(key) {
return await c("plugin:stronghold|get_store_record", {
snapshotPath: this.path,
client: this.client,
key: toBytesDto(key),
}).then((v) => Uint8Array.from(v));
}
async insert(key, value, lifetime) {
return await c("plugin:stronghold|save_store_record", {
snapshotPath: this.path,
client: this.client,
key: toBytesDto(key),
value,
lifetime,
});
}
async remove(key) {
return await c("plugin:stronghold|remove_store_record", {
snapshotPath: this.path,
client: this.client,
key: toBytesDto(key),
}).then((v) => (v != null ? Uint8Array.from(v) : null));
}
}
class Vault extends ProcedureExecutor {
constructor(path, client, name) {
super({
snapshotPath: path,
client,
vault: name,
});
this.path = path;
this.client = toBytesDto(client);
this.name = toBytesDto(name);
}
async insert(recordPath, secret) {
return await c("plugin:stronghold|save_secret", {
snapshotPath: this.path,
client: this.client,
vault: this.name,
recordPath: toBytesDto(recordPath),
secret,
});
}
async remove(location) {
return await c("plugin:stronghold|remove_secret", {
snapshotPath: this.path,
client: this.client,
vault: this.name,
location,
});
}
}
class Stronghold {
constructor(path, password) {
this.path = path;
void this.reload(password);
}
async reload(password) {
return await c("plugin:stronghold|initialize", {
snapshotPath: this.path,
password,
});
}
async unload() {
return await c("plugin:stronghold|destroy", {
snapshotPath: this.path,
});
}
async loadClient(client) {
return await c("plugin:stronghold|load_client", {
snapshotPath: this.path,
client: toBytesDto(client),
}).then(() => new Client(this.path, client));
}
async createClient(client) {
return await c("plugin:stronghold|create_client", {
snapshotPath: this.path,
client: toBytesDto(client),
}).then(() => new Client(this.path, client));
}
async save() {
return await c("plugin:stronghold|save", {
snapshotPath: this.path,
});
}
}
export { Client, Location, Store, Stronghold, Vault };
//# sourceMappingURL=index.min.js.map