@getpara/web-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/LocalStorage.d.ts +10 -0
- package/dist/LocalStorage.js +34 -0
- package/dist/ParaWeb.d.ts +5 -0
- package/dist/ParaWeb.js +7 -0
- package/dist/SessionStorage.d.ts +14 -0
- package/dist/SessionStorage.js +38 -0
- package/dist/WebUtils.d.ts +47 -0
- package/dist/WebUtils.js +113 -0
- package/dist/cryptography/scripts/prime.worker.min.js +2 -0
- package/dist/cryptography/webAuth.d.ts +12 -0
- package/dist/cryptography/webAuth.js +167 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +7 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/utils/emailUtils.d.ts +1 -0
- package/dist/utils/emailUtils.js +5 -0
- package/dist/utils/formattingUtils.d.ts +11 -0
- package/dist/utils/formattingUtils.js +28 -0
- package/dist/utils/isMobile.d.ts +10 -0
- package/dist/utils/isMobile.js +39 -0
- package/dist/utils/truncateEthAddress.d.ts +1 -0
- package/dist/utils/truncateEthAddress.js +8 -0
- package/dist/wallet/keygen.d.ts +26 -0
- package/dist/wallet/keygen.js +185 -0
- package/dist/wallet/privateKey.d.ts +2 -0
- package/dist/wallet/privateKey.js +33 -0
- package/dist/wallet/signing.d.ts +5 -0
- package/dist/wallet/signing.js +100 -0
- package/dist/wasm/wasm_exec.d.ts +0 -0
- package/dist/wasm/wasm_exec.js +513 -0
- package/dist/workers/walletUtils.d.ts +28 -0
- package/dist/workers/walletUtils.js +244 -0
- package/dist/workers/worker.d.ts +19 -0
- package/dist/workers/worker.js +128 -0
- package/dist/workers/workerWrapper.d.ts +6 -0
- package/dist/workers/workerWrapper.js +50 -0
- package/package.json +39 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StorageUtils } from '@getpara/core-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Implements `StorageUtils` using `localStorage`.
|
|
4
|
+
*/
|
|
5
|
+
export declare class LocalStorage implements StorageUtils {
|
|
6
|
+
get: (key: string) => string | null;
|
|
7
|
+
set: (key: string, value: string) => void;
|
|
8
|
+
removeItem: (key: string) => void;
|
|
9
|
+
clear: (prefix: string) => void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implements `StorageUtils` using `localStorage`.
|
|
3
|
+
*/
|
|
4
|
+
export class LocalStorage {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.get = (key) => {
|
|
7
|
+
if (typeof window !== 'undefined') {
|
|
8
|
+
return localStorage.getItem(key) || null;
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
};
|
|
12
|
+
this.set = (key, value) => {
|
|
13
|
+
if (typeof window !== 'undefined') {
|
|
14
|
+
localStorage.setItem(key, value);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
this.removeItem = (key) => {
|
|
18
|
+
if (typeof window !== 'undefined') {
|
|
19
|
+
localStorage.removeItem(key);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
this.clear = (prefix) => {
|
|
23
|
+
if (typeof window !== 'undefined') {
|
|
24
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
25
|
+
const key = localStorage.key(i);
|
|
26
|
+
if (key && key.startsWith(prefix)) {
|
|
27
|
+
localStorage.removeItem(key);
|
|
28
|
+
i--;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/ParaWeb.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StorageUtils } from '@getpara/core-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Implements `StorageUtils` using `sessionStorage`.
|
|
4
|
+
*
|
|
5
|
+
* This class will eventually not be exported and should not be used
|
|
6
|
+
* by consumers of the library.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare class SessionStorage implements StorageUtils {
|
|
10
|
+
get: (key: string) => string | null;
|
|
11
|
+
set: (key: string, value: string) => void;
|
|
12
|
+
removeItem: (key: string) => void;
|
|
13
|
+
clear: (prefix: string) => void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implements `StorageUtils` using `sessionStorage`.
|
|
3
|
+
*
|
|
4
|
+
* This class will eventually not be exported and should not be used
|
|
5
|
+
* by consumers of the library.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export class SessionStorage {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.get = (key) => {
|
|
11
|
+
if (typeof window !== 'undefined') {
|
|
12
|
+
return sessionStorage.getItem(key) || null;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
};
|
|
16
|
+
this.set = (key, value) => {
|
|
17
|
+
if (typeof window !== 'undefined') {
|
|
18
|
+
sessionStorage.setItem(key, value);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
this.removeItem = (key) => {
|
|
22
|
+
if (typeof window !== 'undefined') {
|
|
23
|
+
sessionStorage.removeItem(key);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
this.clear = (prefix) => {
|
|
27
|
+
if (typeof window !== 'undefined') {
|
|
28
|
+
for (let i = 0; i < sessionStorage.length; i++) {
|
|
29
|
+
const key = sessionStorage.key(i);
|
|
30
|
+
if (key && key.startsWith(prefix)) {
|
|
31
|
+
sessionStorage.removeItem(key);
|
|
32
|
+
i--;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Ctx, PlatformUtils, SignatureRes, PopupType } from '@getpara/core-sdk';
|
|
3
|
+
import { LocalStorage } from './LocalStorage.js';
|
|
4
|
+
import { SessionStorage } from './SessionStorage.js';
|
|
5
|
+
import { BackupKitEmailProps, WalletType } from '@getpara/user-management-client';
|
|
6
|
+
import { TPregenIdentifierType } from '@getpara/core-sdk';
|
|
7
|
+
export declare class WebUtils implements PlatformUtils {
|
|
8
|
+
getPrivateKey(ctx: Ctx, userId: string, walletId: string, share: string, sessionCookie: string): Promise<string>;
|
|
9
|
+
keygen(ctx: Ctx, userId: string, type: Exclude<WalletType, WalletType.SOLANA>, secretKey: string | null, // should be acceptable as null in RN as we don't pre-gen them
|
|
10
|
+
sessionCookie: string, emailProps?: BackupKitEmailProps): Promise<{
|
|
11
|
+
signer: string;
|
|
12
|
+
walletId: string;
|
|
13
|
+
}>;
|
|
14
|
+
refresh(ctx: Ctx, sessionCookie: string, userId: string, walletId: string, share: string, oldPartnerId?: string, newPartnerId?: string, keyShareProtocolId?: string): Promise<{
|
|
15
|
+
signer: string;
|
|
16
|
+
}>;
|
|
17
|
+
preKeygen(ctx: Ctx, partnerId: string | undefined, 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
|
|
18
|
+
sessionCookie: string): Promise<{
|
|
19
|
+
signer: string;
|
|
20
|
+
walletId: string;
|
|
21
|
+
}>;
|
|
22
|
+
signMessage(ctx: Ctx, userId: string, walletId: string, share: string, message: string, sessionCookie: string, isDKLS?: boolean, cosmosSignDoc?: string): Promise<SignatureRes>;
|
|
23
|
+
signTransaction(ctx: Ctx, userId: string, walletId: string, share: string, tx: string, chainId: string, sessionCookie: string, isDKLS?: boolean): Promise<SignatureRes>;
|
|
24
|
+
sendTransaction(ctx: Ctx, userId: string, walletId: string, share: string, tx: string, chainId: string, sessionCookie: string, isDKLS?: boolean): Promise<SignatureRes>;
|
|
25
|
+
signHash(_address: string, _hash: string): Promise<{
|
|
26
|
+
v: number;
|
|
27
|
+
r: Buffer;
|
|
28
|
+
s: Buffer;
|
|
29
|
+
}>;
|
|
30
|
+
ed25519Keygen(ctx: Ctx, userId: string, sessionCookie: string, emailProps?: BackupKitEmailProps): Promise<{
|
|
31
|
+
signer: string;
|
|
32
|
+
walletId: string;
|
|
33
|
+
}>;
|
|
34
|
+
ed25519PreKeygen(ctx: Ctx, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, sessionCookie: string): Promise<{
|
|
35
|
+
signer: string;
|
|
36
|
+
walletId: string;
|
|
37
|
+
}>;
|
|
38
|
+
ed25519Sign(ctx: Ctx, userId: string, walletId: string, share: string, base64Bytes: string, sessionCookie: string): Promise<SignatureRes>;
|
|
39
|
+
localStorage: LocalStorage;
|
|
40
|
+
sessionStorage: SessionStorage;
|
|
41
|
+
secureStorage: any;
|
|
42
|
+
isSyncStorage: boolean;
|
|
43
|
+
disableProviderModal: boolean;
|
|
44
|
+
openPopup(popupUrl: string, opts?: {
|
|
45
|
+
type: PopupType;
|
|
46
|
+
}): Window;
|
|
47
|
+
}
|
package/dist/WebUtils.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { PopupType } from '@getpara/core-sdk';
|
|
2
|
+
import { LocalStorage } from './LocalStorage.js';
|
|
3
|
+
import { SessionStorage } from './SessionStorage.js';
|
|
4
|
+
import { keygen, preKeygen, ed25519Keygen, ed25519PreKeygen, refresh } from './wallet/keygen.js';
|
|
5
|
+
import { signMessage, sendTransaction, signTransaction, ed25519Sign } from './wallet/signing.js';
|
|
6
|
+
import { getPrivateKey } from './wallet/privateKey.js';
|
|
7
|
+
export class WebUtils {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.localStorage = new LocalStorage();
|
|
10
|
+
this.sessionStorage = new SessionStorage();
|
|
11
|
+
this.secureStorage = null;
|
|
12
|
+
this.isSyncStorage = true;
|
|
13
|
+
this.disableProviderModal = false;
|
|
14
|
+
}
|
|
15
|
+
getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
16
|
+
return getPrivateKey(ctx, userId, walletId, share, sessionCookie);
|
|
17
|
+
}
|
|
18
|
+
keygen(ctx, userId, type, secretKey, // should be acceptable as null in RN as we don't pre-gen them
|
|
19
|
+
sessionCookie, emailProps = {}) {
|
|
20
|
+
return keygen(ctx, userId, type, secretKey, true, sessionCookie, emailProps);
|
|
21
|
+
}
|
|
22
|
+
refresh(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId) {
|
|
23
|
+
return refresh(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId);
|
|
24
|
+
}
|
|
25
|
+
preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey, // should be acceptable as null in RN as we don't pre-gen them
|
|
26
|
+
sessionCookie) {
|
|
27
|
+
return preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, false, partnerId, sessionCookie);
|
|
28
|
+
}
|
|
29
|
+
signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc) {
|
|
30
|
+
return signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc);
|
|
31
|
+
}
|
|
32
|
+
signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
33
|
+
return signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS);
|
|
34
|
+
}
|
|
35
|
+
sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
36
|
+
return sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS);
|
|
37
|
+
}
|
|
38
|
+
signHash(_address, _hash) {
|
|
39
|
+
throw new Error('not implemented');
|
|
40
|
+
}
|
|
41
|
+
ed25519Keygen(ctx, userId, sessionCookie, emailProps) {
|
|
42
|
+
return ed25519Keygen(ctx, userId, sessionCookie, emailProps);
|
|
43
|
+
}
|
|
44
|
+
ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
|
|
45
|
+
return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie);
|
|
46
|
+
}
|
|
47
|
+
ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
|
|
48
|
+
return ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie);
|
|
49
|
+
}
|
|
50
|
+
openPopup(popupUrl, opts) {
|
|
51
|
+
if (opts) {
|
|
52
|
+
const { type } = opts;
|
|
53
|
+
const popUpWidth = 550;
|
|
54
|
+
let popUpHeight;
|
|
55
|
+
switch (type) {
|
|
56
|
+
case PopupType.LOGIN_PASSKEY: {
|
|
57
|
+
popUpHeight = 798;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case PopupType.CREATE_PASSKEY: {
|
|
61
|
+
popUpHeight = 464;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case PopupType.SIGN_MESSAGE_REVIEW: {
|
|
65
|
+
popUpHeight = 585;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case PopupType.SIGN_TRANSACTION_REVIEW: {
|
|
69
|
+
popUpHeight = 750;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case PopupType.OAUTH:
|
|
73
|
+
default: {
|
|
74
|
+
popUpHeight = 768;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Fixes position when using multiple monitors
|
|
79
|
+
const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
|
|
80
|
+
const dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;
|
|
81
|
+
const width = window.innerWidth
|
|
82
|
+
? window.innerWidth
|
|
83
|
+
: document.documentElement.clientWidth
|
|
84
|
+
? document.documentElement.clientWidth
|
|
85
|
+
: screen.width;
|
|
86
|
+
const height = window.innerHeight
|
|
87
|
+
? window.innerHeight
|
|
88
|
+
: document.documentElement.clientHeight
|
|
89
|
+
? document.documentElement.clientHeight
|
|
90
|
+
: screen.height;
|
|
91
|
+
const left = (width - popUpWidth) / 2 + dualScreenLeft;
|
|
92
|
+
const top = (height - popUpHeight) / 2 + dualScreenTop;
|
|
93
|
+
const windowFeatures = `toolbar=no, menubar=no, width=${popUpWidth},
|
|
94
|
+
height=${popUpHeight}, top=${top}, left=${left}`;
|
|
95
|
+
let popupWindow = window.open(popupUrl, type.toString(), windowFeatures);
|
|
96
|
+
if (!popupWindow) {
|
|
97
|
+
setTimeout(() => {
|
|
98
|
+
popupWindow = window.open(popupUrl, '_blank');
|
|
99
|
+
}, 0);
|
|
100
|
+
}
|
|
101
|
+
return popupWindow;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const popupWindow = window.open(popupUrl, 'popup', 'popup=true,width=400,height=500');
|
|
105
|
+
if (!popupWindow) {
|
|
106
|
+
setTimeout(() => {
|
|
107
|
+
window.open(popupUrl, '_blank');
|
|
108
|
+
}, 0);
|
|
109
|
+
}
|
|
110
|
+
return popupWindow;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(t){var i={};function r(o){if(i[o])return i[o].exports;var s=i[o]={i:o,l:!1,exports:{}};return t[o].call(s.exports,s,s.exports,r),s.l=!0,s.exports}r.m=t,r.c=i,r.d=function(t,i,o){r.o(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:o})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,i){if(1&i&&(t=r(t)),8&i)return t;if(4&i&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&i&&"string"!=typeof t)for(var s in t)r.d(o,s,function(i){return t[i]}.bind(null,s));return o},r.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(i,"a",i),i},r.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},r.p="",r(r.s=1)}([function(t,i){t.exports={options:{usePureJavaScript:!1}}},function(t,i,r){r(2),t.exports=r(0)},function(t,i,r){var o=r(0);r(3);var s=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],e=(1<<26)/s[s.length-1],a=o.jsbn.BigInteger;new a(null).fromInt(2),self.addEventListener("message",(function(t){var i=function(t){for(var i=new a(t.hex,16),r=0,o=t.workLoad,s=0;s<o;++s){if(h(i))return{found:!0,prime:i.toString(16)};i.dAddOffset(n[r++%8],0)}return{found:!1}}(t.data);self.postMessage(i)})),self.postMessage({found:!1});var n=[6,4,2,4,2,4,6,2];function h(t){for(var i=1;i<s.length;){for(var r=s[i],o=i+1;o<s.length&&r<e;)r*=s[o++];for(r=t.modInt(r);i<o;)if(r%s[i++]==0)return!1}return function(t){var i=t.subtract(a.ONE),r=i.getLowestSetBit();if(r<=0)return!1;for(var o,s=i.shiftRight(r),e=(p=t.bitLength(),p<=100?27:p<=150?18:p<=200?15:p<=250?12:p<=300?9:p<=350?8:p<=400?7:p<=500?6:p<=600?5:p<=800?4:p<=1250?3:2),n={nextBytes:function(t){for(var i=0;i<t.length;++i)t[i]=Math.floor(255*Math.random())}},h=0;h<e;++h){do{o=new a(t.bitLength(),n)}while(o.compareTo(a.ONE)<=0||o.compareTo(i)>=0);var u=o.modPow(s,t);if(0!==u.compareTo(a.ONE)&&0!==u.compareTo(i)){for(var f=r;--f;){if(0===(u=u.modPowInt(2,t)).compareTo(a.ONE))return!1;if(0===u.compareTo(i))break}if(0===f)return!1}}var p;return!0}(t)}},function(t,i,r){var o,s=r(0);t.exports=s.jsbn=s.jsbn||{};function e(t,i,r){this.data=[],null!=t&&("number"==typeof t?this.fromNumber(t,i,r):null==i&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,i))}function a(){return new e(null)}function n(t,i,r,o,s,e){for(var a=16383&i,n=i>>14;--e>=0;){var h=16383&this.data[t],u=this.data[t++]>>14,f=n*h+u*a;s=((h=a*h+((16383&f)<<14)+r.data[o]+s)>>28)+(f>>14)+n*u,r.data[o++]=268435455&h}return s}s.jsbn.BigInteger=e,"undefined"==typeof navigator?(e.prototype.am=n,o=28):"Microsoft Internet Explorer"==navigator.appName?(e.prototype.am=function(t,i,r,o,s,e){for(var a=32767&i,n=i>>15;--e>=0;){var h=32767&this.data[t],u=this.data[t++]>>15,f=n*h+u*a;s=((h=a*h+((32767&f)<<15)+r.data[o]+(1073741823&s))>>>30)+(f>>>15)+n*u+(s>>>30),r.data[o++]=1073741823&h}return s},o=30):"Netscape"!=navigator.appName?(e.prototype.am=function(t,i,r,o,s,e){for(;--e>=0;){var a=i*this.data[t++]+r.data[o]+s;s=Math.floor(a/67108864),r.data[o++]=67108863&a}return s},o=26):(e.prototype.am=n,o=28),e.prototype.DB=o,e.prototype.DM=(1<<o)-1,e.prototype.DV=1<<o;e.prototype.FV=Math.pow(2,52),e.prototype.F1=52-o,e.prototype.F2=2*o-52;var h,u,f=new Array;for(h="0".charCodeAt(0),u=0;u<=9;++u)f[h++]=u;for(h="a".charCodeAt(0),u=10;u<36;++u)f[h++]=u;for(h="A".charCodeAt(0),u=10;u<36;++u)f[h++]=u;function p(t){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t)}function d(t,i){var r=f[t.charCodeAt(i)];return null==r?-1:r}function c(t){var i=a();return i.fromInt(t),i}function m(t){var i,r=1;return 0!=(i=t>>>16)&&(t=i,r+=16),0!=(i=t>>8)&&(t=i,r+=8),0!=(i=t>>4)&&(t=i,r+=4),0!=(i=t>>2)&&(t=i,r+=2),0!=(i=t>>1)&&(t=i,r+=1),r}function l(t){this.m=t}function v(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}function T(t,i){return t&i}function y(t,i){return t|i}function b(t,i){return t^i}function g(t,i){return t&~i}function D(t){if(0==t)return-1;var i=0;return 0==(65535&t)&&(t>>=16,i+=16),0==(255&t)&&(t>>=8,i+=8),0==(15&t)&&(t>>=4,i+=4),0==(3&t)&&(t>>=2,i+=2),0==(1&t)&&++i,i}function B(t){for(var i=0;0!=t;)t&=t-1,++i;return i}function S(){}function M(t){return t}function w(t){this.r2=a(),this.q3=a(),e.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}l.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},l.prototype.revert=function(t){return t},l.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},l.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r),this.reduce(r)},l.prototype.sqrTo=function(t,i){t.squareTo(i),this.reduce(i)},v.prototype.convert=function(t){var i=a();return t.abs().dlShiftTo(this.m.t,i),i.divRemTo(this.m,null,i),t.s<0&&i.compareTo(e.ZERO)>0&&this.m.subTo(i,i),i},v.prototype.revert=function(t){var i=a();return t.copyTo(i),this.reduce(i),i},v.prototype.reduce=function(t){for(;t.t<=this.mt2;)t.data[t.t++]=0;for(var i=0;i<this.m.t;++i){var r=32767&t.data[i],o=r*this.mpl+((r*this.mph+(t.data[i]>>15)*this.mpl&this.um)<<15)&t.DM;for(r=i+this.m.t,t.data[r]+=this.m.am(0,o,t,i,0,this.m.t);t.data[r]>=t.DV;)t.data[r]-=t.DV,t.data[++r]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},v.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r),this.reduce(r)},v.prototype.sqrTo=function(t,i){t.squareTo(i),this.reduce(i)},e.prototype.copyTo=function(t){for(var i=this.t-1;i>=0;--i)t.data[i]=this.data[i];t.t=this.t,t.s=this.s},e.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this.data[0]=t:t<-1?this.data[0]=t+this.DV:this.t=0},e.prototype.fromString=function(t,i){var r;if(16==i)r=4;else if(8==i)r=3;else if(256==i)r=8;else if(2==i)r=1;else if(32==i)r=5;else{if(4!=i)return void this.fromRadix(t,i);r=2}this.t=0,this.s=0;for(var o=t.length,s=!1,a=0;--o>=0;){var n=8==r?255&t[o]:d(t,o);n<0?"-"==t.charAt(o)&&(s=!0):(s=!1,0==a?this.data[this.t++]=n:a+r>this.DB?(this.data[this.t-1]|=(n&(1<<this.DB-a)-1)<<a,this.data[this.t++]=n>>this.DB-a):this.data[this.t-1]|=n<<a,(a+=r)>=this.DB&&(a-=this.DB))}8==r&&0!=(128&t[0])&&(this.s=-1,a>0&&(this.data[this.t-1]|=(1<<this.DB-a)-1<<a)),this.clamp(),s&&e.ZERO.subTo(this,this)},e.prototype.clamp=function(){for(var t=this.s&this.DM;this.t>0&&this.data[this.t-1]==t;)--this.t},e.prototype.dlShiftTo=function(t,i){var r;for(r=this.t-1;r>=0;--r)i.data[r+t]=this.data[r];for(r=t-1;r>=0;--r)i.data[r]=0;i.t=this.t+t,i.s=this.s},e.prototype.drShiftTo=function(t,i){for(var r=t;r<this.t;++r)i.data[r-t]=this.data[r];i.t=Math.max(this.t-t,0),i.s=this.s},e.prototype.lShiftTo=function(t,i){var r,o=t%this.DB,s=this.DB-o,e=(1<<s)-1,a=Math.floor(t/this.DB),n=this.s<<o&this.DM;for(r=this.t-1;r>=0;--r)i.data[r+a+1]=this.data[r]>>s|n,n=(this.data[r]&e)<<o;for(r=a-1;r>=0;--r)i.data[r]=0;i.data[a]=n,i.t=this.t+a+1,i.s=this.s,i.clamp()},e.prototype.rShiftTo=function(t,i){i.s=this.s;var r=Math.floor(t/this.DB);if(r>=this.t)i.t=0;else{var o=t%this.DB,s=this.DB-o,e=(1<<o)-1;i.data[0]=this.data[r]>>o;for(var a=r+1;a<this.t;++a)i.data[a-r-1]|=(this.data[a]&e)<<s,i.data[a-r]=this.data[a]>>o;o>0&&(i.data[this.t-r-1]|=(this.s&e)<<s),i.t=this.t-r,i.clamp()}},e.prototype.subTo=function(t,i){for(var r=0,o=0,s=Math.min(t.t,this.t);r<s;)o+=this.data[r]-t.data[r],i.data[r++]=o&this.DM,o>>=this.DB;if(t.t<this.t){for(o-=t.s;r<this.t;)o+=this.data[r],i.data[r++]=o&this.DM,o>>=this.DB;o+=this.s}else{for(o+=this.s;r<t.t;)o-=t.data[r],i.data[r++]=o&this.DM,o>>=this.DB;o-=t.s}i.s=o<0?-1:0,o<-1?i.data[r++]=this.DV+o:o>0&&(i.data[r++]=o),i.t=r,i.clamp()},e.prototype.multiplyTo=function(t,i){var r=this.abs(),o=t.abs(),s=r.t;for(i.t=s+o.t;--s>=0;)i.data[s]=0;for(s=0;s<o.t;++s)i.data[s+r.t]=r.am(0,o.data[s],i,s,0,r.t);i.s=0,i.clamp(),this.s!=t.s&&e.ZERO.subTo(i,i)},e.prototype.squareTo=function(t){for(var i=this.abs(),r=t.t=2*i.t;--r>=0;)t.data[r]=0;for(r=0;r<i.t-1;++r){var o=i.am(r,i.data[r],t,2*r,0,1);(t.data[r+i.t]+=i.am(r+1,2*i.data[r],t,2*r+1,o,i.t-r-1))>=i.DV&&(t.data[r+i.t]-=i.DV,t.data[r+i.t+1]=1)}t.t>0&&(t.data[t.t-1]+=i.am(r,i.data[r],t,2*r,0,1)),t.s=0,t.clamp()},e.prototype.divRemTo=function(t,i,r){var o=t.abs();if(!(o.t<=0)){var s=this.abs();if(s.t<o.t)return null!=i&&i.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=a());var n=a(),h=this.s,u=t.s,f=this.DB-m(o.data[o.t-1]);f>0?(o.lShiftTo(f,n),s.lShiftTo(f,r)):(o.copyTo(n),s.copyTo(r));var p=n.t,d=n.data[p-1];if(0!=d){var c=d*(1<<this.F1)+(p>1?n.data[p-2]>>this.F2:0),l=this.FV/c,v=(1<<this.F1)/c,T=1<<this.F2,y=r.t,b=y-p,g=null==i?a():i;for(n.dlShiftTo(b,g),r.compareTo(g)>=0&&(r.data[r.t++]=1,r.subTo(g,r)),e.ONE.dlShiftTo(p,g),g.subTo(n,n);n.t<p;)n.data[n.t++]=0;for(;--b>=0;){var D=r.data[--y]==d?this.DM:Math.floor(r.data[y]*l+(r.data[y-1]+T)*v);if((r.data[y]+=n.am(0,D,r,b,0,p))<D)for(n.dlShiftTo(b,g),r.subTo(g,r);r.data[y]<--D;)r.subTo(g,r)}null!=i&&(r.drShiftTo(p,i),h!=u&&e.ZERO.subTo(i,i)),r.t=p,r.clamp(),f>0&&r.rShiftTo(f,r),h<0&&e.ZERO.subTo(r,r)}}},e.prototype.invDigit=function(){if(this.t<1)return 0;var t=this.data[0];if(0==(1&t))return 0;var i=3&t;return(i=(i=(i=(i=i*(2-(15&t)*i)&15)*(2-(255&t)*i)&255)*(2-((65535&t)*i&65535))&65535)*(2-t*i%this.DV)%this.DV)>0?this.DV-i:-i},e.prototype.isEven=function(){return 0==(this.t>0?1&this.data[0]:this.s)},e.prototype.exp=function(t,i){if(t>4294967295||t<1)return e.ONE;var r=a(),o=a(),s=i.convert(this),n=m(t)-1;for(s.copyTo(r);--n>=0;)if(i.sqrTo(r,o),(t&1<<n)>0)i.mulTo(o,s,r);else{var h=r;r=o,o=h}return i.revert(r)},e.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var i;if(16==t)i=4;else if(8==t)i=3;else if(2==t)i=1;else if(32==t)i=5;else{if(4!=t)return this.toRadix(t);i=2}var r,o=(1<<i)-1,s=!1,e="",a=this.t,n=this.DB-a*this.DB%i;if(a-- >0)for(n<this.DB&&(r=this.data[a]>>n)>0&&(s=!0,e=p(r));a>=0;)n<i?(r=(this.data[a]&(1<<n)-1)<<i-n,r|=this.data[--a]>>(n+=this.DB-i)):(r=this.data[a]>>(n-=i)&o,n<=0&&(n+=this.DB,--a)),r>0&&(s=!0),s&&(e+=p(r));return s?e:"0"},e.prototype.negate=function(){var t=a();return e.ZERO.subTo(this,t),t},e.prototype.abs=function(){return this.s<0?this.negate():this},e.prototype.compareTo=function(t){var i=this.s-t.s;if(0!=i)return i;var r=this.t;if(0!=(i=r-t.t))return this.s<0?-i:i;for(;--r>=0;)if(0!=(i=this.data[r]-t.data[r]))return i;return 0},e.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+m(this.data[this.t-1]^this.s&this.DM)},e.prototype.mod=function(t){var i=a();return this.abs().divRemTo(t,null,i),this.s<0&&i.compareTo(e.ZERO)>0&&t.subTo(i,i),i},e.prototype.modPowInt=function(t,i){var r;return r=t<256||i.isEven()?new l(i):new v(i),this.exp(t,r)},e.ZERO=c(0),e.ONE=c(1),S.prototype.convert=M,S.prototype.revert=M,S.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r)},S.prototype.sqrTo=function(t,i){t.squareTo(i)},w.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var i=a();return t.copyTo(i),this.reduce(i),i},w.prototype.revert=function(t){return t},w.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},w.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r),this.reduce(r)},w.prototype.sqrTo=function(t,i){t.squareTo(i),this.reduce(i)};var E=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509],O=(1<<26)/E[E.length-1];e.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},e.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var i=this.chunkSize(t),r=Math.pow(t,i),o=c(r),s=a(),e=a(),n="";for(this.divRemTo(o,s,e);s.signum()>0;)n=(r+e.intValue()).toString(t).substr(1)+n,s.divRemTo(o,s,e);return e.intValue().toString(t)+n},e.prototype.fromRadix=function(t,i){this.fromInt(0),null==i&&(i=10);for(var r=this.chunkSize(i),o=Math.pow(i,r),s=!1,a=0,n=0,h=0;h<t.length;++h){var u=d(t,h);u<0?"-"==t.charAt(h)&&0==this.signum()&&(s=!0):(n=i*n+u,++a>=r&&(this.dMultiply(o),this.dAddOffset(n,0),a=0,n=0))}a>0&&(this.dMultiply(Math.pow(i,a)),this.dAddOffset(n,0)),s&&e.ZERO.subTo(this,this)},e.prototype.fromNumber=function(t,i,r){if("number"==typeof i)if(t<2)this.fromInt(1);else for(this.fromNumber(t,r),this.testBit(t-1)||this.bitwiseTo(e.ONE.shiftLeft(t-1),y,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(i);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(e.ONE.shiftLeft(t-1),this);else{var o=new Array,s=7&t;o.length=1+(t>>3),i.nextBytes(o),s>0?o[0]&=(1<<s)-1:o[0]=0,this.fromString(o,256)}},e.prototype.bitwiseTo=function(t,i,r){var o,s,e=Math.min(t.t,this.t);for(o=0;o<e;++o)r.data[o]=i(this.data[o],t.data[o]);if(t.t<this.t){for(s=t.s&this.DM,o=e;o<this.t;++o)r.data[o]=i(this.data[o],s);r.t=this.t}else{for(s=this.s&this.DM,o=e;o<t.t;++o)r.data[o]=i(s,t.data[o]);r.t=t.t}r.s=i(this.s,t.s),r.clamp()},e.prototype.changeBit=function(t,i){var r=e.ONE.shiftLeft(t);return this.bitwiseTo(r,i,r),r},e.prototype.addTo=function(t,i){for(var r=0,o=0,s=Math.min(t.t,this.t);r<s;)o+=this.data[r]+t.data[r],i.data[r++]=o&this.DM,o>>=this.DB;if(t.t<this.t){for(o+=t.s;r<this.t;)o+=this.data[r],i.data[r++]=o&this.DM,o>>=this.DB;o+=this.s}else{for(o+=this.s;r<t.t;)o+=t.data[r],i.data[r++]=o&this.DM,o>>=this.DB;o+=t.s}i.s=o<0?-1:0,o>0?i.data[r++]=o:o<-1&&(i.data[r++]=this.DV+o),i.t=r,i.clamp()},e.prototype.dMultiply=function(t){this.data[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},e.prototype.dAddOffset=function(t,i){if(0!=t){for(;this.t<=i;)this.data[this.t++]=0;for(this.data[i]+=t;this.data[i]>=this.DV;)this.data[i]-=this.DV,++i>=this.t&&(this.data[this.t++]=0),++this.data[i]}},e.prototype.multiplyLowerTo=function(t,i,r){var o,s=Math.min(this.t+t.t,i);for(r.s=0,r.t=s;s>0;)r.data[--s]=0;for(o=r.t-this.t;s<o;++s)r.data[s+this.t]=this.am(0,t.data[s],r,s,0,this.t);for(o=Math.min(t.t,i);s<o;++s)this.am(0,t.data[s],r,s,0,i-s);r.clamp()},e.prototype.multiplyUpperTo=function(t,i,r){--i;var o=r.t=this.t+t.t-i;for(r.s=0;--o>=0;)r.data[o]=0;for(o=Math.max(i-this.t,0);o<t.t;++o)r.data[this.t+o-i]=this.am(i-o,t.data[o],r,0,0,this.t+o-i);r.clamp(),r.drShiftTo(1,r)},e.prototype.modInt=function(t){if(t<=0)return 0;var i=this.DV%t,r=this.s<0?t-1:0;if(this.t>0)if(0==i)r=this.data[0]%t;else for(var o=this.t-1;o>=0;--o)r=(i*r+this.data[o])%t;return r},e.prototype.millerRabin=function(t){var i=this.subtract(e.ONE),r=i.getLowestSetBit();if(r<=0)return!1;for(var o,s=i.shiftRight(r),a={nextBytes:function(t){for(var i=0;i<t.length;++i)t[i]=Math.floor(256*Math.random())}},n=0;n<t;++n){do{o=new e(this.bitLength(),a)}while(o.compareTo(e.ONE)<=0||o.compareTo(i)>=0);var h=o.modPow(s,this);if(0!=h.compareTo(e.ONE)&&0!=h.compareTo(i)){for(var u=1;u++<r&&0!=h.compareTo(i);)if(0==(h=h.modPowInt(2,this)).compareTo(e.ONE))return!1;if(0!=h.compareTo(i))return!1}}return!0},e.prototype.clone=function(){var t=a();return this.copyTo(t),t},e.prototype.intValue=function(){if(this.s<0){if(1==this.t)return this.data[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this.data[0];if(0==this.t)return 0}return(this.data[1]&(1<<32-this.DB)-1)<<this.DB|this.data[0]},e.prototype.byteValue=function(){return 0==this.t?this.s:this.data[0]<<24>>24},e.prototype.shortValue=function(){return 0==this.t?this.s:this.data[0]<<16>>16},e.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this.data[0]<=0?0:1},e.prototype.toByteArray=function(){var t=this.t,i=new Array;i[0]=this.s;var r,o=this.DB-t*this.DB%8,s=0;if(t-- >0)for(o<this.DB&&(r=this.data[t]>>o)!=(this.s&this.DM)>>o&&(i[s++]=r|this.s<<this.DB-o);t>=0;)o<8?(r=(this.data[t]&(1<<o)-1)<<8-o,r|=this.data[--t]>>(o+=this.DB-8)):(r=this.data[t]>>(o-=8)&255,o<=0&&(o+=this.DB,--t)),0!=(128&r)&&(r|=-256),0==s&&(128&this.s)!=(128&r)&&++s,(s>0||r!=this.s)&&(i[s++]=r);return i},e.prototype.equals=function(t){return 0==this.compareTo(t)},e.prototype.min=function(t){return this.compareTo(t)<0?this:t},e.prototype.max=function(t){return this.compareTo(t)>0?this:t},e.prototype.and=function(t){var i=a();return this.bitwiseTo(t,T,i),i},e.prototype.or=function(t){var i=a();return this.bitwiseTo(t,y,i),i},e.prototype.xor=function(t){var i=a();return this.bitwiseTo(t,b,i),i},e.prototype.andNot=function(t){var i=a();return this.bitwiseTo(t,g,i),i},e.prototype.not=function(){for(var t=a(),i=0;i<this.t;++i)t.data[i]=this.DM&~this.data[i];return t.t=this.t,t.s=~this.s,t},e.prototype.shiftLeft=function(t){var i=a();return t<0?this.rShiftTo(-t,i):this.lShiftTo(t,i),i},e.prototype.shiftRight=function(t){var i=a();return t<0?this.lShiftTo(-t,i):this.rShiftTo(t,i),i},e.prototype.getLowestSetBit=function(){for(var t=0;t<this.t;++t)if(0!=this.data[t])return t*this.DB+D(this.data[t]);return this.s<0?this.t*this.DB:-1},e.prototype.bitCount=function(){for(var t=0,i=this.s&this.DM,r=0;r<this.t;++r)t+=B(this.data[r]^i);return t},e.prototype.testBit=function(t){var i=Math.floor(t/this.DB);return i>=this.t?0!=this.s:0!=(this.data[i]&1<<t%this.DB)},e.prototype.setBit=function(t){return this.changeBit(t,y)},e.prototype.clearBit=function(t){return this.changeBit(t,g)},e.prototype.flipBit=function(t){return this.changeBit(t,b)},e.prototype.add=function(t){var i=a();return this.addTo(t,i),i},e.prototype.subtract=function(t){var i=a();return this.subTo(t,i),i},e.prototype.multiply=function(t){var i=a();return this.multiplyTo(t,i),i},e.prototype.divide=function(t){var i=a();return this.divRemTo(t,i,null),i},e.prototype.remainder=function(t){var i=a();return this.divRemTo(t,null,i),i},e.prototype.divideAndRemainder=function(t){var i=a(),r=a();return this.divRemTo(t,i,r),new Array(i,r)},e.prototype.modPow=function(t,i){var r,o,s=t.bitLength(),e=c(1);if(s<=0)return e;r=s<18?1:s<48?3:s<144?4:s<768?5:6,o=s<8?new l(i):i.isEven()?new w(i):new v(i);var n=new Array,h=3,u=r-1,f=(1<<r)-1;if(n[1]=o.convert(this),r>1){var p=a();for(o.sqrTo(n[1],p);h<=f;)n[h]=a(),o.mulTo(p,n[h-2],n[h]),h+=2}var d,T,y=t.t-1,b=!0,g=a();for(s=m(t.data[y])-1;y>=0;){for(s>=u?d=t.data[y]>>s-u&f:(d=(t.data[y]&(1<<s+1)-1)<<u-s,y>0&&(d|=t.data[y-1]>>this.DB+s-u)),h=r;0==(1&d);)d>>=1,--h;if((s-=h)<0&&(s+=this.DB,--y),b)n[d].copyTo(e),b=!1;else{for(;h>1;)o.sqrTo(e,g),o.sqrTo(g,e),h-=2;h>0?o.sqrTo(e,g):(T=e,e=g,g=T),o.mulTo(g,n[d],e)}for(;y>=0&&0==(t.data[y]&1<<s);)o.sqrTo(e,g),T=e,e=g,g=T,--s<0&&(s=this.DB-1,--y)}return o.revert(e)},e.prototype.modInverse=function(t){var i=t.isEven();if(this.isEven()&&i||0==t.signum())return e.ZERO;for(var r=t.clone(),o=this.clone(),s=c(1),a=c(0),n=c(0),h=c(1);0!=r.signum();){for(;r.isEven();)r.rShiftTo(1,r),i?(s.isEven()&&a.isEven()||(s.addTo(this,s),a.subTo(t,a)),s.rShiftTo(1,s)):a.isEven()||a.subTo(t,a),a.rShiftTo(1,a);for(;o.isEven();)o.rShiftTo(1,o),i?(n.isEven()&&h.isEven()||(n.addTo(this,n),h.subTo(t,h)),n.rShiftTo(1,n)):h.isEven()||h.subTo(t,h),h.rShiftTo(1,h);r.compareTo(o)>=0?(r.subTo(o,r),i&&s.subTo(n,s),a.subTo(h,a)):(o.subTo(r,o),i&&n.subTo(s,n),h.subTo(a,h))}return 0!=o.compareTo(e.ONE)?e.ZERO:h.compareTo(t)>=0?h.subtract(t):h.signum()<0?(h.addTo(t,h),h.signum()<0?h.add(t):h):h},e.prototype.pow=function(t){return this.exp(t,new S)},e.prototype.gcd=function(t){var i=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(i.compareTo(r)<0){var o=i;i=r,r=o}var s=i.getLowestSetBit(),e=r.getLowestSetBit();if(e<0)return i;for(s<e&&(e=s),e>0&&(i.rShiftTo(e,i),r.rShiftTo(e,r));i.signum()>0;)(s=i.getLowestSetBit())>0&&i.rShiftTo(s,i),(s=r.getLowestSetBit())>0&&r.rShiftTo(s,r),i.compareTo(r)>=0?(i.subTo(r,i),i.rShiftTo(1,i)):(r.subTo(i,r),r.rShiftTo(1,r));return e>0&&r.lShiftTo(e,r),r},e.prototype.isProbablePrime=function(t){var i,r=this.abs();if(1==r.t&&r.data[0]<=E[E.length-1]){for(i=0;i<E.length;++i)if(r.data[0]==E[i])return!0;return!1}if(r.isEven())return!1;for(i=1;i<E.length;){for(var o=E[i],s=i+1;s<E.length&&o<O;)o*=E[s++];for(o=r.modInt(o);i<s;)if(o%E[i++]==0)return!1}return r.millerRabin(t)}}]);
|
|
2
|
+
//# sourceMappingURL=prime.worker.min.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Environment } from '@getpara/core-sdk';
|
|
2
|
+
export declare function parseCredentialCreationRes(creds: any, algorithm: number): {
|
|
3
|
+
cosePublicKey: string;
|
|
4
|
+
clientDataJSON: string;
|
|
5
|
+
aaguid: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function createCredential(env: Environment, userId: string, identifier: string, isE2E?: boolean): Promise<{
|
|
8
|
+
creds: any;
|
|
9
|
+
userHandle: string;
|
|
10
|
+
algorithm: number;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function generateSignature(env: Environment, challenge: string, allowedPublicKeys: string[], isE2E?: boolean): Promise<any>;
|
|
@@ -0,0 +1,167 @@
|
|
|
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 base64url from 'base64url';
|
|
11
|
+
import * as cbor from 'cbor-web';
|
|
12
|
+
import forge from 'node-forge';
|
|
13
|
+
import { getPortalDomain } from '@getpara/core-sdk';
|
|
14
|
+
const ES256_ALGORITHM = -7;
|
|
15
|
+
const RS256_ALGORITHM = -257;
|
|
16
|
+
function publicKeyCredentialToJSON(pubKeyCred) {
|
|
17
|
+
if (pubKeyCred instanceof ArrayBuffer) {
|
|
18
|
+
return base64url.encode(pubKeyCred);
|
|
19
|
+
}
|
|
20
|
+
else if (pubKeyCred instanceof Array) {
|
|
21
|
+
return pubKeyCred.map(publicKeyCredentialToJSON);
|
|
22
|
+
}
|
|
23
|
+
else if (pubKeyCred instanceof Object) {
|
|
24
|
+
const obj = {};
|
|
25
|
+
for (const key in pubKeyCred) {
|
|
26
|
+
obj[key] = publicKeyCredentialToJSON(pubKeyCred[key]);
|
|
27
|
+
}
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
30
|
+
else
|
|
31
|
+
return pubKeyCred;
|
|
32
|
+
}
|
|
33
|
+
function parseMakeCredAuthData(buffer) {
|
|
34
|
+
const rpIdHash = buffer.slice(0, 32);
|
|
35
|
+
buffer = buffer.slice(32);
|
|
36
|
+
const flagsBuf = buffer.slice(0, 1);
|
|
37
|
+
buffer = buffer.slice(1);
|
|
38
|
+
const flags = flagsBuf[0];
|
|
39
|
+
const counterBuf = buffer.slice(0, 4);
|
|
40
|
+
buffer = buffer.slice(4);
|
|
41
|
+
const counter = counterBuf.readUInt32BE(0);
|
|
42
|
+
const aaguid = buffer.slice(0, 16);
|
|
43
|
+
buffer = buffer.slice(16);
|
|
44
|
+
const credIDLenBuf = buffer.slice(0, 2);
|
|
45
|
+
buffer = buffer.slice(2);
|
|
46
|
+
const credIDLen = credIDLenBuf.readUInt16BE(0);
|
|
47
|
+
const credID = buffer.slice(0, credIDLen);
|
|
48
|
+
buffer = buffer.slice(credIDLen);
|
|
49
|
+
const COSEPublicKey = buffer;
|
|
50
|
+
return {
|
|
51
|
+
rpIdHash,
|
|
52
|
+
flagsBuf,
|
|
53
|
+
flags,
|
|
54
|
+
counter,
|
|
55
|
+
counterBuf,
|
|
56
|
+
aaguid,
|
|
57
|
+
credID,
|
|
58
|
+
COSEPublicKey,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function parseAttestationObject(attestationObject) {
|
|
62
|
+
const attestationObjectBuffer = base64url.toBuffer(attestationObject);
|
|
63
|
+
return cbor.decodeAllSync(attestationObjectBuffer)[0];
|
|
64
|
+
}
|
|
65
|
+
function COSEECDSAtoPKCS(COSEPublicKey) {
|
|
66
|
+
const coseStruct = cbor.decodeAllSync(COSEPublicKey)[0];
|
|
67
|
+
const tag = Buffer.from([0x04]);
|
|
68
|
+
const x = coseStruct.get(-2);
|
|
69
|
+
const y = coseStruct.get(-3);
|
|
70
|
+
return Buffer.concat([tag, x, y]);
|
|
71
|
+
}
|
|
72
|
+
function COSERSAtoPKCS(COSEPublicKey) {
|
|
73
|
+
const coseStruct = cbor.decodeAllSync(COSEPublicKey)[0];
|
|
74
|
+
const n = coseStruct.get(-1);
|
|
75
|
+
const e = coseStruct.get(-2);
|
|
76
|
+
// Convert to Forge's format:
|
|
77
|
+
const nForge = forge.util.createBuffer(n.toString('binary'));
|
|
78
|
+
const eForge = forge.util.createBuffer(e.toString('binary'));
|
|
79
|
+
// Create a new public key object:
|
|
80
|
+
const publicKey = forge.pki.setRsaPublicKey(new forge.jsbn.BigInteger(nForge.toHex(), 16), new forge.jsbn.BigInteger(eForge.toHex(), 16));
|
|
81
|
+
// Export as a PKCS#1 public key buffer:
|
|
82
|
+
return Buffer.from(forge.pki.publicKeyToPem(publicKey), 'utf-8');
|
|
83
|
+
}
|
|
84
|
+
export function parseCredentialCreationRes(creds, algorithm) {
|
|
85
|
+
const parsedAttestation = parseAttestationObject(creds.response.attestationObject);
|
|
86
|
+
const { COSEPublicKey, aaguid } = parseMakeCredAuthData(parsedAttestation.authData);
|
|
87
|
+
if (algorithm === RS256_ALGORITHM) {
|
|
88
|
+
return {
|
|
89
|
+
cosePublicKey: base64url.encode(COSERSAtoPKCS(COSEPublicKey)),
|
|
90
|
+
clientDataJSON: creds.response.clientDataJSON,
|
|
91
|
+
aaguid: aaguid.toString('hex'),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
cosePublicKey: base64url.encode(COSEECDSAtoPKCS(COSEPublicKey)),
|
|
96
|
+
clientDataJSON: creds.response.clientDataJSON,
|
|
97
|
+
aaguid: aaguid.toString('hex'),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
// generate a random 32 byte user handle, which is the max for AES-GCM encryption
|
|
101
|
+
// supported via window.crypto.subtle
|
|
102
|
+
function generateUserHandle() {
|
|
103
|
+
const userHandle = new Uint8Array(32);
|
|
104
|
+
window.crypto.getRandomValues(userHandle);
|
|
105
|
+
return userHandle;
|
|
106
|
+
}
|
|
107
|
+
export function createCredential(env, userId, identifier, isE2E) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const userHandle = generateUserHandle();
|
|
110
|
+
const createCredentialDefaultArgs = {
|
|
111
|
+
publicKey: {
|
|
112
|
+
authenticatorSelection: {
|
|
113
|
+
authenticatorAttachment: 'platform',
|
|
114
|
+
requireResidentKey: true,
|
|
115
|
+
residentKey: 'required',
|
|
116
|
+
userVerification: 'required',
|
|
117
|
+
},
|
|
118
|
+
rp: {
|
|
119
|
+
id: getPortalDomain(env, isE2E),
|
|
120
|
+
name: 'Para',
|
|
121
|
+
},
|
|
122
|
+
user: {
|
|
123
|
+
id: userHandle,
|
|
124
|
+
name: identifier,
|
|
125
|
+
displayName: identifier,
|
|
126
|
+
},
|
|
127
|
+
pubKeyCredParams: [
|
|
128
|
+
{ type: 'public-key', alg: ES256_ALGORITHM },
|
|
129
|
+
// RS256_ALGORITHM should only be needed for windows hello
|
|
130
|
+
{ type: 'public-key', alg: RS256_ALGORITHM },
|
|
131
|
+
],
|
|
132
|
+
attestation: 'direct',
|
|
133
|
+
timeout: 60000,
|
|
134
|
+
// TODO: don't think we really get value from verifying this, but should revisit
|
|
135
|
+
challenge: Buffer.from(userId, 'utf-8'),
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
const credential = yield navigator.credentials.create(createCredentialDefaultArgs);
|
|
139
|
+
const algorithm = credential.response.getPublicKeyAlgorithm
|
|
140
|
+
? credential.response.getPublicKeyAlgorithm()
|
|
141
|
+
: ES256_ALGORITHM;
|
|
142
|
+
const userHandleEncoded = base64url.encode(Buffer.from(userHandle));
|
|
143
|
+
return {
|
|
144
|
+
creds: publicKeyCredentialToJSON(credential),
|
|
145
|
+
userHandle: userHandleEncoded,
|
|
146
|
+
algorithm,
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
export function generateSignature(env, challenge, allowedPublicKeys, isE2E) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const getCredentialDefaultArgs = {
|
|
153
|
+
publicKey: {
|
|
154
|
+
timeout: 60000,
|
|
155
|
+
challenge: Buffer.from(challenge, 'base64'),
|
|
156
|
+
allowCredentials: allowedPublicKeys.map(key => ({
|
|
157
|
+
id: base64url.toBuffer(key),
|
|
158
|
+
type: 'public-key',
|
|
159
|
+
})),
|
|
160
|
+
userVerification: 'required',
|
|
161
|
+
rpId: getPortalDomain(env, isE2E),
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
const assertation = yield navigator.credentials.get(getCredentialDefaultArgs);
|
|
165
|
+
return publicKeyCredentialToJSON(assertation);
|
|
166
|
+
});
|
|
167
|
+
}
|
package/dist/errors.d.ts
ADDED
package/dist/errors.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from '@getpara/core-sdk';
|
|
2
|
+
import { Para as ParaWeb } from './ParaWeb.js';
|
|
3
|
+
import ParaCore from '@getpara/core-sdk';
|
|
4
|
+
export { type StorageUtils, type ConstructorOpts, Environment, type OnRampConfig, type OnRampAllowedAssets, } from '@getpara/core-sdk';
|
|
5
|
+
export { createCredential, generateSignature, parseCredentialCreationRes } from './cryptography/webAuth.js';
|
|
6
|
+
export { truncateEthAddress } from './utils/truncateEthAddress.js';
|
|
7
|
+
export * from './utils/isMobile.js';
|
|
8
|
+
export { ParaWeb, ParaCore };
|
|
9
|
+
export default ParaWeb;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from '@getpara/core-sdk';
|
|
2
|
+
import { Para as ParaWeb } from './ParaWeb.js';
|
|
3
|
+
import ParaCore from '@getpara/core-sdk';
|
|
4
|
+
export { Environment, } from '@getpara/core-sdk';
|
|
5
|
+
export { createCredential, generateSignature, parseCredentialCreationRes } from './cryptography/webAuth.js';
|
|
6
|
+
export { truncateEthAddress } from './utils/truncateEthAddress.js';
|
|
7
|
+
export * from './utils/isMobile.js';
|
|
8
|
+
export { ParaWeb, ParaCore };
|
|
9
|
+
export default ParaWeb;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getMailtoLink(email: any, recoveryShare: any): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export function getMailtoLink(email, recoveryShare) {
|
|
2
|
+
const emailBody = `Hello,%0D%0DBelow is your Para Recovery Secret. Keep this safe!%0D%0D${recoveryShare}%0D%0DPlease get in touch via support@getpara.com if you have any questions`;
|
|
3
|
+
const mailText = `mailto:${email}?subject=Para%20Recovery%20Secret&body=${emailBody}`;
|
|
4
|
+
return mailText;
|
|
5
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Hex = `0x${string}`;
|
|
2
|
+
export interface Signature {
|
|
3
|
+
r: Hex;
|
|
4
|
+
s: Hex;
|
|
5
|
+
v: bigint;
|
|
6
|
+
}
|
|
7
|
+
export declare function hexStringToBase64(hexString: string): string;
|
|
8
|
+
export declare function hexToSignature(hexSig: string): Signature;
|
|
9
|
+
export declare function hexToUint8Array(hex: string): Uint8Array;
|
|
10
|
+
export declare function hexToDecimal(hex: string): string;
|
|
11
|
+
export declare function decimalToHex(decimal: string): Hex;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function hexStringToBase64(hexString) {
|
|
2
|
+
if (hexString.substring(0, 2) === '0x') {
|
|
3
|
+
hexString = hexString.substring(2);
|
|
4
|
+
}
|
|
5
|
+
return Buffer.from(hexString, 'hex').toString('base64');
|
|
6
|
+
}
|
|
7
|
+
export function hexToSignature(hexSig) {
|
|
8
|
+
return {
|
|
9
|
+
r: `0x${hexSig.slice(2, 66)}`,
|
|
10
|
+
s: `0x${hexSig.slice(66, 130)}`,
|
|
11
|
+
v: BigInt(hexSig.slice(130, 132)),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function hexToUint8Array(hex) {
|
|
15
|
+
if (hex.startsWith('0x')) {
|
|
16
|
+
hex = hex.slice(2);
|
|
17
|
+
}
|
|
18
|
+
return new Uint8Array(Buffer.from(hex, 'hex'));
|
|
19
|
+
}
|
|
20
|
+
export function hexToDecimal(hex) {
|
|
21
|
+
if (hex.startsWith('0x')) {
|
|
22
|
+
hex = hex.slice(2);
|
|
23
|
+
}
|
|
24
|
+
return `${parseInt(hex, 16)}`;
|
|
25
|
+
}
|
|
26
|
+
export function decimalToHex(decimal) {
|
|
27
|
+
return `0x${parseInt(decimal).toString(16)}`;
|
|
28
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function isAndroid(): boolean;
|
|
2
|
+
export declare function isSmallIOS(): boolean;
|
|
3
|
+
export declare function isLargeIOS(): boolean;
|
|
4
|
+
export declare function isTablet(): boolean;
|
|
5
|
+
export declare function isIOS(): boolean;
|
|
6
|
+
export declare function isMobile(): boolean;
|
|
7
|
+
export declare function isSafari(): boolean;
|
|
8
|
+
export declare function isIOSWebview(): boolean;
|
|
9
|
+
export declare function isMobileSafari(): boolean;
|
|
10
|
+
export declare function isTelegram(): boolean;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function isAndroid() {
|
|
2
|
+
return typeof navigator !== 'undefined' && /android/i.test(navigator.userAgent);
|
|
3
|
+
}
|
|
4
|
+
export function isSmallIOS() {
|
|
5
|
+
return typeof navigator !== 'undefined' && /iPhone|iPod/.test(navigator.userAgent);
|
|
6
|
+
}
|
|
7
|
+
export function isLargeIOS() {
|
|
8
|
+
return (typeof navigator !== 'undefined' &&
|
|
9
|
+
(/iPad/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)));
|
|
10
|
+
}
|
|
11
|
+
export function isTablet() {
|
|
12
|
+
return (typeof navigator !== 'undefined' &&
|
|
13
|
+
/(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(navigator.userAgent));
|
|
14
|
+
}
|
|
15
|
+
export function isIOS() {
|
|
16
|
+
return isSmallIOS() || isLargeIOS();
|
|
17
|
+
}
|
|
18
|
+
export function isMobile() {
|
|
19
|
+
return isAndroid() || isIOS();
|
|
20
|
+
}
|
|
21
|
+
export function isSafari() {
|
|
22
|
+
return (typeof navigator !== 'undefined' &&
|
|
23
|
+
/AppleWebKit/i.test(navigator.userAgent) &&
|
|
24
|
+
!/CriOS/i.test(navigator.userAgent) &&
|
|
25
|
+
!/Chrome/i.test(navigator.userAgent));
|
|
26
|
+
}
|
|
27
|
+
export function isIOSWebview() {
|
|
28
|
+
const isStandalone = typeof navigator !== 'undefined' && !navigator.standalone;
|
|
29
|
+
return typeof navigator !== 'undefined' && isIOS() && !isStandalone && !/safari/i.test(navigator.userAgent.toLowerCase());
|
|
30
|
+
}
|
|
31
|
+
export function isMobileSafari() {
|
|
32
|
+
return isMobile() && isSafari();
|
|
33
|
+
}
|
|
34
|
+
export function isTelegram() {
|
|
35
|
+
return (typeof window !== 'undefined' &&
|
|
36
|
+
(Boolean(window.TelegramWebviewProxy) ||
|
|
37
|
+
Boolean(window.Telegram) ||
|
|
38
|
+
Boolean(window.TelegramWebviewProxyProto)));
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const truncateEthAddress: (address: string) => string;
|