@getpara/server-sdk 0.1.0
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/cjs/ParaServer.d.ts +4 -0
- package/dist/cjs/ParaServer.js +14 -0
- package/dist/cjs/ServerLocalStorage.d.ts +12 -0
- package/dist/cjs/ServerLocalStorage.js +30 -0
- package/dist/cjs/ServerSessionStorage.d.ts +12 -0
- package/dist/cjs/ServerSessionStorage.js +30 -0
- package/dist/cjs/ServerUtils.d.ts +43 -0
- package/dist/cjs/ServerUtils.js +55 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/wallet/keygen.d.ts +22 -0
- package/dist/cjs/wallet/keygen.js +172 -0
- package/dist/cjs/wallet/privateKey.d.ts +2 -0
- package/dist/cjs/wallet/privateKey.js +62 -0
- package/dist/cjs/wallet/signing.d.ts +5 -0
- package/dist/cjs/wallet/signing.js +133 -0
- package/dist/cjs/wasm/wasm_exec.d.ts +1 -0
- package/dist/cjs/wasm/wasm_exec.js +521 -0
- package/dist/cjs/workers/walletUtils.d.ts +25 -0
- package/dist/cjs/workers/walletUtils.js +247 -0
- package/dist/cjs/workers/worker.d.ts +18 -0
- package/dist/cjs/workers/worker.js +154 -0
- package/dist/cjs/workers/workerWrapper.d.ts +4 -0
- package/dist/cjs/workers/workerWrapper.js +55 -0
- package/dist/esm/ParaServer.d.ts +4 -0
- package/dist/esm/ParaServer.js +7 -0
- package/dist/esm/ServerLocalStorage.d.ts +12 -0
- package/dist/esm/ServerLocalStorage.js +26 -0
- package/dist/esm/ServerSessionStorage.d.ts +12 -0
- package/dist/esm/ServerSessionStorage.js +26 -0
- package/dist/esm/ServerUtils.d.ts +43 -0
- package/dist/esm/ServerUtils.js +51 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/wallet/keygen.d.ts +22 -0
- package/dist/esm/wallet/keygen.js +142 -0
- package/dist/esm/wallet/privateKey.d.ts +2 -0
- package/dist/esm/wallet/privateKey.js +35 -0
- package/dist/esm/wallet/signing.d.ts +5 -0
- package/dist/esm/wallet/signing.js +103 -0
- package/dist/esm/wasm/wasm_exec.d.ts +1 -0
- package/dist/esm/wasm/wasm_exec.js +521 -0
- package/dist/esm/workers/walletUtils.d.ts +25 -0
- package/dist/esm/workers/walletUtils.js +234 -0
- package/dist/esm/workers/worker.d.ts +18 -0
- package/dist/esm/workers/worker.js +124 -0
- package/dist/esm/workers/workerWrapper.d.ts +4 -0
- package/dist/esm/workers/workerWrapper.js +51 -0
- package/dist/types/ParaServer.d.ts +4 -0
- package/dist/types/ServerLocalStorage.d.ts +12 -0
- package/dist/types/ServerSessionStorage.d.ts +12 -0
- package/dist/types/ServerUtils.d.ts +43 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/wallet/keygen.d.ts +22 -0
- package/dist/types/wallet/privateKey.d.ts +2 -0
- package/dist/types/wallet/signing.d.ts +5 -0
- package/dist/types/wasm/wasm_exec.d.ts +1 -0
- package/dist/types/workers/walletUtils.d.ts +25 -0
- package/dist/types/workers/worker.d.ts +18 -0
- package/dist/types/workers/workerWrapper.d.ts +4 -0
- package/package.json +33 -0
|
@@ -0,0 +1,14 @@
|
|
|
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.Para = void 0;
|
|
7
|
+
const core_sdk_1 = __importDefault(require("@getpara/core-sdk"));
|
|
8
|
+
const ServerUtils_js_1 = require("./ServerUtils.js");
|
|
9
|
+
class Para extends core_sdk_1.default {
|
|
10
|
+
getPlatformUtils() {
|
|
11
|
+
return new ServerUtils_js_1.ServerUtils();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.Para = Para;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { StorageUtils } from '@getpara/core-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Implements `StorageUtils`
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare class ServerLocalStorage implements StorageUtils {
|
|
7
|
+
private localStorage;
|
|
8
|
+
get: (key: string) => string | null;
|
|
9
|
+
set: (key: string, value: string) => void;
|
|
10
|
+
removeItem: (key: string) => void;
|
|
11
|
+
clear: (prefix: string) => void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerLocalStorage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Implements `StorageUtils`
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
class ServerLocalStorage {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.localStorage = {};
|
|
11
|
+
this.get = (key) => {
|
|
12
|
+
return this.localStorage[key] || null;
|
|
13
|
+
};
|
|
14
|
+
this.set = (key, value) => {
|
|
15
|
+
this.localStorage[key] = value;
|
|
16
|
+
};
|
|
17
|
+
this.removeItem = (key) => {
|
|
18
|
+
delete this.localStorage[key];
|
|
19
|
+
};
|
|
20
|
+
this.clear = (prefix) => {
|
|
21
|
+
const keys = Object.keys(this.localStorage);
|
|
22
|
+
for (let key in keys) {
|
|
23
|
+
if (key && key.startsWith(prefix)) {
|
|
24
|
+
this.removeItem(key);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ServerLocalStorage = ServerLocalStorage;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { StorageUtils } from '@getpara/core-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Implements `StorageUtils` using a JavaScript object.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare class ServerSessionStorage implements StorageUtils {
|
|
7
|
+
private sessionStorage;
|
|
8
|
+
get: (key: string) => string | null;
|
|
9
|
+
set: (key: string, value: string) => void;
|
|
10
|
+
removeItem: (key: string) => void;
|
|
11
|
+
clear: (prefix: string) => void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerSessionStorage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Implements `StorageUtils` using a JavaScript object.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
class ServerSessionStorage {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.sessionStorage = {};
|
|
11
|
+
this.get = (key) => {
|
|
12
|
+
return this.sessionStorage[key] || null;
|
|
13
|
+
};
|
|
14
|
+
this.set = (key, value) => {
|
|
15
|
+
this.sessionStorage[key] = value;
|
|
16
|
+
};
|
|
17
|
+
this.removeItem = (key) => {
|
|
18
|
+
delete this.sessionStorage[key];
|
|
19
|
+
};
|
|
20
|
+
this.clear = (prefix) => {
|
|
21
|
+
const keys = Object.keys(this.sessionStorage);
|
|
22
|
+
for (let key in keys) {
|
|
23
|
+
if (key && key.startsWith(prefix)) {
|
|
24
|
+
this.removeItem(key);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ServerSessionStorage = ServerSessionStorage;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Ctx, SignatureRes, PlatformUtils, TPregenIdentifierType, WalletType } from '@getpara/core-sdk';
|
|
3
|
+
import { BackupKitEmailProps } from '@getpara/user-management-client';
|
|
4
|
+
import { ServerLocalStorage } from './ServerLocalStorage.js';
|
|
5
|
+
import { ServerSessionStorage } from './ServerSessionStorage.js';
|
|
6
|
+
export declare class ServerUtils implements PlatformUtils {
|
|
7
|
+
getPrivateKey(ctx: Ctx, userId: string, walletId: string, share: string, sessionCookie: string): Promise<string>;
|
|
8
|
+
keygen(ctx: Ctx, userId: string, type: Exclude<WalletType, WalletType.SOLANA>, secretKey: string | null, sessionCookie: string, emailProps?: BackupKitEmailProps): Promise<{
|
|
9
|
+
signer: string;
|
|
10
|
+
walletId: string;
|
|
11
|
+
}>;
|
|
12
|
+
refresh(_ctx: Ctx, _sessionCookie: string, _userId: string, _walletId: string, _share: string, _oldPartnerId?: string, _newPartnerId?: string): Promise<{
|
|
13
|
+
signer: string;
|
|
14
|
+
}>;
|
|
15
|
+
preKeygen(ctx: Ctx, partnerId: string, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type: Exclude<WalletType, WalletType.SOLANA>, secretKey: string | null, // should be acceptable as null in RN as we don't pre-gen them
|
|
16
|
+
sessionCookie: string): Promise<{
|
|
17
|
+
signer: string;
|
|
18
|
+
walletId: string;
|
|
19
|
+
}>;
|
|
20
|
+
signMessage(ctx: Ctx, userId: string, walletId: string, share: string, message: string, sessionCookie: string, isDKLS?: boolean): Promise<SignatureRes>;
|
|
21
|
+
signTransaction(ctx: Ctx, userId: string, walletId: string, share: string, message: string, chainId: string, sessionCookie: string, isDKLS?: boolean): Promise<SignatureRes>;
|
|
22
|
+
sendTransaction(ctx: Ctx, userId: string, walletId: string, share: string, tx: string, chainId: string, sessionCookie: string, isDKLS?: boolean): Promise<SignatureRes>;
|
|
23
|
+
signHash(_address: string, _hash: string): Promise<{
|
|
24
|
+
v: number;
|
|
25
|
+
r: Buffer;
|
|
26
|
+
s: Buffer;
|
|
27
|
+
}>;
|
|
28
|
+
ed25519Keygen(ctx: Ctx, userId: string, sessionCookie: string, emailProps?: BackupKitEmailProps): Promise<{
|
|
29
|
+
signer: string;
|
|
30
|
+
walletId: string;
|
|
31
|
+
}>;
|
|
32
|
+
ed25519PreKeygen(ctx: Ctx, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, sessionCookie: string): Promise<{
|
|
33
|
+
signer: string;
|
|
34
|
+
walletId: string;
|
|
35
|
+
}>;
|
|
36
|
+
ed25519Sign(ctx: Ctx, userId: string, walletId: string, share: string, base64Bytes: string, sessionCookie: string): Promise<SignatureRes>;
|
|
37
|
+
localStorage: ServerLocalStorage;
|
|
38
|
+
sessionStorage: ServerSessionStorage;
|
|
39
|
+
secureStorage: any;
|
|
40
|
+
isSyncStorage: boolean;
|
|
41
|
+
disableProviderModal: boolean;
|
|
42
|
+
openPopup(_popupUrl: string): Window;
|
|
43
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerUtils = void 0;
|
|
4
|
+
const ServerLocalStorage_js_1 = require("./ServerLocalStorage.js");
|
|
5
|
+
const ServerSessionStorage_js_1 = require("./ServerSessionStorage.js");
|
|
6
|
+
const keygen_js_1 = require("./wallet/keygen.js");
|
|
7
|
+
const signing_js_1 = require("./wallet/signing.js");
|
|
8
|
+
const privateKey_js_1 = require("./wallet/privateKey.js");
|
|
9
|
+
class ServerUtils {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.localStorage = new ServerLocalStorage_js_1.ServerLocalStorage();
|
|
12
|
+
this.sessionStorage = new ServerSessionStorage_js_1.ServerSessionStorage();
|
|
13
|
+
this.secureStorage = undefined;
|
|
14
|
+
this.isSyncStorage = true;
|
|
15
|
+
this.disableProviderModal = true;
|
|
16
|
+
}
|
|
17
|
+
getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
18
|
+
return (0, privateKey_js_1.getPrivateKey)(ctx, userId, walletId, share, sessionCookie);
|
|
19
|
+
}
|
|
20
|
+
keygen(ctx, userId, type, secretKey, sessionCookie, emailProps) {
|
|
21
|
+
return (0, keygen_js_1.keygen)(ctx, userId, type, secretKey, true, sessionCookie, emailProps);
|
|
22
|
+
}
|
|
23
|
+
refresh(_ctx, _sessionCookie, _userId, _walletId, _share, _oldPartnerId, _newPartnerId) {
|
|
24
|
+
throw new Error('not implemented');
|
|
25
|
+
}
|
|
26
|
+
preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey, // should be acceptable as null in RN as we don't pre-gen them
|
|
27
|
+
sessionCookie) {
|
|
28
|
+
return (0, keygen_js_1.preKeygen)(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, false, partnerId, sessionCookie);
|
|
29
|
+
}
|
|
30
|
+
signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS) {
|
|
31
|
+
return (0, signing_js_1.signMessage)(ctx, userId, walletId, share, message, sessionCookie, isDKLS);
|
|
32
|
+
}
|
|
33
|
+
signTransaction(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS) {
|
|
34
|
+
return (0, signing_js_1.signTransaction)(ctx, userId, walletId, share, message, chainId, sessionCookie, isDKLS);
|
|
35
|
+
}
|
|
36
|
+
sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
37
|
+
return (0, signing_js_1.sendTransaction)(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS);
|
|
38
|
+
}
|
|
39
|
+
signHash(_address, _hash) {
|
|
40
|
+
throw new Error('not implemented');
|
|
41
|
+
}
|
|
42
|
+
ed25519Keygen(ctx, userId, sessionCookie, emailProps) {
|
|
43
|
+
return (0, keygen_js_1.ed25519Keygen)(ctx, userId, sessionCookie, emailProps);
|
|
44
|
+
}
|
|
45
|
+
ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
|
|
46
|
+
return (0, keygen_js_1.ed25519PreKeygen)(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie);
|
|
47
|
+
}
|
|
48
|
+
ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
|
|
49
|
+
return (0, signing_js_1.ed25519Sign)(ctx, userId, walletId, share, base64Bytes, sessionCookie);
|
|
50
|
+
}
|
|
51
|
+
openPopup(_popupUrl) {
|
|
52
|
+
throw new Error('not implemented');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.ServerUtils = ServerUtils;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Para = void 0;
|
|
18
|
+
__exportStar(require("@getpara/core-sdk"), exports);
|
|
19
|
+
const ParaServer_js_1 = require("./ParaServer.js");
|
|
20
|
+
Object.defineProperty(exports, "Para", { enumerable: true, get: function () { return ParaServer_js_1.Para; } });
|
|
21
|
+
exports.default = ParaServer_js_1.Para;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Ctx, TPregenIdentifierType } from '@getpara/core-sdk';
|
|
2
|
+
import { BackupKitEmailProps, WalletType } from '@getpara/user-management-client';
|
|
3
|
+
export declare function keygen(ctx: Ctx, userId: string, type: WalletType, secretKey: string | null, skipDistribute?: boolean, sessionCookie?: string, _emailProps?: BackupKitEmailProps): Promise<{
|
|
4
|
+
signer: string;
|
|
5
|
+
walletId: string;
|
|
6
|
+
recoveryShare: string | null;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function preKeygen(ctx: Ctx, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type: WalletType, secretKey: string | null, _skipDistribute: boolean, partnerId: string, sessionCookie?: string): Promise<{
|
|
9
|
+
signer: string;
|
|
10
|
+
walletId: string;
|
|
11
|
+
recoveryShare: string | null;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function ed25519Keygen(ctx: Ctx, userId: string, sessionCookie?: string, _emailProps?: BackupKitEmailProps): Promise<{
|
|
14
|
+
signer: string;
|
|
15
|
+
walletId: string;
|
|
16
|
+
recoveryShare: string | null;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function ed25519PreKeygen(ctx: Ctx, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, sessionCookie?: string): Promise<{
|
|
19
|
+
signer: string;
|
|
20
|
+
walletId: string;
|
|
21
|
+
recoveryShare: string | null;
|
|
22
|
+
}>;
|
|
@@ -0,0 +1,172 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.ed25519PreKeygen = exports.ed25519Keygen = exports.preKeygen = exports.keygen = void 0;
|
|
36
|
+
const uuid = __importStar(require("uuid"));
|
|
37
|
+
const core_sdk_1 = require("@getpara/core-sdk");
|
|
38
|
+
const workerWrapper_js_1 = require("../workers/workerWrapper.js");
|
|
39
|
+
function isKeygenComplete(ctx, userId, walletId) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const wallets = yield ctx.client.getWallets(userId);
|
|
42
|
+
const wallet = wallets.data.wallets.find(w => w.id === walletId);
|
|
43
|
+
return !!wallet.address;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, walletId) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const wallets = yield ctx.client.getPregenWallets({ [pregenIdentifierType]: [pregenIdentifier] });
|
|
49
|
+
const wallet = wallets.wallets.find(w => w.id === walletId);
|
|
50
|
+
return !!(wallet === null || wallet === void 0 ? void 0 : wallet.address);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCookie, _emailProps = {}) {
|
|
54
|
+
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const workId = uuid.v4();
|
|
56
|
+
const worker = yield (0, workerWrapper_js_1.setupWorker)(ctx, (res) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
yield (0, core_sdk_1.waitUntilTrue)(() => __awaiter(this, void 0, void 0, function* () { return isKeygenComplete(ctx, userId, res.walletId); }), 15000, 1000);
|
|
58
|
+
if (skipDistribute) {
|
|
59
|
+
resolve({
|
|
60
|
+
signer: res.signer,
|
|
61
|
+
walletId: res.walletId,
|
|
62
|
+
recoveryShare: null,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}), workId);
|
|
66
|
+
worker.postMessage({
|
|
67
|
+
env: ctx.env,
|
|
68
|
+
apiKey: ctx.apiKey,
|
|
69
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
70
|
+
params: { userId, secretKey, type },
|
|
71
|
+
functionType: 'KEYGEN',
|
|
72
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
73
|
+
disableWorkers: ctx.disableWorkers,
|
|
74
|
+
sessionCookie,
|
|
75
|
+
useDKLS: ctx.useDKLS,
|
|
76
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
77
|
+
wasmOverride: ctx.wasmOverride,
|
|
78
|
+
workId,
|
|
79
|
+
});
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
exports.keygen = keygen;
|
|
83
|
+
function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, _skipDistribute = false, partnerId, sessionCookie) {
|
|
84
|
+
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const workId = uuid.v4();
|
|
86
|
+
const worker = yield (0, workerWrapper_js_1.setupWorker)(ctx, (res) => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
yield (0, core_sdk_1.waitUntilTrue)(() => __awaiter(this, void 0, void 0, function* () { return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId); }), 15000, 1000);
|
|
88
|
+
resolve({
|
|
89
|
+
signer: res.signer,
|
|
90
|
+
walletId: res.walletId,
|
|
91
|
+
recoveryShare: null,
|
|
92
|
+
});
|
|
93
|
+
}), workId);
|
|
94
|
+
const email = undefined;
|
|
95
|
+
const params = { pregenIdentifier, pregenIdentifierType, secretKey, partnerId, email, type };
|
|
96
|
+
if (pregenIdentifierType === 'EMAIL') {
|
|
97
|
+
params.email = pregenIdentifier;
|
|
98
|
+
}
|
|
99
|
+
worker.postMessage({
|
|
100
|
+
env: ctx.env,
|
|
101
|
+
apiKey: ctx.apiKey,
|
|
102
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
103
|
+
params: params,
|
|
104
|
+
functionType: 'PREKEYGEN',
|
|
105
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
106
|
+
disableWorkers: ctx.disableWorkers,
|
|
107
|
+
sessionCookie,
|
|
108
|
+
useDKLS: ctx.useDKLS,
|
|
109
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
110
|
+
wasmOverride: ctx.wasmOverride,
|
|
111
|
+
workId,
|
|
112
|
+
});
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
exports.preKeygen = preKeygen;
|
|
116
|
+
function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}) {
|
|
117
|
+
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const workId = uuid.v4();
|
|
119
|
+
const worker = yield (0, workerWrapper_js_1.setupWorker)(ctx, (res) => __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
yield (0, core_sdk_1.waitUntilTrue)(() => __awaiter(this, void 0, void 0, function* () { return isKeygenComplete(ctx, userId, res.walletId); }), 15000, 1000);
|
|
121
|
+
resolve({
|
|
122
|
+
signer: res.signer,
|
|
123
|
+
walletId: res.walletId,
|
|
124
|
+
recoveryShare: null,
|
|
125
|
+
});
|
|
126
|
+
}), workId);
|
|
127
|
+
worker.postMessage({
|
|
128
|
+
env: ctx.env,
|
|
129
|
+
apiKey: ctx.apiKey,
|
|
130
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
131
|
+
params: { userId },
|
|
132
|
+
functionType: 'ED25519_KEYGEN',
|
|
133
|
+
disableWorkers: ctx.disableWorkers,
|
|
134
|
+
sessionCookie,
|
|
135
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
136
|
+
wasmOverride: ctx.wasmOverride,
|
|
137
|
+
workId,
|
|
138
|
+
});
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
exports.ed25519Keygen = ed25519Keygen;
|
|
142
|
+
function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
|
|
143
|
+
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
const workId = uuid.v4();
|
|
145
|
+
const worker = yield (0, workerWrapper_js_1.setupWorker)(ctx, (res) => __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
yield (0, core_sdk_1.waitUntilTrue)(() => __awaiter(this, void 0, void 0, function* () { return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId); }), 15000, 1000);
|
|
147
|
+
resolve({
|
|
148
|
+
signer: res.signer,
|
|
149
|
+
walletId: res.walletId,
|
|
150
|
+
recoveryShare: null,
|
|
151
|
+
});
|
|
152
|
+
}), workId);
|
|
153
|
+
const email = undefined;
|
|
154
|
+
const params = { pregenIdentifier, pregenIdentifierType, email };
|
|
155
|
+
if (pregenIdentifierType === 'EMAIL') {
|
|
156
|
+
params.email = pregenIdentifier;
|
|
157
|
+
}
|
|
158
|
+
worker.postMessage({
|
|
159
|
+
env: ctx.env,
|
|
160
|
+
apiKey: ctx.apiKey,
|
|
161
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
162
|
+
params: params,
|
|
163
|
+
functionType: 'ED25519_PREKEYGEN',
|
|
164
|
+
disableWorkers: ctx.disableWorkers,
|
|
165
|
+
sessionCookie,
|
|
166
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
167
|
+
wasmOverride: ctx.wasmOverride,
|
|
168
|
+
workId,
|
|
169
|
+
});
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
exports.ed25519PreKeygen = ed25519PreKeygen;
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.getPrivateKey = void 0;
|
|
36
|
+
const uuid = __importStar(require("uuid"));
|
|
37
|
+
const workerWrapper_js_1 = require("../workers/workerWrapper.js");
|
|
38
|
+
function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
return yield new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const workId = uuid.v4();
|
|
42
|
+
const worker = yield (0, workerWrapper_js_1.setupWorker)(ctx, (res) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
resolve(res);
|
|
44
|
+
}), workId);
|
|
45
|
+
worker.postMessage({
|
|
46
|
+
env: ctx.env,
|
|
47
|
+
apiKey: ctx.apiKey,
|
|
48
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
49
|
+
params: { share, walletId, userId },
|
|
50
|
+
functionType: 'GET_PRIVATE_KEY',
|
|
51
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
52
|
+
disableWorkers: ctx.disableWorkers,
|
|
53
|
+
sessionCookie,
|
|
54
|
+
useDKLS: ctx.useDKLS,
|
|
55
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
56
|
+
wasmOverride: ctx.wasmOverride,
|
|
57
|
+
workId,
|
|
58
|
+
});
|
|
59
|
+
}));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
exports.getPrivateKey = getPrivateKey;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Ctx, SignatureRes } from '@getpara/core-sdk';
|
|
2
|
+
export declare function signTransaction(ctx: Ctx, userId: string, walletId: string, share: string, tx: string, chainId: string, sessionCookie?: string, isDKLS?: boolean): Promise<SignatureRes>;
|
|
3
|
+
export declare function sendTransaction(ctx: Ctx, userId: string, walletId: string, share: string, tx: string, chainId: string, sessionCookie?: string, isDKLS?: boolean): Promise<SignatureRes>;
|
|
4
|
+
export declare function signMessage(ctx: Ctx, userId: string, walletId: string, share: string, message: string, sessionCookie?: string, isDKLS?: boolean): Promise<SignatureRes>;
|
|
5
|
+
export declare function ed25519Sign(ctx: Ctx, userId: string, walletId: string, share: string, base64Bytes: string, sessionCookie?: string): Promise<SignatureRes>;
|
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.ed25519Sign = exports.signMessage = exports.sendTransaction = exports.signTransaction = void 0;
|
|
36
|
+
const uuid = __importStar(require("uuid"));
|
|
37
|
+
const workerWrapper_js_1 = require("../workers/workerWrapper.js");
|
|
38
|
+
function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
return yield new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const workId = uuid.v4();
|
|
42
|
+
const worker = yield (0, workerWrapper_js_1.setupWorker)(ctx, (sendTransactionRes) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
resolve(sendTransactionRes);
|
|
44
|
+
}), workId);
|
|
45
|
+
worker.postMessage({
|
|
46
|
+
env: ctx.env,
|
|
47
|
+
apiKey: ctx.apiKey,
|
|
48
|
+
cosmosPrefix: ctx.cosmosPrefix,
|
|
49
|
+
params: { share, walletId, userId, tx, chainId },
|
|
50
|
+
functionType: 'SIGN_TRANSACTION',
|
|
51
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
52
|
+
disableWorkers: ctx.disableWorkers,
|
|
53
|
+
sessionCookie,
|
|
54
|
+
useDKLS: isDKLS,
|
|
55
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
56
|
+
wasmOverride: ctx.wasmOverride,
|
|
57
|
+
workId,
|
|
58
|
+
});
|
|
59
|
+
}));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
exports.signTransaction = signTransaction;
|
|
63
|
+
function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
return yield new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const workId = uuid.v4();
|
|
67
|
+
const worker = yield (0, workerWrapper_js_1.setupWorker)(ctx, (sendTransactionRes) => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
resolve(sendTransactionRes);
|
|
69
|
+
}), workId);
|
|
70
|
+
worker.postMessage({
|
|
71
|
+
env: ctx.env,
|
|
72
|
+
apiKey: ctx.apiKey,
|
|
73
|
+
params: { share, walletId, userId, tx, chainId },
|
|
74
|
+
functionType: 'SEND_TRANSACTION',
|
|
75
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
76
|
+
disableWorkers: ctx.disableWorkers,
|
|
77
|
+
sessionCookie,
|
|
78
|
+
useDKLS: isDKLS,
|
|
79
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
80
|
+
wasmOverride: ctx.wasmOverride,
|
|
81
|
+
workId,
|
|
82
|
+
});
|
|
83
|
+
}));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
exports.sendTransaction = sendTransaction;
|
|
87
|
+
function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
return yield new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const workId = uuid.v4();
|
|
91
|
+
const worker = yield (0, workerWrapper_js_1.setupWorker)(ctx, (signMessageRes) => __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
resolve(signMessageRes);
|
|
93
|
+
}), workId);
|
|
94
|
+
worker.postMessage({
|
|
95
|
+
env: ctx.env,
|
|
96
|
+
apiKey: ctx.apiKey,
|
|
97
|
+
params: { share, walletId, userId, message },
|
|
98
|
+
functionType: 'SIGN_MESSAGE',
|
|
99
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
100
|
+
disableWorkers: ctx.disableWorkers,
|
|
101
|
+
sessionCookie,
|
|
102
|
+
useDKLS: isDKLS,
|
|
103
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
104
|
+
wasmOverride: ctx.wasmOverride,
|
|
105
|
+
workId,
|
|
106
|
+
});
|
|
107
|
+
}));
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
exports.signMessage = signMessage;
|
|
111
|
+
function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
return yield new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const workId = uuid.v4();
|
|
115
|
+
const worker = yield (0, workerWrapper_js_1.setupWorker)(ctx, (signMessageRes) => __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
resolve(signMessageRes);
|
|
117
|
+
}), workId);
|
|
118
|
+
worker.postMessage({
|
|
119
|
+
env: ctx.env,
|
|
120
|
+
apiKey: ctx.apiKey,
|
|
121
|
+
params: { share, walletId, userId, base64Bytes },
|
|
122
|
+
functionType: 'ED25519_SIGN',
|
|
123
|
+
offloadMPCComputationURL: ctx.offloadMPCComputationURL,
|
|
124
|
+
disableWorkers: ctx.disableWorkers,
|
|
125
|
+
sessionCookie,
|
|
126
|
+
disableWebSockets: ctx.disableWebSockets,
|
|
127
|
+
wasmOverride: ctx.wasmOverride,
|
|
128
|
+
workId,
|
|
129
|
+
});
|
|
130
|
+
}));
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
exports.ed25519Sign = ed25519Sign;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const globalThisCopy: typeof globalThis;
|