@portal-hq/web 0.0.1-beta-1 → 0.0.1-beta1

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.
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const utils_1 = require("@portal-hq/utils");
13
- const WEB_SDK_VERSION = '0.0.1-beta-1';
13
+ const WEB_SDK_VERSION = '0.0.1-beta1';
14
14
  class Mpc {
15
15
  constructor({ apiKey, chainId, portal, rpcUrl,
16
16
  // Optional
@@ -0,0 +1,57 @@
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
+ class Signer {
13
+ constructor({ portal }) {
14
+ this.portal = portal;
15
+ }
16
+ sign(message) {
17
+ var _a, _b;
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const address = yield ((_a = this.portal.mpc) === null || _a === void 0 ? void 0 : _a.getAddress());
20
+ const { method, params } = message;
21
+ switch (method) {
22
+ case 'eth_requestAccounts':
23
+ return [address];
24
+ case 'eth_accounts':
25
+ return [address];
26
+ default:
27
+ break;
28
+ }
29
+ const result = yield ((_b = this.portal.mpc) === null || _b === void 0 ? void 0 : _b.sign({
30
+ host: this.portal.mpcHost,
31
+ method,
32
+ params: this.buildParams(method, params),
33
+ mpcVersion: this.portal.mpcVersion,
34
+ }));
35
+ return result;
36
+ });
37
+ }
38
+ buildParams(method, txParams) {
39
+ let params = txParams;
40
+ switch (method) {
41
+ case 'eth_sign':
42
+ case 'personal_sign':
43
+ case 'eth_signTypedData_v3':
44
+ case 'eth_signTypedData_v4':
45
+ if (!Array.isArray(txParams)) {
46
+ params = [txParams];
47
+ }
48
+ break;
49
+ default:
50
+ if (Array.isArray(txParams)) {
51
+ params = txParams[0];
52
+ }
53
+ }
54
+ return params;
55
+ }
56
+ }
57
+ exports.default = Signer;
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { PortalMpcError } from '@portal-hq/utils';
11
- const WEB_SDK_VERSION = '0.0.1-beta-1';
11
+ const WEB_SDK_VERSION = '0.0.1-beta1';
12
12
  class Mpc {
13
13
  constructor({ apiKey, chainId, portal, rpcUrl,
14
14
  // Optional
@@ -0,0 +1,55 @@
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
+ class Signer {
11
+ constructor({ portal }) {
12
+ this.portal = portal;
13
+ }
14
+ sign(message) {
15
+ var _a, _b;
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const address = yield ((_a = this.portal.mpc) === null || _a === void 0 ? void 0 : _a.getAddress());
18
+ const { method, params } = message;
19
+ switch (method) {
20
+ case 'eth_requestAccounts':
21
+ return [address];
22
+ case 'eth_accounts':
23
+ return [address];
24
+ default:
25
+ break;
26
+ }
27
+ const result = yield ((_b = this.portal.mpc) === null || _b === void 0 ? void 0 : _b.sign({
28
+ host: this.portal.mpcHost,
29
+ method,
30
+ params: this.buildParams(method, params),
31
+ mpcVersion: this.portal.mpcVersion,
32
+ }));
33
+ return result;
34
+ });
35
+ }
36
+ buildParams(method, txParams) {
37
+ let params = txParams;
38
+ switch (method) {
39
+ case 'eth_sign':
40
+ case 'personal_sign':
41
+ case 'eth_signTypedData_v3':
42
+ case 'eth_signTypedData_v4':
43
+ if (!Array.isArray(txParams)) {
44
+ params = [txParams];
45
+ }
46
+ break;
47
+ default:
48
+ if (Array.isArray(txParams)) {
49
+ params = txParams[0];
50
+ }
51
+ }
52
+ return params;
53
+ }
54
+ }
55
+ export default Signer;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Portal MPC Support for Web",
4
4
  "author": "Portal Labs, Inc.",
5
5
  "homepage": "https://portalhq.io/",
6
- "version": "0.0.1-beta-1",
6
+ "version": "0.0.1-beta1",
7
7
  "license": "MIT",
8
8
  "main": "lib/commonjs/index",
9
9
  "module": "lib/esm/index",
@@ -18,9 +18,10 @@
18
18
  "scripts": {
19
19
  "bundle": "sh ./scripts/version-iframe.sh && webpack && sh ./scripts/copy-static-files.sh && git stash",
20
20
  "coverage": "jest --collect-coverage",
21
- "prepare": "sh ./scripts/version-mpc.sh && yarn prepare:cjs && yarn prepare:esm && rm -rf lib/esm/iframe && rm -rf lib/commonjs/iframe",
21
+ "prepare": "sh ./scripts/version-mpc.sh && yarn prepare:cjs && yarn prepare:esm && rm -rf lib/esm/iframe && rm -rf lib/commonjs/iframe && git stash push -- src/mpc/index.ts",
22
22
  "prepare:cjs": "tsc --outDir lib/commonjs --module commonjs",
23
23
  "prepare:esm": "tsc --outDir lib/esm --module es2015 --target es2015",
24
+ "prerelease": "yarn bundle && sh ./scripts/write-to-gcp-bucket.sh",
24
25
  "test": "jest"
25
26
  },
26
27
  "dependencies": {
package/src/mpc/index.ts CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  WorkerResult,
17
17
  } from '../../types'
18
18
 
19
- const WEB_SDK_VERSION = '0.0.1-beta-1'
19
+ const WEB_SDK_VERSION = '<WEB_SDK_VERSION>'
20
20
 
21
21
  class Mpc {
22
22
  private apiHost: string