@cityofzion/bs-ethereum 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LedgerServiceEthereum.js +77 -43
- package/package.json +1 -1
|
@@ -83,59 +83,93 @@ class LedgerSigner extends ethers_1.Signer {
|
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
signMessage(message) {
|
|
86
|
-
var _a, _b;
|
|
86
|
+
var _a, _b, _c;
|
|
87
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
|
|
89
|
-
message
|
|
88
|
+
try {
|
|
89
|
+
if (typeof message === 'string') {
|
|
90
|
+
message = ethers_1.ethers.utils.toUtf8Bytes(message);
|
|
91
|
+
}
|
|
92
|
+
const ledgerApp = new hw_app_eth_1.default(__classPrivateFieldGet(this, _LedgerSigner_transport, "f"));
|
|
93
|
+
(_a = __classPrivateFieldGet(this, _LedgerSigner_emitter, "f")) === null || _a === void 0 ? void 0 : _a.emit('getSignatureStart');
|
|
94
|
+
const obj = yield __classPrivateFieldGet(this, _LedgerSigner_instances, "m", _LedgerSigner_retry).call(this, () => ledgerApp.signPersonalMessage(__classPrivateFieldGet(this, _LedgerSigner_path, "f"), ethers_1.ethers.utils.hexlify(message).substring(2)));
|
|
95
|
+
(_b = __classPrivateFieldGet(this, _LedgerSigner_emitter, "f")) === null || _b === void 0 ? void 0 : _b.emit('getSignatureEnd');
|
|
96
|
+
// Normalize the signature for Ethers
|
|
97
|
+
obj.r = '0x' + obj.r;
|
|
98
|
+
obj.s = '0x' + obj.s;
|
|
99
|
+
return ethers_1.ethers.utils.joinSignature(obj);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
(_c = __classPrivateFieldGet(this, _LedgerSigner_emitter, "f")) === null || _c === void 0 ? void 0 : _c.emit('getSignatureEnd');
|
|
103
|
+
throw error;
|
|
90
104
|
}
|
|
91
|
-
const ledgerApp = new hw_app_eth_1.default(__classPrivateFieldGet(this, _LedgerSigner_transport, "f"));
|
|
92
|
-
(_a = __classPrivateFieldGet(this, _LedgerSigner_emitter, "f")) === null || _a === void 0 ? void 0 : _a.emit('getSignatureStart');
|
|
93
|
-
const obj = yield __classPrivateFieldGet(this, _LedgerSigner_instances, "m", _LedgerSigner_retry).call(this, () => ledgerApp.signPersonalMessage(__classPrivateFieldGet(this, _LedgerSigner_path, "f"), ethers_1.ethers.utils.hexlify(message).substring(2)));
|
|
94
|
-
(_b = __classPrivateFieldGet(this, _LedgerSigner_emitter, "f")) === null || _b === void 0 ? void 0 : _b.emit('getSignatureEnd');
|
|
95
|
-
// Normalize the signature for Ethers
|
|
96
|
-
obj.r = '0x' + obj.r;
|
|
97
|
-
obj.s = '0x' + obj.s;
|
|
98
|
-
return ethers_1.ethers.utils.joinSignature(obj);
|
|
99
105
|
});
|
|
100
106
|
}
|
|
101
107
|
signTransaction(transaction) {
|
|
102
|
-
var _a, _b;
|
|
108
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
103
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
110
|
+
try {
|
|
111
|
+
const ledgerApp = new hw_app_eth_1.default(__classPrivateFieldGet(this, _LedgerSigner_transport, "f"));
|
|
112
|
+
const tx = yield ethers_1.ethers.utils.resolveProperties(transaction);
|
|
113
|
+
const unsignedTransaction = {
|
|
114
|
+
chainId: (_a = tx.chainId) !== null && _a !== void 0 ? _a : undefined,
|
|
115
|
+
data: (_b = tx.data) !== null && _b !== void 0 ? _b : undefined,
|
|
116
|
+
gasLimit: (_c = tx.gasLimit) !== null && _c !== void 0 ? _c : undefined,
|
|
117
|
+
gasPrice: (_d = tx.gasPrice) !== null && _d !== void 0 ? _d : undefined,
|
|
118
|
+
nonce: tx.nonce ? ethers_1.ethers.BigNumber.from(tx.nonce).toNumber() : undefined,
|
|
119
|
+
to: (_e = tx.to) !== null && _e !== void 0 ? _e : undefined,
|
|
120
|
+
value: (_f = tx.value) !== null && _f !== void 0 ? _f : undefined,
|
|
121
|
+
};
|
|
122
|
+
const serializedUnsignedTransaction = ethers_1.ethers.utils.serializeTransaction(unsignedTransaction).substring(2);
|
|
123
|
+
const resolution = yield hw_app_eth_1.ledgerService.resolveTransaction(serializedUnsignedTransaction, {}, {});
|
|
124
|
+
(_g = __classPrivateFieldGet(this, _LedgerSigner_emitter, "f")) === null || _g === void 0 ? void 0 : _g.emit('getSignatureStart');
|
|
125
|
+
const signature = yield __classPrivateFieldGet(this, _LedgerSigner_instances, "m", _LedgerSigner_retry).call(this, () => ledgerApp.signTransaction(__classPrivateFieldGet(this, _LedgerSigner_path, "f"), serializedUnsignedTransaction, resolution));
|
|
126
|
+
(_h = __classPrivateFieldGet(this, _LedgerSigner_emitter, "f")) === null || _h === void 0 ? void 0 : _h.emit('getSignatureEnd');
|
|
127
|
+
return ethers_1.ethers.utils.serializeTransaction(unsignedTransaction, {
|
|
128
|
+
v: ethers_1.ethers.BigNumber.from('0x' + signature.v).toNumber(),
|
|
129
|
+
r: '0x' + signature.r,
|
|
130
|
+
s: '0x' + signature.s,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
(_j = __classPrivateFieldGet(this, _LedgerSigner_emitter, "f")) === null || _j === void 0 ? void 0 : _j.emit('getSignatureEnd');
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
117
137
|
});
|
|
118
138
|
}
|
|
119
139
|
_signTypedData(domain, types, value) {
|
|
120
|
-
var _a, _b;
|
|
140
|
+
var _a, _b, _c;
|
|
121
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
try {
|
|
143
|
+
const populated = yield ethers_1.ethers.utils._TypedDataEncoder.resolveNames(domain, types, value, (name) => __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
if (!this.provider)
|
|
145
|
+
throw new Error('Cannot resolve ENS names without a provider');
|
|
146
|
+
const resolved = yield this.provider.resolveName(name);
|
|
147
|
+
if (!resolved)
|
|
148
|
+
throw new Error('No address found for domain name');
|
|
149
|
+
return resolved;
|
|
150
|
+
}));
|
|
151
|
+
const payload = ethers_1.ethers.utils._TypedDataEncoder.getPayload(populated.domain, types, populated.value);
|
|
152
|
+
const ledgerApp = new hw_app_eth_1.default(__classPrivateFieldGet(this, _LedgerSigner_transport, "f"));
|
|
153
|
+
(_a = __classPrivateFieldGet(this, _LedgerSigner_emitter, "f")) === null || _a === void 0 ? void 0 : _a.emit('getSignatureStart');
|
|
154
|
+
let obj;
|
|
155
|
+
try {
|
|
156
|
+
obj = yield __classPrivateFieldGet(this, _LedgerSigner_instances, "m", _LedgerSigner_retry).call(this, () => ledgerApp.signEIP712Message(__classPrivateFieldGet(this, _LedgerSigner_path, "f"), payload));
|
|
157
|
+
}
|
|
158
|
+
catch (_d) {
|
|
159
|
+
const domainSeparatorHex = ethers_1.ethers.utils._TypedDataEncoder.hashDomain(payload.domain);
|
|
160
|
+
const hashStructMessageHex = ethers_1.ethers.utils._TypedDataEncoder.hashStruct(payload.primaryType, types, payload.message);
|
|
161
|
+
obj = yield __classPrivateFieldGet(this, _LedgerSigner_instances, "m", _LedgerSigner_retry).call(this, () => ledgerApp.signEIP712HashedMessage(__classPrivateFieldGet(this, _LedgerSigner_path, "f"), domainSeparatorHex, hashStructMessageHex));
|
|
162
|
+
}
|
|
163
|
+
(_b = __classPrivateFieldGet(this, _LedgerSigner_emitter, "f")) === null || _b === void 0 ? void 0 : _b.emit('getSignatureEnd');
|
|
164
|
+
// Normalize the signature for Ethers
|
|
165
|
+
obj.r = '0x' + obj.r;
|
|
166
|
+
obj.s = '0x' + obj.s;
|
|
167
|
+
return ethers_1.ethers.utils.joinSignature(obj);
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
(_c = __classPrivateFieldGet(this, _LedgerSigner_emitter, "f")) === null || _c === void 0 ? void 0 : _c.emit('getSignatureEnd');
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
139
173
|
});
|
|
140
174
|
}
|
|
141
175
|
}
|