@sphereon/ssi-sdk-web3.headless-provider 0.33.1-feature.vcdm2.tsup.32 → 0.33.1-next.2
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/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/ethers-headless-provider.d.ts +73 -0
- package/dist/ethers-headless-provider.d.ts.map +1 -0
- package/dist/ethers-headless-provider.js +276 -0
- package/dist/ethers-headless-provider.js.map +1 -0
- package/dist/ethers-kms-signer.d.ts +37 -0
- package/dist/ethers-kms-signer.d.ts.map +1 -0
- package/dist/ethers-kms-signer.js +183 -0
- package/dist/ethers-kms-signer.js.map +1 -0
- package/dist/event-emitter.d.ts +8 -0
- package/dist/event-emitter.d.ts.map +1 -0
- package/dist/event-emitter.js +44 -0
- package/dist/event-emitter.js.map +1 -0
- package/dist/factory.d.ts +6 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +30 -0
- package/dist/factory.js.map +1 -0
- package/dist/functions.d.ts +5 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/functions.js +33 -0
- package/dist/functions.js.map +1 -0
- package/dist/index.d.ts +9 -218
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -619
- package/dist/index.js.map +1 -1
- package/dist/rpc-server.d.ts +8 -0
- package/dist/rpc-server.d.ts.map +1 -0
- package/dist/rpc-server.js +99 -0
- package/dist/rpc-server.js.map +1 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +25 -0
- package/dist/types.js.map +1 -0
- package/package.json +16 -26
- package/src/ethers-kms-signer.ts +3 -4
- package/dist/index.cjs +0 -652
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -220
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class ErrorWithCode extends Error {
|
|
2
|
+
code?: number;
|
|
3
|
+
constructor(message?: string, code?: number);
|
|
4
|
+
}
|
|
5
|
+
export declare const Deny: () => ErrorWithCode;
|
|
6
|
+
export declare const Unauthorized: () => ErrorWithCode;
|
|
7
|
+
export declare const UnsupportedMethod: () => ErrorWithCode;
|
|
8
|
+
export declare const Disconnected: () => ErrorWithCode;
|
|
9
|
+
export declare const ChainDisconnected: () => ErrorWithCode;
|
|
10
|
+
export declare const UnrecognizedChainID: () => ErrorWithCode;
|
|
11
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;IAG7B,IAAI,CAAC,EAAE,MAAM;gBADpB,OAAO,CAAC,EAAE,MAAM,EACT,IAAI,CAAC,EAAE,MAAM;CAKvB;AAED,eAAO,MAAM,IAAI,QAAO,aAA0E,CAAA;AAElG,eAAO,MAAM,YAAY,QAAO,aAAoH,CAAA;AAEpJ,eAAO,MAAM,iBAAiB,QAAO,aAA+F,CAAA;AAEpI,eAAO,MAAM,YAAY,QAAO,aAAyF,CAAA;AAEzH,eAAO,MAAM,iBAAiB,QAAO,aAAiG,CAAA;AAEtI,eAAO,MAAM,mBAAmB,QAAO,aACwE,CAAA"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnrecognizedChainID = exports.ChainDisconnected = exports.Disconnected = exports.UnsupportedMethod = exports.Unauthorized = exports.Deny = exports.ErrorWithCode = void 0;
|
|
4
|
+
class ErrorWithCode extends Error {
|
|
5
|
+
constructor(message, code) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.ErrorWithCode = ErrorWithCode;
|
|
12
|
+
const Deny = () => new ErrorWithCode('The user rejected the request.', 4001);
|
|
13
|
+
exports.Deny = Deny;
|
|
14
|
+
const Unauthorized = () => new ErrorWithCode('The requested method and/or account has not been authorized by the user.', 4100);
|
|
15
|
+
exports.Unauthorized = Unauthorized;
|
|
16
|
+
const UnsupportedMethod = () => new ErrorWithCode('The Provider does not support the requested method.', 4200);
|
|
17
|
+
exports.UnsupportedMethod = UnsupportedMethod;
|
|
18
|
+
const Disconnected = () => new ErrorWithCode('The Provider is disconnected from all chains.', 4900);
|
|
19
|
+
exports.Disconnected = Disconnected;
|
|
20
|
+
const ChainDisconnected = () => new ErrorWithCode('The Provider is not connected to the requested chain.', 4901);
|
|
21
|
+
exports.ChainDisconnected = ChainDisconnected;
|
|
22
|
+
const UnrecognizedChainID = () => new ErrorWithCode('Unrecognized chain ID. Try adding the chain using `wallet_addEthereumChain` first.', 4902);
|
|
23
|
+
exports.UnrecognizedChainID = UnrecognizedChainID;
|
|
24
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,aAAc,SAAQ,KAAK;IACtC,YACE,OAAgB,EACT,IAAa;QAEpB,KAAK,CAAC,OAAO,CAAC,CAAA;QAFP,SAAI,GAAJ,IAAI,CAAS;QAGpB,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AARD,sCAQC;AAEM,MAAM,IAAI,GAAG,GAAkB,EAAE,CAAC,IAAI,aAAa,CAAC,gCAAgC,EAAE,IAAI,CAAC,CAAA;AAArF,QAAA,IAAI,QAAiF;AAE3F,MAAM,YAAY,GAAG,GAAkB,EAAE,CAAC,IAAI,aAAa,CAAC,0EAA0E,EAAE,IAAI,CAAC,CAAA;AAAvI,QAAA,YAAY,gBAA2H;AAE7I,MAAM,iBAAiB,GAAG,GAAkB,EAAE,CAAC,IAAI,aAAa,CAAC,qDAAqD,EAAE,IAAI,CAAC,CAAA;AAAvH,QAAA,iBAAiB,qBAAsG;AAE7H,MAAM,YAAY,GAAG,GAAkB,EAAE,CAAC,IAAI,aAAa,CAAC,+CAA+C,EAAE,IAAI,CAAC,CAAA;AAA5G,QAAA,YAAY,gBAAgG;AAElH,MAAM,iBAAiB,GAAG,GAAkB,EAAE,CAAC,IAAI,aAAa,CAAC,uDAAuD,EAAE,IAAI,CAAC,CAAA;AAAzH,QAAA,iBAAiB,qBAAwG;AAE/H,MAAM,mBAAmB,GAAG,GAAkB,EAAE,CACrD,IAAI,aAAa,CAAC,oFAAoF,EAAE,IAAI,CAAC,CAAA;AADlG,QAAA,mBAAmB,uBAC+E"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { TransactionRequest } from '@ethersproject/abstract-provider';
|
|
2
|
+
import { ethers, Signer } from 'ethers';
|
|
3
|
+
import { ErrorWithCode } from './errors';
|
|
4
|
+
import { EventEmitter } from './event-emitter';
|
|
5
|
+
import { ChainConnection, IWeb3Provider, PendingRequest, Web3Method, Web3ProviderConfig } from './types';
|
|
6
|
+
export declare class EthersHeadlessProvider extends EventEmitter implements IWeb3Provider {
|
|
7
|
+
private readonly chains;
|
|
8
|
+
private _pendingRequests;
|
|
9
|
+
private _signers;
|
|
10
|
+
private _activeChainId;
|
|
11
|
+
private _rpc;
|
|
12
|
+
private _config;
|
|
13
|
+
private _authorizedRequests;
|
|
14
|
+
constructor(signers: Signer[], chains: ChainConnection[], config?: Web3ProviderConfig);
|
|
15
|
+
request(args: {
|
|
16
|
+
method: 'eth_call';
|
|
17
|
+
params: any[];
|
|
18
|
+
}): Promise<any>;
|
|
19
|
+
request(args: {
|
|
20
|
+
method: 'eth_getBalance';
|
|
21
|
+
params: string[];
|
|
22
|
+
}): Promise<string>;
|
|
23
|
+
request(args: {
|
|
24
|
+
method: 'eth_accounts';
|
|
25
|
+
params: [];
|
|
26
|
+
}): Promise<string[]>;
|
|
27
|
+
request(args: {
|
|
28
|
+
method: 'eth_requestAccounts';
|
|
29
|
+
params: string[];
|
|
30
|
+
}): Promise<string[]>;
|
|
31
|
+
request(args: {
|
|
32
|
+
method: 'net_version';
|
|
33
|
+
params: [];
|
|
34
|
+
}): Promise<number>;
|
|
35
|
+
request(args: {
|
|
36
|
+
method: 'eth_chainId';
|
|
37
|
+
params: [];
|
|
38
|
+
}): Promise<string>;
|
|
39
|
+
request(args: {
|
|
40
|
+
method: 'personal_sign';
|
|
41
|
+
params: string[];
|
|
42
|
+
}): Promise<string>;
|
|
43
|
+
request(args: {
|
|
44
|
+
method: 'eth_signTypedData' | 'eth_signTypedData_v1';
|
|
45
|
+
params: [object[], string];
|
|
46
|
+
}): Promise<string>;
|
|
47
|
+
request(args: {
|
|
48
|
+
method: 'eth_signTypedData_v3' | 'eth_signTypedData_v4';
|
|
49
|
+
params: string[];
|
|
50
|
+
}): Promise<string>;
|
|
51
|
+
request(args: {
|
|
52
|
+
method: 'eth_sendTransaction';
|
|
53
|
+
params: TransactionRequest[];
|
|
54
|
+
}): Promise<string>;
|
|
55
|
+
getCurrentWallet(): Signer;
|
|
56
|
+
waitAuthorization<T>(requestInfo: PendingRequest['requestInfo'], task: () => Promise<T>, permanentPermission?: boolean, methodOverride?: string): Promise<unknown>;
|
|
57
|
+
private consumeRequest;
|
|
58
|
+
private consumeAllRequests;
|
|
59
|
+
getPendingRequests(): PendingRequest['requestInfo'][];
|
|
60
|
+
getPendingRequestCount(requestKind?: Web3Method): number;
|
|
61
|
+
authorize(requestKind: Web3Method): Promise<void>;
|
|
62
|
+
reject(requestKind: Web3Method, reason?: ErrorWithCode): Promise<void>;
|
|
63
|
+
authorizeAll(): void;
|
|
64
|
+
rejectAll(reason?: ErrorWithCode): void;
|
|
65
|
+
changeAccounts(signers: Signer[]): Promise<void>;
|
|
66
|
+
private getCurrentChain;
|
|
67
|
+
getRpc(): ethers.providers.JsonRpcProvider;
|
|
68
|
+
getNetwork(): ChainConnection;
|
|
69
|
+
getNetworks(): ChainConnection[];
|
|
70
|
+
addNetwork(chainId: number, rpcUrl: string): void;
|
|
71
|
+
switchNetwork(chainId: number): void;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=ethers-headless-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ethers-headless-provider.d.ts","sourceRoot":"","sources":["../src/ethers-headless-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAIrE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AAI/C,OAAO,EAAsB,aAAa,EAAqC,MAAM,UAAU,CAAA;AAE/F,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,kBAAkB,EAAW,MAAM,SAAS,CAAA;AAEjH,qBAAa,sBAAuB,SAAQ,YAAa,YAAW,aAAa;IAU7E,OAAO,CAAC,QAAQ,CAAC,MAAM;IATzB,OAAO,CAAC,gBAAgB,CAA4C;IACpE,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,cAAc,CAAQ;IAC9B,OAAO,CAAC,IAAI,CAAuD;IACnE,OAAO,CAAC,OAAO,CAAgD;IAC/D,OAAO,CAAC,mBAAmB,CAA+C;gBAGxE,OAAO,EAAE,MAAM,EAAE,EACA,MAAM,EAAE,eAAe,EAAE,EAE1C,MAAM,GAAE,kBAAuB;IAQjC,OAAO,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,UAAU,CAAC;QAAC,MAAM,EAAE,GAAG,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAClE,OAAO,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,gBAAgB,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9E,OAAO,CAAC,I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AAC,CAAC,CAAC,EAAE,mBAAmB,UAAQ,EAAE,cAAc,CAAC,EAAE,MAAM;IA0B7I,OAAO,CAAC,cAAc;IAetB,OAAO,CAAC,kBAAkB;IAM1B,kBAAkB,IAAI,cAAc,CAAC,aAAa,CAAC,EAAE;IAIrD,sBAAsB,CAAC,WAAW,CAAC,EAAE,UAAU,GAAG,MAAM;IASlD,SAAS,CAAC,WAAW,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjD,MAAM,CAAC,WAAW,EAAE,UAAU,EAAE,MAAM,GAAE,aAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKpF,YAAY,IAAI,IAAI;IAIpB,SAAS,CAAC,MAAM,GAAE,aAAsB,GAAG,IAAI;IAIzC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtD,OAAO,CAAC,eAAe;IAQhB,MAAM,IAAI,MAAM,CAAC,SAAS,CAAC,eAAe;IAYjD,UAAU,IAAI,eAAe;IAI7B,WAAW,IAAI,eAAe,EAAE;IAIhC,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAIjD,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAUrC"}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.EthersHeadlessProvider = void 0;
|
|
27
|
+
const strings_1 = require("@ethersproject/strings");
|
|
28
|
+
const eth_sig_util_1 = require("@metamask/eth-sig-util");
|
|
29
|
+
const strict_1 = __importDefault(require("assert/strict"));
|
|
30
|
+
const ethers_1 = require("ethers");
|
|
31
|
+
// import {hashMessage} from "ethers/lib/utils";
|
|
32
|
+
const rxjs_1 = require("rxjs");
|
|
33
|
+
const errors_1 = require("./errors");
|
|
34
|
+
const event_emitter_1 = require("./event-emitter");
|
|
35
|
+
const types_1 = require("./types");
|
|
36
|
+
class EthersHeadlessProvider extends event_emitter_1.EventEmitter {
|
|
37
|
+
constructor(signers, chains,
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
config = {}) {
|
|
40
|
+
super();
|
|
41
|
+
this.chains = chains;
|
|
42
|
+
this._pendingRequests = new rxjs_1.BehaviorSubject([]);
|
|
43
|
+
this._signers = [];
|
|
44
|
+
this._rpc = {};
|
|
45
|
+
this._authorizedRequests = {};
|
|
46
|
+
this._signers = signers;
|
|
47
|
+
this._activeChainId = chains[0].chainId;
|
|
48
|
+
this._config = Object.assign({ debug: true, logger: console.log }, config);
|
|
49
|
+
}
|
|
50
|
+
request(_a) {
|
|
51
|
+
return __awaiter(this, arguments, void 0, function* ({ method, params }) {
|
|
52
|
+
if (this._config.debug) {
|
|
53
|
+
this._config.logger(JSON.stringify({ method, params }));
|
|
54
|
+
}
|
|
55
|
+
switch (method) {
|
|
56
|
+
case 'eth_call':
|
|
57
|
+
case 'eth_getBalance':
|
|
58
|
+
case 'eth_estimateGas':
|
|
59
|
+
case 'eth_blockNumber':
|
|
60
|
+
case 'eth_getBlockByNumber':
|
|
61
|
+
case 'eth_getTransactionByHash':
|
|
62
|
+
case 'eth_getTransactionReceipt':
|
|
63
|
+
case 'eth_feeHistory':
|
|
64
|
+
return this.getRpc().send(method, params);
|
|
65
|
+
case 'eth_requestAccounts':
|
|
66
|
+
case 'eth_accounts':
|
|
67
|
+
return this.waitAuthorization({ method, params }, () => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const { chainId } = this.getCurrentChain();
|
|
69
|
+
this.emit('connect', { chainId });
|
|
70
|
+
return Promise.all(this._signers.map((wallet) => wallet.getAddress()));
|
|
71
|
+
}), true, 'eth_requestAccounts');
|
|
72
|
+
case 'eth_chainId': {
|
|
73
|
+
const { chainId } = this.getCurrentChain();
|
|
74
|
+
return '0x' + chainId.toString(16);
|
|
75
|
+
}
|
|
76
|
+
case 'net_version': {
|
|
77
|
+
const { chainId } = this.getCurrentChain();
|
|
78
|
+
return '' + chainId;
|
|
79
|
+
}
|
|
80
|
+
case 'eth_sendTransaction': {
|
|
81
|
+
return this.waitAuthorization({ method, params }, () => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const wallet = this.getCurrentWallet();
|
|
83
|
+
const rpc = this.getRpc();
|
|
84
|
+
const _a = params[0], { gas, from } = _a, txRequest = __rest(_a, ["gas", "from"]);
|
|
85
|
+
const tx = yield wallet.connect(rpc).sendTransaction(txRequest);
|
|
86
|
+
return tx.hash;
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
case 'eth_sign': {
|
|
90
|
+
return this.waitAuthorization({ method, params }, () => __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const wallet = this.getCurrentWallet();
|
|
92
|
+
const rpc = this.getRpc();
|
|
93
|
+
const message = params[1];
|
|
94
|
+
return yield wallet.connect(rpc).signMessage(message);
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
case 'wallet_addEthereumChain': {
|
|
98
|
+
return this.waitAuthorization({ method, params }, () => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const chainId = Number(params[0].chainId);
|
|
100
|
+
const { rpcUrl } = params[0];
|
|
101
|
+
this.addNetwork(chainId, rpcUrl);
|
|
102
|
+
return null;
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
case 'wallet_switchEthereumChain': {
|
|
106
|
+
if (this._activeChainId === Number(params[0].chainId)) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
return this.waitAuthorization({ method, params }, () => __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
const chainId = Number(params[0].chainId);
|
|
111
|
+
this.switchNetwork(chainId);
|
|
112
|
+
return null;
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
case 'personal_sign': {
|
|
116
|
+
return this.waitAuthorization({ method, params }, () => __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const wallet = this.getCurrentWallet();
|
|
118
|
+
const address = yield wallet.getAddress();
|
|
119
|
+
strict_1.default.equal(address, ethers_1.ethers.utils.getAddress(params[1]));
|
|
120
|
+
const message = (0, strings_1.toUtf8String)(params[0]);
|
|
121
|
+
const signature = yield wallet.signMessage(message);
|
|
122
|
+
if (this._config.debug) {
|
|
123
|
+
this._config.logger('personal_sign', {
|
|
124
|
+
message,
|
|
125
|
+
signature,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return signature;
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
case 'eth_signTypedData':
|
|
132
|
+
case 'eth_signTypedData_v1': {
|
|
133
|
+
return this.waitAuthorization({ method, params }, () => __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
const wallet = this.getCurrentWallet();
|
|
135
|
+
const address = yield wallet.getAddress();
|
|
136
|
+
strict_1.default.equal(address, ethers_1.ethers.utils.getAddress(params[1]));
|
|
137
|
+
const msgParams = params[0];
|
|
138
|
+
return (0, eth_sig_util_1.signTypedData)({
|
|
139
|
+
privateKey: Buffer.from(wallet.privateKey.slice(2), 'hex'),
|
|
140
|
+
data: msgParams,
|
|
141
|
+
version: eth_sig_util_1.SignTypedDataVersion.V1,
|
|
142
|
+
});
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
case 'eth_signTypedData_v3':
|
|
146
|
+
case 'eth_signTypedData_v4': {
|
|
147
|
+
return this.waitAuthorization({ method, params }, () => __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
const wallet = this.getCurrentWallet();
|
|
149
|
+
const address = yield wallet.getAddress();
|
|
150
|
+
strict_1.default.equal(address, ethers_1.ethers.utils.getAddress(params[0]));
|
|
151
|
+
const msgParams = JSON.parse(params[1]);
|
|
152
|
+
return (0, eth_sig_util_1.signTypedData)({
|
|
153
|
+
privateKey: Buffer.from(wallet.privateKey.slice(2), 'hex'),
|
|
154
|
+
data: msgParams,
|
|
155
|
+
version: method === 'eth_signTypedData_v4' ? eth_sig_util_1.SignTypedDataVersion.V4 : eth_sig_util_1.SignTypedDataVersion.V3,
|
|
156
|
+
});
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
default:
|
|
160
|
+
return this.getRpc().send(method, params);
|
|
161
|
+
// throw UnsupportedMethod()
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
getCurrentWallet() {
|
|
166
|
+
const wallet = this._signers[0];
|
|
167
|
+
if (!wallet) {
|
|
168
|
+
throw (0, errors_1.Unauthorized)();
|
|
169
|
+
}
|
|
170
|
+
return wallet;
|
|
171
|
+
}
|
|
172
|
+
waitAuthorization(requestInfo, task, permanentPermission = false, methodOverride) {
|
|
173
|
+
const method = methodOverride !== null && methodOverride !== void 0 ? methodOverride : requestInfo.method;
|
|
174
|
+
if (this._authorizedRequests[method]) {
|
|
175
|
+
return task();
|
|
176
|
+
}
|
|
177
|
+
return new Promise((resolve, reject) => {
|
|
178
|
+
const pendingRequest = {
|
|
179
|
+
requestInfo,
|
|
180
|
+
authorize: () => __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
if (permanentPermission) {
|
|
182
|
+
this._authorizedRequests[method] = true;
|
|
183
|
+
}
|
|
184
|
+
resolve(yield task());
|
|
185
|
+
}),
|
|
186
|
+
reject(err) {
|
|
187
|
+
reject(err);
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
this._pendingRequests.next(this._pendingRequests.getValue().concat(pendingRequest));
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
consumeRequest(requestKind) {
|
|
194
|
+
return (0, rxjs_1.firstValueFrom)(this._pendingRequests.pipe((0, rxjs_1.switchMap)((a) => (0, rxjs_1.from)(a)), (0, rxjs_1.filter)((request) => {
|
|
195
|
+
return request.requestInfo.method === requestKind;
|
|
196
|
+
}), (0, rxjs_1.first)(), (0, rxjs_1.tap)((item) => {
|
|
197
|
+
this._pendingRequests.next((0, types_1.without)(this._pendingRequests.getValue(), item));
|
|
198
|
+
})));
|
|
199
|
+
}
|
|
200
|
+
consumeAllRequests() {
|
|
201
|
+
const pendingRequests = this._pendingRequests.getValue();
|
|
202
|
+
this._pendingRequests.next([]);
|
|
203
|
+
return pendingRequests;
|
|
204
|
+
}
|
|
205
|
+
getPendingRequests() {
|
|
206
|
+
return this._pendingRequests.getValue().map((pendingRequest) => pendingRequest.requestInfo);
|
|
207
|
+
}
|
|
208
|
+
getPendingRequestCount(requestKind) {
|
|
209
|
+
const pendingRequests = this._pendingRequests.getValue();
|
|
210
|
+
if (!requestKind) {
|
|
211
|
+
return pendingRequests.length;
|
|
212
|
+
}
|
|
213
|
+
return pendingRequests.filter((pendingRequest) => pendingRequest.requestInfo.method === requestKind).length;
|
|
214
|
+
}
|
|
215
|
+
authorize(requestKind) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
const pendingRequest = yield this.consumeRequest(requestKind);
|
|
218
|
+
return pendingRequest.authorize();
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
reject(requestKind_1) {
|
|
222
|
+
return __awaiter(this, arguments, void 0, function* (requestKind, reason = (0, errors_1.Deny)()) {
|
|
223
|
+
const pendingRequest = yield this.consumeRequest(requestKind);
|
|
224
|
+
return pendingRequest.reject(reason);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
authorizeAll() {
|
|
228
|
+
this.consumeAllRequests().forEach((request) => request.authorize());
|
|
229
|
+
}
|
|
230
|
+
rejectAll(reason = (0, errors_1.Deny)()) {
|
|
231
|
+
this.consumeAllRequests().forEach((request) => request.reject(reason));
|
|
232
|
+
}
|
|
233
|
+
changeAccounts(signers) {
|
|
234
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
this._signers = signers;
|
|
236
|
+
this.emit('accountsChanged', yield Promise.all(this._signers.map((signer) => signer.getAddress())));
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
getCurrentChain() {
|
|
240
|
+
const chainConn = this.chains.find((chainConn) => chainConn.chainId === this._activeChainId);
|
|
241
|
+
if (!chainConn) {
|
|
242
|
+
throw (0, errors_1.Disconnected)();
|
|
243
|
+
}
|
|
244
|
+
return chainConn;
|
|
245
|
+
}
|
|
246
|
+
getRpc() {
|
|
247
|
+
const chainConn = this.getCurrentChain();
|
|
248
|
+
let rpc = this._rpc[chainConn.chainId];
|
|
249
|
+
if (!rpc) {
|
|
250
|
+
rpc = new ethers_1.ethers.providers.JsonRpcProvider(chainConn.rpcUrl, chainConn.chainId);
|
|
251
|
+
this._rpc[chainConn.chainId] = rpc;
|
|
252
|
+
}
|
|
253
|
+
return rpc;
|
|
254
|
+
}
|
|
255
|
+
getNetwork() {
|
|
256
|
+
return this.getCurrentChain();
|
|
257
|
+
}
|
|
258
|
+
getNetworks() {
|
|
259
|
+
return this.chains;
|
|
260
|
+
}
|
|
261
|
+
addNetwork(chainId, rpcUrl) {
|
|
262
|
+
this.chains.push({ chainId, rpcUrl });
|
|
263
|
+
}
|
|
264
|
+
switchNetwork(chainId) {
|
|
265
|
+
const idx = this.chains.findIndex((connection) => connection.chainId === chainId);
|
|
266
|
+
if (idx < 0) {
|
|
267
|
+
throw (0, errors_1.UnrecognizedChainID)();
|
|
268
|
+
}
|
|
269
|
+
if (chainId !== this._activeChainId) {
|
|
270
|
+
this._activeChainId = chainId;
|
|
271
|
+
this.emit('chainChanged', chainId);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.EthersHeadlessProvider = EthersHeadlessProvider;
|
|
276
|
+
//# sourceMappingURL=ethers-headless-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ethers-headless-provider.js","sourceRoot":"","sources":["../src/ethers-headless-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAAqD;AACrD,yDAA4E;AAC5E,2DAAkC;AAClC,mCAA+C;AAC/C,gDAAgD;AAChD,+BAA2F;AAE3F,qCAA+F;AAE/F,mDAA8C;AAC9C,mCAAiH;AAEjH,MAAa,sBAAuB,SAAQ,4BAAY;IAQtD,YACE,OAAiB,EACA,MAAyB;IAC1C,aAAa;IACb,SAA6B,EAAE;QAE/B,KAAK,EAAE,CAAA;QAJU,WAAM,GAAN,MAAM,CAAmB;QATpC,qBAAgB,GAAG,IAAI,sBAAe,CAAmB,EAAE,CAAC,CAAA;QAC5D,aAAQ,GAAa,EAAE,CAAA;QAEvB,SAAI,GAAqD,EAAE,CAAA;QAE3D,wBAAmB,GAA6C,EAAE,CAAA;QASxE,IA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AAG,CAAA;IACZ,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,eAAe,EAAE,CAAA;IAC/B,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,UAAU,CAAC,OAAe,EAAE,MAAc;QACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;IACvC,CAAC;IAED,aAAa,CAAC,OAAe;QAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;QACjF,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;YACZ,MAAM,IAAA,4BAAmB,GAAE,CAAA;QAC7B,CAAC;QACD,IAAI,OAAO,KAAK,IAAI,CAAC,cAAc,EAAE,CAAC;YACpC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAA;YAC7B,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;QACpC,CAAC;IACH,CAAC;CACF;AAlTD,wDAkTC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Provider, TransactionRequest } from '@ethersproject/abstract-provider';
|
|
2
|
+
import { Deferrable } from '@ethersproject/properties';
|
|
3
|
+
import { IKey } from '@veramo/core';
|
|
4
|
+
import { ethers, Signer, TypedDataDomain, TypedDataField } from 'ethers';
|
|
5
|
+
import { IRequiredContext, TypedDataSigner } from './types';
|
|
6
|
+
export declare class EthersKMSSignerBuilder {
|
|
7
|
+
private context?;
|
|
8
|
+
private keyRef?;
|
|
9
|
+
private provider?;
|
|
10
|
+
withContext(context: IRequiredContext): this;
|
|
11
|
+
withKid(kid: string): this;
|
|
12
|
+
withKeyRef(keyRef: Pick<IKey, 'kid'> | string): this;
|
|
13
|
+
withProvider(provider: ethers.providers.Provider): this;
|
|
14
|
+
build(): EthersKMSSigner;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* This is a Ethers signer that delegates back to the KMS for the actual signatures.
|
|
18
|
+
* This means we do not expose private keys and can use any Secp256k1 key stored in the KMS if we want
|
|
19
|
+
*
|
|
20
|
+
* Be aware that the provided KeyRef needs to belong to the respective KMS, as it will use a lookup for the key in the KMS to sign
|
|
21
|
+
*/
|
|
22
|
+
export declare class EthersKMSSigner extends Signer implements TypedDataSigner {
|
|
23
|
+
private readonly context;
|
|
24
|
+
private readonly keyRef;
|
|
25
|
+
constructor({ provider, context, keyRef }: {
|
|
26
|
+
provider?: ethers.providers.Provider;
|
|
27
|
+
context: IRequiredContext;
|
|
28
|
+
keyRef: Pick<IKey, 'kid'>;
|
|
29
|
+
});
|
|
30
|
+
getAddress(): Promise<string>;
|
|
31
|
+
signTransaction(transaction: Deferrable<TransactionRequest>): Promise<string>;
|
|
32
|
+
signRaw(message: string | Uint8Array): Promise<string>;
|
|
33
|
+
signMessage(message: string | Uint8Array): Promise<string>;
|
|
34
|
+
_signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
|
|
35
|
+
connect(provider?: Provider): EthersKMSSigner;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=ethers-kms-signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ethers-kms-signer.d.ts","sourceRoot":"","sources":["../src/ethers-kms-signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAEtD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAMxE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,S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AAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAcxI,OAAO,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,eAAe;CAG9C"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
35
|
+
var t = {};
|
|
36
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
37
|
+
t[p] = s[p];
|
|
38
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
39
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
40
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
41
|
+
t[p[i]] = s[p[i]];
|
|
42
|
+
}
|
|
43
|
+
return t;
|
|
44
|
+
};
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.EthersKMSSigner = exports.EthersKMSSignerBuilder = void 0;
|
|
47
|
+
const transactions_1 = require("@ethersproject/transactions");
|
|
48
|
+
const ethers_1 = require("ethers");
|
|
49
|
+
// import {arrayify, defineReadOnly, serializeTransaction} from 'ethers/lib/utils'
|
|
50
|
+
const utils_1 = require("ethers/lib/utils");
|
|
51
|
+
const u8a = __importStar(require("uint8arrays"));
|
|
52
|
+
// import {ECDSASignature} from "web3-eth-accounts";
|
|
53
|
+
const functions_1 = require("./functions");
|
|
54
|
+
class EthersKMSSignerBuilder {
|
|
55
|
+
withContext(context) {
|
|
56
|
+
this.context = context;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
withKid(kid) {
|
|
60
|
+
this.keyRef = { kid };
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
withKeyRef(keyRef) {
|
|
64
|
+
if (typeof keyRef === 'string') {
|
|
65
|
+
return this.withKid(keyRef);
|
|
66
|
+
}
|
|
67
|
+
this.keyRef = keyRef;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
withProvider(provider) {
|
|
71
|
+
this.provider = provider;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
build() {
|
|
75
|
+
if (!this.context) {
|
|
76
|
+
throw Error('Agent context needs to be provided');
|
|
77
|
+
}
|
|
78
|
+
if (!this.keyRef) {
|
|
79
|
+
throw Error('Keyref needs to be provided');
|
|
80
|
+
}
|
|
81
|
+
return new EthersKMSSigner({ context: this.context, keyRef: this.keyRef, provider: this.provider });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.EthersKMSSignerBuilder = EthersKMSSignerBuilder;
|
|
85
|
+
/**
|
|
86
|
+
* This is a Ethers signer that delegates back to the KMS for the actual signatures.
|
|
87
|
+
* This means we do not expose private keys and can use any Secp256k1 key stored in the KMS if we want
|
|
88
|
+
*
|
|
89
|
+
* Be aware that the provided KeyRef needs to belong to the respective KMS, as it will use a lookup for the key in the KMS to sign
|
|
90
|
+
*/
|
|
91
|
+
class EthersKMSSigner extends ethers_1.Signer {
|
|
92
|
+
constructor({ provider, context, keyRef }) {
|
|
93
|
+
super();
|
|
94
|
+
// defineReadOnly(this, "address", address);
|
|
95
|
+
(0, utils_1.defineReadOnly)(this, 'provider', provider || undefined);
|
|
96
|
+
this.context = context;
|
|
97
|
+
this.keyRef = keyRef;
|
|
98
|
+
}
|
|
99
|
+
getAddress() {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
return yield (0, functions_1.getAddressFromAgent)(this.context, this.keyRef);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
signTransaction(transaction) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
const _a = yield transaction, { from } = _a, tx = __rest(_a, ["from"]);
|
|
107
|
+
return this.context.agent.keyManagerSign({
|
|
108
|
+
algorithm: 'eth_signTransaction',
|
|
109
|
+
keyRef: this.keyRef.kid,
|
|
110
|
+
// keyRef: this.keyRef,
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
data: (0, utils_1.arrayify)((0, transactions_1.serialize)(tx)),
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
signRaw(message) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
return yield this.context.agent.keyManagerSign({
|
|
119
|
+
algorithm: 'eth_rawSign',
|
|
120
|
+
keyRef: this.keyRef.kid,
|
|
121
|
+
encoding: 'base16',
|
|
122
|
+
// @ts-ignore // KMS accepts uint8arrays but interface does not expose it
|
|
123
|
+
data: message,
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
signMessage(message) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
return yield this.context.agent.keyManagerSign({
|
|
130
|
+
algorithm: 'eth_signMessage',
|
|
131
|
+
keyRef: this.keyRef.kid,
|
|
132
|
+
encoding: 'base16',
|
|
133
|
+
// @ts-ignore // KMS accepts uint8arrays but interface does not expose it
|
|
134
|
+
data: message,
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
_signTypedData(domain, types, value) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
const jsonData = {
|
|
141
|
+
domain,
|
|
142
|
+
types,
|
|
143
|
+
message: value,
|
|
144
|
+
};
|
|
145
|
+
return this.context.agent.keyManagerSign({
|
|
146
|
+
algorithm: 'eth_signTypedData',
|
|
147
|
+
keyRef: this.keyRef.kid,
|
|
148
|
+
// @ts-ignore // KMS accepts uint8arrays but interface does not expose it
|
|
149
|
+
data: u8a.fromString(JSON.stringify(jsonData)),
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
connect(provider) {
|
|
154
|
+
return new EthersKMSSigner({ provider, context: this.context, keyRef: this.keyRef });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.EthersKMSSigner = EthersKMSSigner;
|
|
158
|
+
/*
|
|
159
|
+
/!**
|
|
160
|
+
* Convert signature format of the `eth_sign` RPC method to signature parameters
|
|
161
|
+
* NOTE: all because of a bug in geth: https://github.com/ethereum/go-ethereum/issues/2053
|
|
162
|
+
*!/
|
|
163
|
+
export const fromRpcSig = function(sig: string): ECDSASignature {
|
|
164
|
+
const buf: Buffer = toBuffer(sig)
|
|
165
|
+
|
|
166
|
+
if (buf.length < 65) {
|
|
167
|
+
throw new Error('Invalid signature length')
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
let v = bufferToInt(buf.slice(64))
|
|
171
|
+
// support both versions of `eth_sign` responses
|
|
172
|
+
if (v < 27) {
|
|
173
|
+
v += 27
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
v: v,
|
|
178
|
+
r: buf.slice(0, 32),
|
|
179
|
+
s: buf.slice(32, 64)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
*/
|
|
183
|
+
//# sourceMappingURL=ethers-kms-signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ethers-kms-signer.js","sourceRoot":"","sources":["../src/ethers-kms-signer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,8DAAuD;AAGvD,mCAAwE;AACxE,kFAAkF;AAClF,4CAA+E;AAC/E,iDAAkC;AAClC,oDAAoD;AACpD,2CAAiD;AAGjD,MAAa,sBAAsB;IAKjC,WAAW,CAAC,OAAyB;QACnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,CAAC,GAAW;QACjB,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,EAAE,CAAA;QACrB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,UAAU,CAAC,MAAkC;QAC3C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,OA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