@keystonehq/metamask-airgapped-keyring
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -7,3 +7,2 @@ 'use strict'; | ||
var HDKey = _interopDefault(require('hdkey')); | ||
var baseEthKeyring = require('@keystonehq/base-eth-keyring'); | ||
@@ -125,2 +124,3 @@ var events = require('events'); | ||
super(opts); | ||
this.indexedAccounts = {}; | ||
@@ -157,4 +157,5 @@ this.getInteraction = () => { | ||
this.latestAccount = 0; | ||
this.hdk = new HDKey(); | ||
this.hdk = undefined; | ||
this.unlockedAccount = 0; | ||
this.indexedAccounts = {}; | ||
}; | ||
@@ -180,3 +181,2 @@ | ||
const to = from + n; | ||
const newAccounts = []; | ||
@@ -186,8 +186,8 @@ for (let i = from; i < to; i++) { | ||
newAccounts.push(address); | ||
this.page = 0; | ||
this.latestAccount++; | ||
this.indexedAccounts[i] = address; | ||
} | ||
this.accounts = this.accounts.concat(newAccounts); | ||
this.accounts = Object.values(this.indexedAccounts); | ||
resolve(this.accounts); | ||
@@ -194,0 +194,0 @@ } catch (e) { |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("hdkey")),s=require("@keystonehq/base-eth-keyring"),n=require("events"),i=require("@metamask/obs-store"),r=require("@keystonehq/bc-ur-registry-eth"),c=require("uuid"),o=require("@ethereumjs/tx"),a=e(require("rlp"));class h extends n.EventEmitter{constructor(){if(super(),this.readCryptoHDKey=()=>new Promise((e,t)=>{this.memStore.updateState({sync:{reading:!0}}),this.on("keystone-sync_success",t=>{const s=r.CryptoHDKey.fromCBOR(Buffer.from(t,"hex"));this.resetState(),e(s)}),this.on("keystone-sync_cancel",()=>{this.resetState(),t(new Error("KeystoneError#sync_cancel. Sync process canceled, please retry"))})}),this.submitCryptoHDKey=e=>{this.emit("keystone-sync_success",e)},this.cancelReadCryptoHDKey=()=>{this.emit("keystone-sync_cancel")},this.requestSignature=(e,t,s)=>new Promise((n,i)=>{const o=e.toUR(),a=e.getRequestId(),h=c.stringify(a),u={requestId:h,payload:{type:o.type,cbor:o.cbor.toString("hex")},title:t,description:s};this.memStore.updateState({sign:{request:u}}),this.once(h+"-signed",e=>{const t=r.ETHSignature.fromCBOR(Buffer.from(e,"hex"));this.resetState(),n(t)}),this.once(h+"-canceled",()=>{this.resetState(),i(new Error("KeystoneError#Tx_canceled. Signing canceled, please retry"))})}),this.submitSignature=(e,t)=>{this.emit(e+"-signed",t)},this.cancelRequestSignature=()=>{const e=this.memStore.getState().sign.request;if(e){const{requestId:t}=e;this.memStore.updateState({sign:{}}),this.emit(t+"-canceled")}},this.resetState=()=>{this.memStore.updateState({sync:{reading:!1},sign:{}})},h.instance)return h.instance;this.memStore=new i.ObservableStore({sync:{reading:!1},sign:{},_version:1}),h.instance=this}}class u extends s.BaseKeyring{constructor(e){if(super(e),this.getInteraction=()=>new h,this.getMemStore=()=>this.getInteraction().memStore,this.setAccountToUnlock=e=>{this.unlockedAccount=parseInt(e,10)},this.removeAccount=e=>{if(!this.accounts.map(e=>e.toLowerCase()).includes(e.toLowerCase()))throw new Error(`Address ${e} not found in this keyring`);this.accounts=this.accounts.filter(t=>t.toLowerCase()!==e.toLowerCase())},this.forgetDevice=()=>{this.xfp="",this.xpub="",this.hdPath="",this.page=0,this.perPage=5,this.accounts=[],this.currentAccount=0,this.paths={},this.latestAccount=0,this.hdk=new t,this.unlockedAccount=0},this.submitCryptoHDKey=this.getInteraction().submitCryptoHDKey,this.submitSignature=this.getInteraction().submitSignature,this.cancelReadCryptoHDKey=this.getInteraction().cancelReadCryptoHDKey,this.cancelSignRequest=this.getInteraction().cancelRequestSignature,u.instance)return u.instance.deserialize(e),u.instance;u.instance=this}addAccounts(e=1){return new Promise((t,s)=>{try{const s=this.unlockedAccount,n=s+e,i=[];for(let e=s;e<n;e++){const t=this._addressFromIndex("m",e);i.push(t),this.page=0,this.latestAccount++}this.accounts=this.accounts.concat(i),t(this.accounts)}catch(e){s(e)}})}async signTransaction(e,t){const s=0===t.type?r.DataType.transaction:r.DataType.typedTransaction;let n;n=0===t.type?a.encode(t.getMessageToSign(!1)):t.getMessageToSign(!1);const i=this._pathFromAddress(e),h=t.common.chainId(),u=c.v4(),y=r.EthSignRequest.constructETHRequest(n,s,i,this.xfp,u,h),{r:d,s:g,v:m}=await this.requestSignature(u,y,"Scan with your Keystone",'After your Keystone has signed the transaction, click on "Scan Keystone" to receive the signature'),p=t.toJSON();return p.v=m,p.s=g,p.r=d,p.type=t.type,o.TransactionFactory.fromTxData(p,{common:t.common})}}u.type=s.BaseKeyring.type,exports.MetaMaskKeyring=u; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@keystonehq/base-eth-keyring"),s=require("events"),n=require("@metamask/obs-store"),i=require("@keystonehq/bc-ur-registry-eth"),r=require("uuid"),c=require("@ethereumjs/tx"),o=(e=require("rlp"))&&"object"==typeof e&&"default"in e?e.default:e;class a extends s.EventEmitter{constructor(){if(super(),this.readCryptoHDKey=()=>new Promise((e,t)=>{this.memStore.updateState({sync:{reading:!0}}),this.on("keystone-sync_success",t=>{const s=i.CryptoHDKey.fromCBOR(Buffer.from(t,"hex"));this.resetState(),e(s)}),this.on("keystone-sync_cancel",()=>{this.resetState(),t(new Error("KeystoneError#sync_cancel. Sync process canceled, please retry"))})}),this.submitCryptoHDKey=e=>{this.emit("keystone-sync_success",e)},this.cancelReadCryptoHDKey=()=>{this.emit("keystone-sync_cancel")},this.requestSignature=(e,t,s)=>new Promise((n,c)=>{const o=e.toUR(),a=e.getRequestId(),h=r.stringify(a),u={requestId:h,payload:{type:o.type,cbor:o.cbor.toString("hex")},title:t,description:s};this.memStore.updateState({sign:{request:u}}),this.once(h+"-signed",e=>{const t=i.ETHSignature.fromCBOR(Buffer.from(e,"hex"));this.resetState(),n(t)}),this.once(h+"-canceled",()=>{this.resetState(),c(new Error("KeystoneError#Tx_canceled. Signing canceled, please retry"))})}),this.submitSignature=(e,t)=>{this.emit(e+"-signed",t)},this.cancelRequestSignature=()=>{const e=this.memStore.getState().sign.request;if(e){const{requestId:t}=e;this.memStore.updateState({sign:{}}),this.emit(t+"-canceled")}},this.resetState=()=>{this.memStore.updateState({sync:{reading:!1},sign:{}})},a.instance)return a.instance;this.memStore=new n.ObservableStore({sync:{reading:!1},sign:{},_version:1}),a.instance=this}}class h extends t.BaseKeyring{constructor(e){if(super(e),this.indexedAccounts={},this.getInteraction=()=>new a,this.getMemStore=()=>this.getInteraction().memStore,this.setAccountToUnlock=e=>{this.unlockedAccount=parseInt(e,10)},this.removeAccount=e=>{if(!this.accounts.map(e=>e.toLowerCase()).includes(e.toLowerCase()))throw new Error(`Address ${e} not found in this keyring`);this.accounts=this.accounts.filter(t=>t.toLowerCase()!==e.toLowerCase())},this.forgetDevice=()=>{this.xfp="",this.xpub="",this.hdPath="",this.page=0,this.perPage=5,this.accounts=[],this.currentAccount=0,this.paths={},this.latestAccount=0,this.hdk=void 0,this.unlockedAccount=0,this.indexedAccounts={}},this.submitCryptoHDKey=this.getInteraction().submitCryptoHDKey,this.submitSignature=this.getInteraction().submitSignature,this.cancelReadCryptoHDKey=this.getInteraction().cancelReadCryptoHDKey,this.cancelSignRequest=this.getInteraction().cancelRequestSignature,h.instance)return h.instance.deserialize(e),h.instance;h.instance=this}addAccounts(e=1){return new Promise((t,s)=>{try{const s=this.unlockedAccount,n=s+e;for(let e=s;e<n;e++){const t=this._addressFromIndex("m",e);this.page=0,this.latestAccount++,this.indexedAccounts[e]=t}this.accounts=Object.values(this.indexedAccounts),t(this.accounts)}catch(e){s(e)}})}async signTransaction(e,t){const s=0===t.type?i.DataType.transaction:i.DataType.typedTransaction;let n;n=0===t.type?o.encode(t.getMessageToSign(!1)):t.getMessageToSign(!1);const a=this._pathFromAddress(e),h=t.common.chainId(),u=r.v4(),y=i.EthSignRequest.constructETHRequest(n,s,a,this.xfp,u,h),{r:d,s:g,v:m}=await this.requestSignature(u,y,"Scan with your Keystone",'After your Keystone has signed the transaction, click on "Scan Keystone" to receive the signature'),p=t.toJSON();return p.v=m,p.s=g,p.r=d,p.type=t.type,c.TransactionFactory.fromTxData(p,{common:t.common})}}h.type=t.BaseKeyring.type,exports.MetaMaskKeyring=h; | ||
//# sourceMappingURL=metamask-airgapped-keyring.cjs.production.min.js.map |
@@ -1,2 +0,1 @@ | ||
import HDKey from 'hdkey'; | ||
import { BaseKeyring } from '@keystonehq/base-eth-keyring'; | ||
@@ -118,2 +117,3 @@ import { EventEmitter } from 'events'; | ||
super(opts); | ||
this.indexedAccounts = {}; | ||
@@ -150,4 +150,5 @@ this.getInteraction = () => { | ||
this.latestAccount = 0; | ||
this.hdk = new HDKey(); | ||
this.hdk = undefined; | ||
this.unlockedAccount = 0; | ||
this.indexedAccounts = {}; | ||
}; | ||
@@ -173,3 +174,2 @@ | ||
const to = from + n; | ||
const newAccounts = []; | ||
@@ -179,8 +179,8 @@ for (let i = from; i < to; i++) { | ||
newAccounts.push(address); | ||
this.page = 0; | ||
this.latestAccount++; | ||
this.indexedAccounts[i] = address; | ||
} | ||
this.accounts = this.accounts.concat(newAccounts); | ||
this.accounts = Object.values(this.indexedAccounts); | ||
resolve(this.accounts); | ||
@@ -187,0 +187,0 @@ } catch (e) { |
@@ -7,2 +7,3 @@ import { BaseKeyring, StoredKeyring } from '@keystonehq/base-eth-keyring'; | ||
private unlockedAccount; | ||
private indexedAccounts; | ||
constructor(opts?: StoredKeyring); | ||
@@ -9,0 +10,0 @@ getInteraction: () => MetamaskInteractionProvider; |
{ | ||
"name": "@keystonehq/metamask-airgapped-keyring", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "airgapped eth keyring for metamask", | ||
@@ -30,6 +30,5 @@ "author": "aaronisme <aarondongchen@gmail.com>", | ||
"@ethereumjs/tx": "^3.3.0", | ||
"@keystonehq/base-eth-keyring": "^0.0.7", | ||
"@keystonehq/bc-ur-registry-eth": "^0.6.11", | ||
"@keystonehq/base-eth-keyring": "^0.0.8", | ||
"@keystonehq/bc-ur-registry-eth": "^0.6.12", | ||
"@metamask/obs-store": "^7.0.0", | ||
"hdkey": "^2.0.1", | ||
"rlp": "^2.2.6", | ||
@@ -45,3 +44,3 @@ "uuid": "^8.3.2" | ||
}, | ||
"gitHead": "6649d0ec62611bf82199a040fcdba77b59e012e4" | ||
"gitHead": "cdb5ca0fe6826a973dc9c739ab443074d9f62671" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
63323
6
479
+ Added@keystonehq/base-eth-keyring@0.0.8(transitive)
- Removedhdkey@^2.0.1
- Removed@keystonehq/base-eth-keyring@0.0.7(transitive)