@portal-hq/provider 1.1.0 → 1.1.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/lib/commonjs/providers/index.js +6 -1
- package/lib/esm/providers/index.js +6 -1
- package/package.json +4 -4
- package/src/providers/index.ts +8 -1
- package/lib/commonjs/requesters/http.js +0 -52
- package/lib/commonjs/requesters/index.js +0 -8
- package/lib/commonjs/signers/http.js +0 -56
- package/lib/esm/requesters/http.js +0 -50
- package/lib/esm/requesters/index.js +0 -1
- package/lib/esm/signers/http.js +0 -54
|
@@ -237,7 +237,7 @@ class Provider {
|
|
|
237
237
|
* @param chainId The numerical ID of the chain to switch to
|
|
238
238
|
* @returns BaseProvider
|
|
239
239
|
*/
|
|
240
|
-
setChainId(chainId) {
|
|
240
|
+
setChainId(chainId, connect) {
|
|
241
241
|
return __awaiter(this, void 0, void 0, function* () {
|
|
242
242
|
// Update the chainId
|
|
243
243
|
this.chainId = chainId;
|
|
@@ -249,6 +249,11 @@ class Provider {
|
|
|
249
249
|
this.emit('chainChanged', {
|
|
250
250
|
chainId: this.chainId,
|
|
251
251
|
});
|
|
252
|
+
if (connect) {
|
|
253
|
+
connect.emit('portalConnect_chainChanged', {
|
|
254
|
+
chainId: this.chainId,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
252
257
|
// Dispatch 'connect' event
|
|
253
258
|
this.dispatchConnect();
|
|
254
259
|
return this;
|
|
@@ -235,7 +235,7 @@ class Provider {
|
|
|
235
235
|
* @param chainId The numerical ID of the chain to switch to
|
|
236
236
|
* @returns BaseProvider
|
|
237
237
|
*/
|
|
238
|
-
setChainId(chainId) {
|
|
238
|
+
setChainId(chainId, connect) {
|
|
239
239
|
return __awaiter(this, void 0, void 0, function* () {
|
|
240
240
|
// Update the chainId
|
|
241
241
|
this.chainId = chainId;
|
|
@@ -247,6 +247,11 @@ class Provider {
|
|
|
247
247
|
this.emit('chainChanged', {
|
|
248
248
|
chainId: this.chainId,
|
|
249
249
|
});
|
|
250
|
+
if (connect) {
|
|
251
|
+
connect.emit('portalConnect_chainChanged', {
|
|
252
|
+
chainId: this.chainId,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
250
255
|
// Dispatch 'connect' event
|
|
251
256
|
this.dispatchConnect();
|
|
252
257
|
return this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portal-hq/provider",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/esm/index",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"test": "jest"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@portal-hq/connect": "^1.1.
|
|
23
|
-
"@portal-hq/utils": "^1.1.
|
|
22
|
+
"@portal-hq/connect": "^1.1.1",
|
|
23
|
+
"@portal-hq/utils": "^1.1.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@babel/preset-typescript": "^7.18.6",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"ts-jest": "^29.0.3",
|
|
31
31
|
"typescript": "^4.8.4"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "2ba5caccbaae676a2b207bab294bbd59cfc136ca"
|
|
34
34
|
}
|
package/src/providers/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
type RequestArguments,
|
|
19
19
|
type SwitchEthereumChainParameter,
|
|
20
20
|
} from '../../types'
|
|
21
|
+
import PortalConnect from '@portal-hq/connect'
|
|
21
22
|
|
|
22
23
|
const passiveSignerMethods = [
|
|
23
24
|
'eth_accounts',
|
|
@@ -312,7 +313,7 @@ class Provider {
|
|
|
312
313
|
* @param chainId The numerical ID of the chain to switch to
|
|
313
314
|
* @returns BaseProvider
|
|
314
315
|
*/
|
|
315
|
-
public async setChainId(chainId: number): Promise<Provider> {
|
|
316
|
+
public async setChainId(chainId: number, connect?: PortalConnect): Promise<Provider> {
|
|
316
317
|
// Update the chainId
|
|
317
318
|
this.chainId = chainId
|
|
318
319
|
|
|
@@ -326,6 +327,12 @@ class Provider {
|
|
|
326
327
|
chainId: this.chainId,
|
|
327
328
|
} as SwitchEthereumChainParameter)
|
|
328
329
|
|
|
330
|
+
|
|
331
|
+
if (connect) {
|
|
332
|
+
connect.emit('portalConnect_chainChanged', {
|
|
333
|
+
chainId: this.chainId,
|
|
334
|
+
} as SwitchEthereumChainParameter)
|
|
335
|
+
}
|
|
329
336
|
// Dispatch 'connect' event
|
|
330
337
|
this.dispatchConnect()
|
|
331
338
|
|
|
@@ -1,52 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const utils_1 = require("@portal-hq/utils");
|
|
13
|
-
class HttpRequester {
|
|
14
|
-
constructor({ baseUrl }) {
|
|
15
|
-
this.baseUrl = baseUrl.startsWith('https://')
|
|
16
|
-
? baseUrl
|
|
17
|
-
: `https://${baseUrl}`;
|
|
18
|
-
}
|
|
19
|
-
get(path, options) {
|
|
20
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const requestOptions = {
|
|
22
|
-
method: 'GET',
|
|
23
|
-
url: `${this.baseUrl}${path}`,
|
|
24
|
-
};
|
|
25
|
-
if (options && options.headers) {
|
|
26
|
-
requestOptions.headers = this.buildHeaders(options.headers);
|
|
27
|
-
}
|
|
28
|
-
const request = new utils_1.HttpRequest(requestOptions);
|
|
29
|
-
const response = (yield request.send());
|
|
30
|
-
return response;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
post(path, options) {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const requestOptions = {
|
|
36
|
-
method: 'POST',
|
|
37
|
-
url: `${this.baseUrl}${path}`,
|
|
38
|
-
};
|
|
39
|
-
requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
|
|
40
|
-
if (options && options.body) {
|
|
41
|
-
requestOptions.body = options.body;
|
|
42
|
-
}
|
|
43
|
-
const request = new utils_1.HttpRequest(requestOptions);
|
|
44
|
-
const response = (yield request.send());
|
|
45
|
-
return response;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
buildHeaders(headers) {
|
|
49
|
-
return Object.assign({ 'Content-Type': 'application/json' }, headers);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.default = HttpRequester;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.HttpRequester = void 0;
|
|
7
|
-
var http_1 = require("./http");
|
|
8
|
-
Object.defineProperty(exports, "HttpRequester", { enumerable: true, get: function () { return __importDefault(http_1).default; } });
|
|
@@ -1,56 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const utils_1 = require("@portal-hq/utils");
|
|
13
|
-
class HttpSigner {
|
|
14
|
-
constructor(opts) {
|
|
15
|
-
if (!opts.portal) {
|
|
16
|
-
throw new utils_1.MissingOptionError({
|
|
17
|
-
className: 'HttpSigner',
|
|
18
|
-
option: 'portal',
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
this.keychain = opts.keychain;
|
|
22
|
-
this.portal = opts.portal;
|
|
23
|
-
}
|
|
24
|
-
sign(message, provider) {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const address = yield this.keychain.getAddress();
|
|
27
|
-
const { chainId, method, params } = message;
|
|
28
|
-
switch (method) {
|
|
29
|
-
case 'eth_requestAccounts':
|
|
30
|
-
return [address];
|
|
31
|
-
case 'eth_accounts':
|
|
32
|
-
return [address];
|
|
33
|
-
default:
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
console.log(`[Portal:HttpSigner] Requesting signature from exchange for:`, JSON.stringify({
|
|
37
|
-
chainId,
|
|
38
|
-
method,
|
|
39
|
-
params: JSON.stringify([params]),
|
|
40
|
-
}, null, 2));
|
|
41
|
-
const signatureResponse = yield this.portal.post('/api/v1/clients/transactions/sign', {
|
|
42
|
-
body: {
|
|
43
|
-
chainId,
|
|
44
|
-
method,
|
|
45
|
-
params: JSON.stringify([params]),
|
|
46
|
-
},
|
|
47
|
-
headers: {
|
|
48
|
-
Authorization: `Bearer ${provider.apiKey}`,
|
|
49
|
-
'Content-Type': 'application/json',
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
return signatureResponse;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.default = HttpSigner;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { HttpRequest, } from '@portal-hq/utils';
|
|
11
|
-
class HttpRequester {
|
|
12
|
-
constructor({ baseUrl }) {
|
|
13
|
-
this.baseUrl = baseUrl.startsWith('https://')
|
|
14
|
-
? baseUrl
|
|
15
|
-
: `https://${baseUrl}`;
|
|
16
|
-
}
|
|
17
|
-
get(path, options) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
const requestOptions = {
|
|
20
|
-
method: 'GET',
|
|
21
|
-
url: `${this.baseUrl}${path}`,
|
|
22
|
-
};
|
|
23
|
-
if (options && options.headers) {
|
|
24
|
-
requestOptions.headers = this.buildHeaders(options.headers);
|
|
25
|
-
}
|
|
26
|
-
const request = new HttpRequest(requestOptions);
|
|
27
|
-
const response = (yield request.send());
|
|
28
|
-
return response;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
post(path, options) {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const requestOptions = {
|
|
34
|
-
method: 'POST',
|
|
35
|
-
url: `${this.baseUrl}${path}`,
|
|
36
|
-
};
|
|
37
|
-
requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
|
|
38
|
-
if (options && options.body) {
|
|
39
|
-
requestOptions.body = options.body;
|
|
40
|
-
}
|
|
41
|
-
const request = new HttpRequest(requestOptions);
|
|
42
|
-
const response = (yield request.send());
|
|
43
|
-
return response;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
buildHeaders(headers) {
|
|
47
|
-
return Object.assign({ 'Content-Type': 'application/json' }, headers);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export default HttpRequester;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as HttpRequester } from './http';
|
package/lib/esm/signers/http.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { MissingOptionError, } from '@portal-hq/utils';
|
|
11
|
-
class HttpSigner {
|
|
12
|
-
constructor(opts) {
|
|
13
|
-
if (!opts.portal) {
|
|
14
|
-
throw new MissingOptionError({
|
|
15
|
-
className: 'HttpSigner',
|
|
16
|
-
option: 'portal',
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
this.keychain = opts.keychain;
|
|
20
|
-
this.portal = opts.portal;
|
|
21
|
-
}
|
|
22
|
-
sign(message, provider) {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const address = yield this.keychain.getAddress();
|
|
25
|
-
const { chainId, method, params } = message;
|
|
26
|
-
switch (method) {
|
|
27
|
-
case 'eth_requestAccounts':
|
|
28
|
-
return [address];
|
|
29
|
-
case 'eth_accounts':
|
|
30
|
-
return [address];
|
|
31
|
-
default:
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
console.log(`[Portal:HttpSigner] Requesting signature from exchange for:`, JSON.stringify({
|
|
35
|
-
chainId,
|
|
36
|
-
method,
|
|
37
|
-
params: JSON.stringify([params]),
|
|
38
|
-
}, null, 2));
|
|
39
|
-
const signatureResponse = yield this.portal.post('/api/v1/clients/transactions/sign', {
|
|
40
|
-
body: {
|
|
41
|
-
chainId,
|
|
42
|
-
method,
|
|
43
|
-
params: JSON.stringify([params]),
|
|
44
|
-
},
|
|
45
|
-
headers: {
|
|
46
|
-
Authorization: `Bearer ${provider.apiKey}`,
|
|
47
|
-
'Content-Type': 'application/json',
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
return signatureResponse;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
export default HttpSigner;
|