@getpara/core-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/ParaCore.js +2600 -0
- package/dist/cjs/PlatformUtils.js +2 -0
- package/dist/cjs/StorageUtils.js +2 -0
- package/dist/cjs/cryptography/utils.js +251 -0
- package/dist/cjs/definitions.js +155 -0
- package/dist/cjs/errors.js +27 -0
- package/dist/cjs/external/mpcComputationClient.js +33 -0
- package/dist/cjs/external/userManagementClient.js +51 -0
- package/dist/cjs/index.js +81 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/shares/KeyContainer.js +84 -0
- package/dist/cjs/shares/recovery.js +62 -0
- package/dist/cjs/shares/shareDistribution.js +67 -0
- package/dist/cjs/transmission/transmissionUtils.js +73 -0
- package/dist/cjs/types/index.js +20 -0
- package/dist/cjs/types/params.js +2 -0
- package/dist/cjs/types/popupTypes.js +12 -0
- package/dist/cjs/types/theme.js +2 -0
- package/dist/cjs/types/walletTypes.js +2 -0
- package/dist/cjs/utils/formattingUtils.js +71 -0
- package/dist/cjs/utils/pollingUtils.js +25 -0
- package/dist/esm/ParaCore.js +2563 -0
- package/dist/esm/PlatformUtils.js +1 -0
- package/dist/esm/StorageUtils.js +1 -0
- package/dist/esm/cryptography/utils.js +226 -0
- package/dist/esm/definitions.js +142 -0
- package/dist/esm/errors.js +21 -0
- package/dist/esm/external/mpcComputationClient.js +26 -0
- package/dist/esm/external/userManagementClient.js +42 -0
- package/dist/esm/index.js +19 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/shares/KeyContainer.js +57 -0
- package/dist/esm/shares/recovery.js +58 -0
- package/dist/esm/shares/shareDistribution.js +63 -0
- package/dist/esm/transmission/transmissionUtils.js +45 -0
- package/dist/esm/types/index.js +4 -0
- package/dist/esm/types/params.js +1 -0
- package/dist/esm/types/popupTypes.js +9 -0
- package/dist/esm/types/theme.js +1 -0
- package/dist/esm/types/walletTypes.js +1 -0
- package/dist/esm/utils/formattingUtils.js +58 -0
- package/dist/esm/utils/pollingUtils.js +21 -0
- package/dist/types/ParaCore.d.ts +1021 -0
- package/dist/types/PlatformUtils.d.ts +48 -0
- package/dist/types/StorageUtils.d.ts +20 -0
- package/dist/types/cryptography/utils.d.ts +51 -0
- package/dist/types/definitions.d.ts +88 -0
- package/dist/types/errors.d.ts +12 -0
- package/dist/types/external/mpcComputationClient.d.ts +2 -0
- package/dist/types/external/userManagementClient.d.ts +13 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/shares/KeyContainer.d.ts +14 -0
- package/dist/types/shares/recovery.d.ts +12 -0
- package/dist/types/shares/shareDistribution.d.ts +12 -0
- package/dist/types/transmission/transmissionUtils.d.ts +3 -0
- package/dist/types/types/index.d.ts +4 -0
- package/dist/types/types/params.d.ts +24 -0
- package/dist/types/types/popupTypes.d.ts +8 -0
- package/dist/types/types/theme.d.ts +12 -0
- package/dist/types/types/walletTypes.d.ts +11 -0
- package/dist/types/utils/formattingUtils.d.ts +16 -0
- package/dist/types/utils/pollingUtils.d.ts +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,45 @@
|
|
|
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 { randomBytes } from 'crypto';
|
|
11
|
+
import { Encrypt as ECIESEncrypt, Decrypt as ECIESDecrypt } from '@celo/utils/lib/ecies.js';
|
|
12
|
+
import { Buffer } from 'buffer';
|
|
13
|
+
import * as eutil from 'ethereumjs-util';
|
|
14
|
+
export function upload(message, userManagementClient) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
let secret;
|
|
17
|
+
let publicKeyUint8Array;
|
|
18
|
+
while (true) {
|
|
19
|
+
try {
|
|
20
|
+
secret = randomBytes(32).toString('hex');
|
|
21
|
+
// privateToPublic throws error when private key is larger than group order
|
|
22
|
+
// so we want to keep trying until we get a valid private key
|
|
23
|
+
publicKeyUint8Array = eutil.privateToPublic(Buffer.from(secret, 'hex'));
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const pubkey = Buffer.from(publicKeyUint8Array);
|
|
31
|
+
const data = ECIESEncrypt(pubkey, Buffer.from(message, 'ucs2')).toString('base64');
|
|
32
|
+
const { data: { id }, } = yield userManagementClient.tempTrasmissionInit(data);
|
|
33
|
+
return encodeURIComponent(id + '|' + secret);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export function retrieve(uriEncodedMessage, userManagementClient) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const [id, secret] = decodeURIComponent(uriEncodedMessage).split('|');
|
|
39
|
+
const response = yield userManagementClient.tempTrasmission(id);
|
|
40
|
+
const data = response.data.message;
|
|
41
|
+
const buf = Buffer.from(data, 'base64');
|
|
42
|
+
const res = Buffer.from(ECIESDecrypt(Buffer.from(secret, 'hex'), buf).buffer).toString('ucs2');
|
|
43
|
+
return res;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var PopupType;
|
|
2
|
+
(function (PopupType) {
|
|
3
|
+
PopupType["SIGN_TRANSACTION_REVIEW"] = "SIGN_TRANSACTION_REVIEW";
|
|
4
|
+
PopupType["SIGN_MESSAGE_REVIEW"] = "SIGN_MESSAGE_REVIEW";
|
|
5
|
+
PopupType["LOGIN_PASSKEY"] = "LOGIN_PASSKEY";
|
|
6
|
+
PopupType["CREATE_PASSKEY"] = "CREATE_PASSKEY";
|
|
7
|
+
PopupType["OAUTH"] = "OAUTH";
|
|
8
|
+
PopupType["ON_RAMP_TRANSACTION"] = "ON_RAMP_TRANSACTION";
|
|
9
|
+
})(PopupType || (PopupType = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { toBech32 } from '@cosmjs/encoding';
|
|
2
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
3
|
+
import { ripemd160 } from '@noble/hashes/ripemd160';
|
|
4
|
+
import elliptic from 'elliptic';
|
|
5
|
+
const secp256k1 = new elliptic.ec('secp256k1');
|
|
6
|
+
export function hexStringToBase64(hexString) {
|
|
7
|
+
if (hexString.substring(0, 2) === '0x') {
|
|
8
|
+
hexString = hexString.substring(2);
|
|
9
|
+
}
|
|
10
|
+
return Buffer.from(hexString, 'hex').toString('base64');
|
|
11
|
+
}
|
|
12
|
+
export function hexToSignature(hexSig) {
|
|
13
|
+
return {
|
|
14
|
+
r: `0x${hexSig.slice(2, 66)}`,
|
|
15
|
+
s: `0x${hexSig.slice(66, 130)}`,
|
|
16
|
+
v: BigInt(hexSig.slice(130, 132)),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function hexToUint8Array(hex) {
|
|
20
|
+
if (hex.startsWith('0x')) {
|
|
21
|
+
hex = hex.slice(2);
|
|
22
|
+
}
|
|
23
|
+
return new Uint8Array(Buffer.from(hex, 'hex'));
|
|
24
|
+
}
|
|
25
|
+
export function hexToDecimal(hex) {
|
|
26
|
+
if (hex.startsWith('0x')) {
|
|
27
|
+
hex = hex.slice(2);
|
|
28
|
+
}
|
|
29
|
+
return `${parseInt(hex, 16)}`;
|
|
30
|
+
}
|
|
31
|
+
export function decimalToHex(decimal) {
|
|
32
|
+
return `0x${parseInt(decimal).toString(16)}`;
|
|
33
|
+
}
|
|
34
|
+
function compressPubkey(pubkey) {
|
|
35
|
+
switch (pubkey.length) {
|
|
36
|
+
case 33:
|
|
37
|
+
return pubkey;
|
|
38
|
+
case 65:
|
|
39
|
+
return Uint8Array.from(secp256k1.keyFromPublic(pubkey).getPublic(true, 'array'));
|
|
40
|
+
default:
|
|
41
|
+
throw new Error('Invalid pubkey length');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function rawSecp256k1PubkeyToRawAddress(pubkeyData) {
|
|
45
|
+
if (pubkeyData.length !== 33) {
|
|
46
|
+
throw new Error(`Invalid Secp256k1 pubkey length (compressed): ${pubkeyData.length}`);
|
|
47
|
+
}
|
|
48
|
+
return ripemd160(sha256(pubkeyData));
|
|
49
|
+
}
|
|
50
|
+
export function getCosmosAddress(publicKey, prefix) {
|
|
51
|
+
const uncompressedPublicKey = new Uint8Array(Buffer.from(publicKey.startsWith('0x') ? publicKey.slice(2) : publicKey, 'hex'));
|
|
52
|
+
const compressedPublicKey = compressPubkey(uncompressedPublicKey);
|
|
53
|
+
return toBech32(prefix, rawSecp256k1PubkeyToRawAddress(compressedPublicKey));
|
|
54
|
+
}
|
|
55
|
+
export function truncateAddress(str, addressType, { prefix = addressType === 'COSMOS' ? 'cosmos' : undefined } = {}) {
|
|
56
|
+
const headLength = (addressType === 'COSMOS' ? prefix.length : addressType === 'SOLANA' ? 0 : 2) + 4;
|
|
57
|
+
return `${str.slice(0, headLength)}...${str.slice(-4)}`;
|
|
58
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
export function waitUntilTrue(condition, timeoutMs, intervalMs) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
const start = Date.now();
|
|
13
|
+
while (Date.now() - start < timeoutMs) {
|
|
14
|
+
if (yield condition()) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
yield new Promise(resolve => setTimeout(resolve, intervalMs));
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
});
|
|
21
|
+
}
|