@getpara/web-sdk 2.0.0-dev.1 → 2.0.0-dev.3
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.js +36 -0
- package/dist/ParaWeb.d.ts +9 -0
- package/dist/ParaWeb.js +71 -0
- package/dist/SessionStorage.js +36 -0
- package/dist/WebUtils.d.ts +4 -4
- package/dist/WebUtils.js +110 -0
- package/dist/chunk-WLGKV3EF.js +35 -0
- package/dist/cryptography/webAuth.js +162 -0
- package/dist/errors.js +12 -0
- package/dist/index.js +12 -1817
- package/dist/package.json +6 -0
- package/dist/utils/emailUtils.js +10 -0
- package/dist/utils/formattingUtils.js +37 -0
- package/dist/utils/isMobile.js +47 -0
- package/dist/utils/isPasskeySupported.js +17 -0
- package/dist/utils/truncateEthAddress.js +11 -0
- package/dist/wallet/keygen.d.ts +3 -3
- package/dist/wallet/keygen.js +250 -0
- package/dist/wallet/privateKey.js +41 -0
- package/dist/wallet/signing.js +140 -0
- package/dist/wasm/wasm_exec.js +564 -0
- package/dist/workers/walletUtils.d.ts +4 -6
- package/dist/workers/walletUtils.js +363 -0
- package/dist/workers/worker.d.ts +9 -1
- package/dist/workers/worker.js +62 -910
- package/dist/workers/workerWrapper.d.ts +1 -1
- package/dist/workers/workerWrapper.js +85 -0
- package/package.json +30 -25
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
- package/dist/workers/worker.js.br +0 -0
- package/dist/workers/worker.js.gz +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "./chunk-WLGKV3EF.js";
|
|
3
|
+
class LocalStorage {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.get = (key) => {
|
|
6
|
+
if (typeof window !== "undefined") {
|
|
7
|
+
return localStorage.getItem(key) || null;
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
};
|
|
11
|
+
this.set = (key, value) => {
|
|
12
|
+
if (typeof window !== "undefined") {
|
|
13
|
+
localStorage.setItem(key, value);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
this.removeItem = (key) => {
|
|
17
|
+
if (typeof window !== "undefined") {
|
|
18
|
+
localStorage.removeItem(key);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
this.clear = (prefix) => {
|
|
22
|
+
if (typeof window !== "undefined") {
|
|
23
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
24
|
+
const key = localStorage.key(i);
|
|
25
|
+
if (key && key.startsWith(prefix)) {
|
|
26
|
+
localStorage.removeItem(key);
|
|
27
|
+
i--;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
LocalStorage
|
|
36
|
+
};
|
package/dist/ParaWeb.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import ParaCore, { ConstructorOpts, Environment } from '@getpara/core-sdk';
|
|
2
2
|
import { WebUtils } from './WebUtils.js';
|
|
3
3
|
export declare class Para extends ParaCore {
|
|
4
|
+
#private;
|
|
5
|
+
farcasterSdk: any;
|
|
6
|
+
isReady: boolean;
|
|
7
|
+
isFarcasterMiniApp: boolean;
|
|
4
8
|
constructor(env: Environment, apiKey?: string, opts?: ConstructorOpts);
|
|
9
|
+
protected ready(): Promise<void>;
|
|
10
|
+
protected get toStringAdditions(): {
|
|
11
|
+
isFarcasterMiniApp: boolean;
|
|
12
|
+
};
|
|
5
13
|
protected getPlatformUtils(): WebUtils;
|
|
14
|
+
isPasskeySupported(): Promise<boolean>;
|
|
6
15
|
}
|
package/dist/ParaWeb.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__async,
|
|
4
|
+
__privateAdd,
|
|
5
|
+
__privateGet,
|
|
6
|
+
__privateSet
|
|
7
|
+
} from "./chunk-WLGKV3EF.js";
|
|
8
|
+
var _isPasskeySupported;
|
|
9
|
+
import * as Sentry from "@sentry/browser";
|
|
10
|
+
import ParaCore, { Environment } from "@getpara/core-sdk";
|
|
11
|
+
import { WebUtils } from "./WebUtils.js";
|
|
12
|
+
import { isPasskeySupported } from "./utils/isPasskeySupported.js";
|
|
13
|
+
class Para extends ParaCore {
|
|
14
|
+
constructor(env, apiKey, opts) {
|
|
15
|
+
super(env, apiKey, opts);
|
|
16
|
+
this.farcasterSdk = void 0;
|
|
17
|
+
this.isReady = false;
|
|
18
|
+
this.isFarcasterMiniApp = false;
|
|
19
|
+
__privateAdd(this, _isPasskeySupported);
|
|
20
|
+
if (env !== Environment.PROD && env !== Environment.DEV) {
|
|
21
|
+
Sentry.init({
|
|
22
|
+
environment: env.toLowerCase(),
|
|
23
|
+
dsn: "https://38f27d4836da617ab9e95cf66b9611d9@o4504568036720640.ingest.us.sentry.io/4508850812944384"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
ready() {
|
|
28
|
+
return __async(this, null, function* () {
|
|
29
|
+
var _a, _b, _c, _d;
|
|
30
|
+
if (!this.isReady) {
|
|
31
|
+
try {
|
|
32
|
+
this.farcasterSdk = (_b = (_a = yield import("@farcaster/miniapp-sdk")) == null ? void 0 : _a.sdk) != null ? _b : void 0;
|
|
33
|
+
if (!((_c = this.farcasterSdk) == null ? void 0 : _c.isInMiniApp)) {
|
|
34
|
+
throw new Error("Farcaster SDK not detected or failed to load");
|
|
35
|
+
}
|
|
36
|
+
this.devLog("Farcaster SDK detected and loaded successfully.", this.farcasterSdk);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
this.devLog(e);
|
|
39
|
+
}
|
|
40
|
+
if (!!((_d = this.farcasterSdk) == null ? void 0 : _d.isInMiniApp)) {
|
|
41
|
+
this.devLog("Initializing Farcaster SDK...");
|
|
42
|
+
this.isFarcasterMiniApp = yield this.farcasterSdk.isInMiniApp();
|
|
43
|
+
if (this.isFarcasterMiniApp) {
|
|
44
|
+
this.externalWalletConnectionOnly = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
this.isReady = true;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
get toStringAdditions() {
|
|
52
|
+
return {
|
|
53
|
+
isFarcasterMiniApp: this.isFarcasterMiniApp
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
getPlatformUtils() {
|
|
57
|
+
return new WebUtils();
|
|
58
|
+
}
|
|
59
|
+
isPasskeySupported() {
|
|
60
|
+
return __async(this, null, function* () {
|
|
61
|
+
if (__privateGet(this, _isPasskeySupported) === void 0) {
|
|
62
|
+
__privateSet(this, _isPasskeySupported, yield isPasskeySupported());
|
|
63
|
+
}
|
|
64
|
+
return __privateGet(this, _isPasskeySupported);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
_isPasskeySupported = new WeakMap();
|
|
69
|
+
export {
|
|
70
|
+
Para
|
|
71
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "./chunk-WLGKV3EF.js";
|
|
3
|
+
class SessionStorage {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.get = (key) => {
|
|
6
|
+
if (typeof window !== "undefined") {
|
|
7
|
+
return sessionStorage.getItem(key) || null;
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
};
|
|
11
|
+
this.set = (key, value) => {
|
|
12
|
+
if (typeof window !== "undefined") {
|
|
13
|
+
sessionStorage.setItem(key, value);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
this.removeItem = (key) => {
|
|
17
|
+
if (typeof window !== "undefined") {
|
|
18
|
+
sessionStorage.removeItem(key);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
this.clear = (prefix) => {
|
|
22
|
+
if (typeof window !== "undefined") {
|
|
23
|
+
for (let i = 0; i < sessionStorage.length; i++) {
|
|
24
|
+
const key = sessionStorage.key(i);
|
|
25
|
+
if (key && key.startsWith(prefix)) {
|
|
26
|
+
sessionStorage.removeItem(key);
|
|
27
|
+
i--;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
SessionStorage
|
|
36
|
+
};
|
package/dist/WebUtils.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Ctx, PlatformUtils, SignatureRes, PopupType } from '@getpara/core-sdk';
|
|
3
2
|
import { LocalStorage } from './LocalStorage.js';
|
|
4
3
|
import { SessionStorage } from './SessionStorage.js';
|
|
5
|
-
import { BackupKitEmailProps,
|
|
4
|
+
import { BackupKitEmailProps, TWalletType, SDKType } from '@getpara/user-management-client';
|
|
6
5
|
import { TPregenIdentifierType } from '@getpara/core-sdk';
|
|
7
6
|
export declare class WebUtils implements PlatformUtils {
|
|
7
|
+
sdkType: SDKType;
|
|
8
8
|
getPrivateKey(ctx: Ctx, userId: string, walletId: string, share: string, sessionCookie: string): Promise<string>;
|
|
9
|
-
keygen(ctx: Ctx, userId: string, type: Exclude<
|
|
9
|
+
keygen(ctx: Ctx, userId: string, type: Exclude<TWalletType, 'SOLANA'>, secretKey: string | null, // should be acceptable as null in RN as we don't pre-gen them
|
|
10
10
|
sessionCookie: string, emailProps?: BackupKitEmailProps): Promise<{
|
|
11
11
|
signer: string;
|
|
12
12
|
walletId: string;
|
|
@@ -14,7 +14,7 @@ export declare class WebUtils implements PlatformUtils {
|
|
|
14
14
|
refresh(ctx: Ctx, sessionCookie: string, userId: string, walletId: string, share: string, oldPartnerId?: string, newPartnerId?: string, keyShareProtocolId?: string): Promise<{
|
|
15
15
|
signer: string;
|
|
16
16
|
}>;
|
|
17
|
-
preKeygen(ctx: Ctx, partnerId: string | undefined, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type: Exclude<
|
|
17
|
+
preKeygen(ctx: Ctx, partnerId: string | undefined, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type: Exclude<TWalletType, 'SOLANA'>, secretKey: string | null, // should be acceptable as null in RN as we don't pre-gen them
|
|
18
18
|
sessionCookie: string): Promise<{
|
|
19
19
|
signer: string;
|
|
20
20
|
walletId: string;
|
package/dist/WebUtils.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "./chunk-WLGKV3EF.js";
|
|
3
|
+
import { PopupType } from "@getpara/core-sdk";
|
|
4
|
+
import { LocalStorage } from "./LocalStorage.js";
|
|
5
|
+
import { SessionStorage } from "./SessionStorage.js";
|
|
6
|
+
import { keygen, preKeygen, ed25519Keygen, ed25519PreKeygen, refresh } from "./wallet/keygen.js";
|
|
7
|
+
import { signMessage, sendTransaction, signTransaction, ed25519Sign } from "./wallet/signing.js";
|
|
8
|
+
import { getPrivateKey } from "./wallet/privateKey.js";
|
|
9
|
+
class WebUtils {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.sdkType = "WEB";
|
|
12
|
+
this.localStorage = new LocalStorage();
|
|
13
|
+
this.sessionStorage = new SessionStorage();
|
|
14
|
+
this.secureStorage = null;
|
|
15
|
+
this.isSyncStorage = true;
|
|
16
|
+
this.disableProviderModal = false;
|
|
17
|
+
}
|
|
18
|
+
getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
19
|
+
return getPrivateKey(ctx, userId, walletId, share, sessionCookie);
|
|
20
|
+
}
|
|
21
|
+
keygen(ctx, userId, type, secretKey, sessionCookie, emailProps = {}) {
|
|
22
|
+
return keygen(ctx, userId, type, secretKey, true, sessionCookie, emailProps);
|
|
23
|
+
}
|
|
24
|
+
refresh(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId) {
|
|
25
|
+
return refresh(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId);
|
|
26
|
+
}
|
|
27
|
+
preKeygen(ctx, partnerId, pregenIdentifier, pregenIdentifierType, type, secretKey, sessionCookie) {
|
|
28
|
+
return preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, false, partnerId, sessionCookie);
|
|
29
|
+
}
|
|
30
|
+
signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc) {
|
|
31
|
+
return signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc);
|
|
32
|
+
}
|
|
33
|
+
signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
34
|
+
return signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS);
|
|
35
|
+
}
|
|
36
|
+
sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
37
|
+
return 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 ed25519Keygen(ctx, userId, sessionCookie, emailProps);
|
|
44
|
+
}
|
|
45
|
+
ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
|
|
46
|
+
return ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie);
|
|
47
|
+
}
|
|
48
|
+
ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
|
|
49
|
+
return ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie);
|
|
50
|
+
}
|
|
51
|
+
openPopup(popupUrl, opts) {
|
|
52
|
+
if (typeof window === "undefined") {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (opts) {
|
|
56
|
+
const { type } = opts;
|
|
57
|
+
const popUpWidth = 550;
|
|
58
|
+
let popUpHeight;
|
|
59
|
+
switch (type) {
|
|
60
|
+
case PopupType.LOGIN_PASSKEY: {
|
|
61
|
+
popUpHeight = 798;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case PopupType.CREATE_PASSKEY: {
|
|
65
|
+
popUpHeight = 464;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case PopupType.SIGN_MESSAGE_REVIEW: {
|
|
69
|
+
popUpHeight = 585;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case PopupType.SIGN_TRANSACTION_REVIEW: {
|
|
73
|
+
popUpHeight = 750;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case PopupType.OAUTH:
|
|
77
|
+
default: {
|
|
78
|
+
popUpHeight = 768;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const dualScreenLeft = window.screenLeft !== void 0 ? window.screenLeft : window.screenX;
|
|
83
|
+
const dualScreenTop = window.screenTop !== void 0 ? window.screenTop : window.screenY;
|
|
84
|
+
const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
|
|
85
|
+
const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
|
|
86
|
+
const left = (width - popUpWidth) / 2 + dualScreenLeft;
|
|
87
|
+
const top = (height - popUpHeight) / 2 + dualScreenTop;
|
|
88
|
+
const windowFeatures = `toolbar=no, menubar=no, width=${popUpWidth},
|
|
89
|
+
height=${popUpHeight}, top=${top}, left=${left}`;
|
|
90
|
+
let popupWindow = window.open(popupUrl, type.toString(), windowFeatures);
|
|
91
|
+
if (!popupWindow) {
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
popupWindow = window.open(popupUrl, "_blank");
|
|
94
|
+
}, 0);
|
|
95
|
+
}
|
|
96
|
+
return popupWindow;
|
|
97
|
+
} else {
|
|
98
|
+
const popupWindow = window.open(popupUrl, "popup", "popup=true,width=400,height=500");
|
|
99
|
+
if (!popupWindow) {
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
window.open(popupUrl, "_blank");
|
|
102
|
+
}, 0);
|
|
103
|
+
}
|
|
104
|
+
return popupWindow;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
WebUtils
|
|
110
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __typeError = (msg) => {
|
|
3
|
+
throw TypeError(msg);
|
|
4
|
+
};
|
|
5
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
6
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
7
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
8
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
9
|
+
var __async = (__this, __arguments, generator) => {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
var fulfilled = (value) => {
|
|
12
|
+
try {
|
|
13
|
+
step(generator.next(value));
|
|
14
|
+
} catch (e) {
|
|
15
|
+
reject(e);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var rejected = (value) => {
|
|
19
|
+
try {
|
|
20
|
+
step(generator.throw(value));
|
|
21
|
+
} catch (e) {
|
|
22
|
+
reject(e);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
26
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
__privateGet,
|
|
32
|
+
__privateAdd,
|
|
33
|
+
__privateSet,
|
|
34
|
+
__async
|
|
35
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__async
|
|
4
|
+
} from "../chunk-WLGKV3EF.js";
|
|
5
|
+
import base64url from "base64url";
|
|
6
|
+
import * as cbor from "cbor-web";
|
|
7
|
+
import forge from "node-forge";
|
|
8
|
+
import { getPortalDomain } from "@getpara/core-sdk";
|
|
9
|
+
const ES256_ALGORITHM = -7;
|
|
10
|
+
const RS256_ALGORITHM = -257;
|
|
11
|
+
function publicKeyCredentialToJSON(pubKeyCred) {
|
|
12
|
+
if (pubKeyCred instanceof ArrayBuffer || ArrayBuffer.isView(pubKeyCred)) {
|
|
13
|
+
return base64url.encode(pubKeyCred);
|
|
14
|
+
} else if (pubKeyCred instanceof Array) {
|
|
15
|
+
return pubKeyCred.map(publicKeyCredentialToJSON);
|
|
16
|
+
} else if (pubKeyCred instanceof Object) {
|
|
17
|
+
const obj = {};
|
|
18
|
+
for (const key in pubKeyCred) {
|
|
19
|
+
obj[key] = publicKeyCredentialToJSON(pubKeyCred[key]);
|
|
20
|
+
}
|
|
21
|
+
return obj;
|
|
22
|
+
} else return pubKeyCred;
|
|
23
|
+
}
|
|
24
|
+
function parseMakeCredAuthData(buffer) {
|
|
25
|
+
const rpIdHash = buffer.slice(0, 32);
|
|
26
|
+
buffer = buffer.slice(32);
|
|
27
|
+
const flagsBuf = buffer.slice(0, 1);
|
|
28
|
+
buffer = buffer.slice(1);
|
|
29
|
+
const flags = flagsBuf[0];
|
|
30
|
+
const counterBuf = buffer.slice(0, 4);
|
|
31
|
+
buffer = buffer.slice(4);
|
|
32
|
+
const counter = counterBuf.readUInt32BE(0);
|
|
33
|
+
const aaguid = buffer.slice(0, 16);
|
|
34
|
+
buffer = buffer.slice(16);
|
|
35
|
+
const credIDLenBuf = buffer.slice(0, 2);
|
|
36
|
+
buffer = buffer.slice(2);
|
|
37
|
+
const credIDLen = credIDLenBuf.readUInt16BE(0);
|
|
38
|
+
const credID = buffer.slice(0, credIDLen);
|
|
39
|
+
buffer = buffer.slice(credIDLen);
|
|
40
|
+
const COSEPublicKey = buffer;
|
|
41
|
+
return {
|
|
42
|
+
rpIdHash,
|
|
43
|
+
flagsBuf,
|
|
44
|
+
flags,
|
|
45
|
+
counter,
|
|
46
|
+
counterBuf,
|
|
47
|
+
aaguid,
|
|
48
|
+
credID,
|
|
49
|
+
COSEPublicKey
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function parseAttestationObject(attestationObject) {
|
|
53
|
+
const attestationObjectBuffer = base64url.toBuffer(attestationObject);
|
|
54
|
+
return cbor.decodeAllSync(attestationObjectBuffer)[0];
|
|
55
|
+
}
|
|
56
|
+
function COSEECDSAtoPKCS(COSEPublicKey) {
|
|
57
|
+
const coseStruct = cbor.decodeAllSync(COSEPublicKey)[0];
|
|
58
|
+
const tag = Buffer.from([4]);
|
|
59
|
+
const x = coseStruct.get(-2);
|
|
60
|
+
const y = coseStruct.get(-3);
|
|
61
|
+
return Buffer.concat([tag, x, y]);
|
|
62
|
+
}
|
|
63
|
+
function COSERSAtoPKCS(COSEPublicKey) {
|
|
64
|
+
const coseStruct = cbor.decodeAllSync(COSEPublicKey)[0];
|
|
65
|
+
const n = coseStruct.get(-1);
|
|
66
|
+
const e = coseStruct.get(-2);
|
|
67
|
+
const nForge = forge.util.createBuffer(n.toString("binary"));
|
|
68
|
+
const eForge = forge.util.createBuffer(e.toString("binary"));
|
|
69
|
+
const publicKey = forge.pki.setRsaPublicKey(
|
|
70
|
+
new forge.jsbn.BigInteger(nForge.toHex(), 16),
|
|
71
|
+
new forge.jsbn.BigInteger(eForge.toHex(), 16)
|
|
72
|
+
);
|
|
73
|
+
return Buffer.from(forge.pki.publicKeyToPem(publicKey), "utf-8");
|
|
74
|
+
}
|
|
75
|
+
function parseCredentialCreationRes(creds, algorithm) {
|
|
76
|
+
const parsedAttestation = parseAttestationObject(creds.response.attestationObject);
|
|
77
|
+
const { COSEPublicKey, aaguid } = parseMakeCredAuthData(parsedAttestation.authData);
|
|
78
|
+
if (algorithm === RS256_ALGORITHM) {
|
|
79
|
+
return {
|
|
80
|
+
cosePublicKey: base64url.encode(COSERSAtoPKCS(COSEPublicKey)),
|
|
81
|
+
clientDataJSON: creds.response.clientDataJSON,
|
|
82
|
+
aaguid: aaguid.toString("hex")
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
cosePublicKey: base64url.encode(COSEECDSAtoPKCS(COSEPublicKey)),
|
|
87
|
+
clientDataJSON: creds.response.clientDataJSON,
|
|
88
|
+
aaguid: aaguid.toString("hex")
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function generateUserHandle() {
|
|
92
|
+
const userHandle = new Uint8Array(32);
|
|
93
|
+
window.crypto.getRandomValues(userHandle);
|
|
94
|
+
return userHandle;
|
|
95
|
+
}
|
|
96
|
+
function createCredential(env, userId, identifier, isE2E) {
|
|
97
|
+
return __async(this, null, function* () {
|
|
98
|
+
if (typeof navigator === "undefined") {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const userHandle = generateUserHandle();
|
|
102
|
+
const createCredentialDefaultArgs = {
|
|
103
|
+
publicKey: {
|
|
104
|
+
authenticatorSelection: {
|
|
105
|
+
authenticatorAttachment: "platform",
|
|
106
|
+
requireResidentKey: true,
|
|
107
|
+
residentKey: "required",
|
|
108
|
+
userVerification: "required"
|
|
109
|
+
},
|
|
110
|
+
rp: {
|
|
111
|
+
id: getPortalDomain(env, isE2E),
|
|
112
|
+
name: "Para"
|
|
113
|
+
},
|
|
114
|
+
user: {
|
|
115
|
+
id: userHandle,
|
|
116
|
+
name: identifier,
|
|
117
|
+
displayName: identifier
|
|
118
|
+
},
|
|
119
|
+
pubKeyCredParams: [
|
|
120
|
+
{ type: "public-key", alg: ES256_ALGORITHM },
|
|
121
|
+
// RS256_ALGORITHM should only be needed for windows hello
|
|
122
|
+
{ type: "public-key", alg: RS256_ALGORITHM }
|
|
123
|
+
],
|
|
124
|
+
attestation: "direct",
|
|
125
|
+
timeout: 6e4,
|
|
126
|
+
// TODO: don't think we really get value from verifying this, but should revisit
|
|
127
|
+
challenge: Buffer.from(userId, "utf-8")
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const credential = yield navigator.credentials.create(createCredentialDefaultArgs);
|
|
131
|
+
const algorithm = credential.response.getPublicKeyAlgorithm ? credential.response.getPublicKeyAlgorithm() : ES256_ALGORITHM;
|
|
132
|
+
const userHandleEncoded = base64url.encode(Buffer.from(userHandle));
|
|
133
|
+
return {
|
|
134
|
+
creds: publicKeyCredentialToJSON(credential),
|
|
135
|
+
userHandle: userHandleEncoded,
|
|
136
|
+
algorithm
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function generateSignature(env, challenge, allowedPublicKeys, isE2E) {
|
|
141
|
+
return __async(this, null, function* () {
|
|
142
|
+
const getCredentialDefaultArgs = {
|
|
143
|
+
publicKey: {
|
|
144
|
+
timeout: 6e4,
|
|
145
|
+
challenge: Buffer.from(challenge, "base64"),
|
|
146
|
+
allowCredentials: allowedPublicKeys.map((key) => ({
|
|
147
|
+
id: base64url.toBuffer(key),
|
|
148
|
+
type: "public-key"
|
|
149
|
+
})),
|
|
150
|
+
userVerification: "required",
|
|
151
|
+
rpId: getPortalDomain(env, isE2E)
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const assertation = yield navigator.credentials.get(getCredentialDefaultArgs);
|
|
155
|
+
return publicKeyCredentialToJSON(assertation);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
export {
|
|
159
|
+
createCredential,
|
|
160
|
+
generateSignature,
|
|
161
|
+
parseCredentialCreationRes
|
|
162
|
+
};
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "./chunk-WLGKV3EF.js";
|
|
3
|
+
class TransactionReviewError extends Error {
|
|
4
|
+
constructor(transactionReviewUrl) {
|
|
5
|
+
super("transaction review error");
|
|
6
|
+
this.name = "TransactionReviewError";
|
|
7
|
+
this.transactionReviewUrl = transactionReviewUrl;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
TransactionReviewError
|
|
12
|
+
};
|