UNPKG

@nori-zk/mina-token-bridge

Version:

A Mina zk-program contract allowing users to mint tokens on Nori Bridge.

52 lines 2.77 kB
var _MockWalletWorker_minaPrivateKey; import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; import { fetchAccount, Mina, PrivateKey, Transaction, } from 'o1js'; import { compileEcdsaEthereum, compileEcdsaSigPresentationVerifier, createEcdsaSigPresentation, } from '../../credentialAttestation.js'; export class MockWalletWorker { constructor() { // Initialise methods _MockWalletWorker_minaPrivateKey.set(this, void 0); } async setMinaPrivateKey(minaPrivateKeyBase58) { if (__classPrivateFieldGet(this, _MockWalletWorker_minaPrivateKey, "f")) throw new Error('Mina private key has already been set.'); __classPrivateFieldSet(this, _MockWalletWorker_minaPrivateKey, PrivateKey.fromBase58(minaPrivateKeyBase58), "f"); } // CREDENTIAL METHODS ****************************************************************************** //credential (compile) async compileCredentialDeps() { // Compile programs / contracts console.time('compileEcdsaEthereum'); await compileEcdsaEthereum(); console.timeEnd('compileEcdsaEthereum'); // 1:20.330 (m:ss.mmm) console.time('compilePresentationVerifier'); await compileEcdsaSigPresentationVerifier(); console.timeEnd('compilePresentationVerifier'); // 11.507s } // Credential methods async computeEcdsaSigPresentation(presentationRequestJson, credentialJson) { console.time('getPresentation'); const presentationJson = await createEcdsaSigPresentation(presentationRequestJson, credentialJson, __classPrivateFieldGet(this, _MockWalletWorker_minaPrivateKey, "f")); console.timeEnd('getPresentation'); // 46.801s return presentationJson; } // Mina setup ****************************************************************************** async minaSetup(options) { const Network = Mina.Network(options); Mina.setActiveInstance(Network); } // ****************************************************************************** async fetchAccounts(accounts) { await Promise.all(accounts.map((addr) => fetchAccount({ publicKey: addr }))); } // Sign and send transaction async signAndSend(provedTxJsonStr) { if (!__classPrivateFieldGet(this, _MockWalletWorker_minaPrivateKey, "f")) throw new Error('#minaPrivateKey is undefined please call setMinaPrivateKey first'); const tx = Transaction.fromJSON(JSON.parse(provedTxJsonStr)); const result = await tx.sign([__classPrivateFieldGet(this, _MockWalletWorker_minaPrivateKey, "f")]).send().wait(); return { txHash: result.hash }; } } _MockWalletWorker_minaPrivateKey = new WeakMap(); //# sourceMappingURL=worker.js.map