"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("crypto"),t=require("ethers"),r=require("uuid"),i=require("uint8arrays"),s=require("@i3m/base-wallet");function a(e){return e&&e.__esModule?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var n=a(e),c=o(i);class u extends s.WalletError{}class l{constructor(e,t){this.dialog=e,this.store=t}async import(e){const i=r.v4(),a=t.ethers.utils.computePublicKey(s.parseHex(e)),o={kid:i,type:"Secp256k1",publicKeyHex:s.parseHex(a,!1),privateKeyHex:s.parseHex(e,!1)},n=await this.store.get("keys");return await this.store.set("keys",{...n,[i]:o}),o}async createAccountKeyPair(){const e=n.default.randomBytes(32).toString("hex");return(await this.import(e)).kid}async getPublicKey(e){const r=await this.store.get("keys");if(void 0===r)throw new u("No keys initialized yet");return t.ethers.utils.arrayify(s.parseHex(r[e].publicKeyHex))}async signDigest(e,r){const i=await this.store.get("keys");if(void 0===i)throw new u("No keys initialized yet");const a=s.parseHex(i[e].privateKeyHex),o=new t.ethers.utils.SigningKey(a);if(!0!==await this.dialog.confirmation({title:"Sign?",message:`Are you sure you want to sign using key ${a} the following hex data: \n${t.ethers.utils.hexlify(r)}`,acceptMsg:"Sign",rejectMsg:"Reject"}))throw new u("Signature rejected by user");const n=o.signDigest(r),l=t.ethers.utils.joinSignature(n);return c.fromString(l.substring(2),"base16")}async delete(e){return await this.store.delete(`keys.${e}`),!0}async wipe(){}}class y extends s.BaseWallet{async importDid(e){if(void 0===e&&(e=await this.dialog.form({title:"Import DID",descriptors:{alias:{type:"text",message:"Set an alias for your DID"},privateKey:{type:"text",message:"Paste the private key"}},order:["alias","privateKey"]})),void 0===e)return;const r=this.getKeyWallet(),i=await r.import(s.parseHex(e.privateKey)),a=t.ethers.utils.computePublicKey(s.parseHex(i.publicKeyHex),!0);await this.veramo.agent.didManagerImport({did:`${this.provider}:${a}`,alias:e.alias,controllerKeyId:i.kid,keys:[{...i,type:"Secp256k1",kms:this.veramo.defaultKms}],provider:this.provider,services:[]})}}exports.BokWallet=y,exports.default=async e=>{const t=new l(e.dialog,e.store);return new y({...e,keyWallet:t})}; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXgubm9kZS5janMiLCJzb3VyY2VzIjpbIi4uL3NyYy90cy9lcnJvcnMudHMiLCIuLi9zcmMvdHMvYm9rLWtleS13YWxsZXQudHMiLCIuLi9zcmMvdHMvYm9rLXdhbGxldC50cyIsIi4uL3NyYy90cy9pbmRleC50cyJdLCJzb3VyY2VzQ29udGVudCI6bnVsbCwibmFtZXMiOlsiQm9rV2FsbGV0RXJyb3IiLCJXYWxsZXRFcnJvciIsIkJva0tleVdhbGxldCIsImNvbnN0cnVjdG9yIiwiZGlhbG9nIiwic3RvcmUiLCJ0aGlzIiwiYXN5bmMiLCJwcml2YXRlS2V5SGV4Iiwia2lkIiwidXVpZCIsInB1YmxpY0tleUhleCIsImV0aGVycyIsInV0aWxzIiwiY29tcHV0ZVB1YmxpY0tleSIsInBhcnNlSGV4Iiwia2V5IiwidHlwZSIsImtleXMiLCJnZXQiLCJzZXQiLCJjcnlwdG8iLCJyYW5kb21CeXRlcyIsInRvU3RyaW5nIiwiaW1wb3J0IiwidW5kZWZpbmVkIiwiYXJyYXlpZnkiLCJtZXNzYWdlRGlnZXN0Iiwic2lnbmluZ0tleSIsIlNpZ25pbmdLZXkiLCJjb25maXJtYXRpb24iLCJ0aXRsZSIsIm1lc3NhZ2UiLCJoZXhsaWZ5IiwiYWNjZXB0TXNnIiwicmVqZWN0TXNnIiwic2lnbmF0dXJlIiwic2lnbkRpZ2VzdCIsInNpZ25hdHVyZUhleCIsImpvaW5TaWduYXR1cmUiLCJ1OGEiLCJmcm9tU3RyaW5nIiwic3V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