@tomo-inc/cubist-wallet-sdk 0.0.4
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/CHANGELOG.md +11 -0
- package/README.md +14 -0
- package/RN.md +54 -0
- package/package.json +40 -0
- package/project.json +59 -0
- package/src/__tests__/cube-mfa.test.ts +64 -0
- package/src/api.ts +64 -0
- package/src/const.ts +96 -0
- package/src/cube-account.ts +324 -0
- package/src/cube-connect.ts +22 -0
- package/src/cube-export.ts +125 -0
- package/src/cube-libs.ts +29 -0
- package/src/cube-mfa.ts +494 -0
- package/src/cube-sign.ts +210 -0
- package/src/export-key.ts +150 -0
- package/src/index.ts +15 -0
- package/src/passkey.ts +221 -0
- package/src/signature.ts +23 -0
- package/src/types.ts +269 -0
- package/src/utils.ts +71 -0
- package/tsconfig.json +15 -0
- package/tsup.config.ts +23 -0
package/src/utils.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const applyLocalDevFixes = (
|
|
2
|
+
type: "add" | "approval",
|
|
3
|
+
challenge: any,
|
|
4
|
+
{ userId, rpId, fidoName }: { userId: string; rpId: string; fidoName: string },
|
|
5
|
+
) => {
|
|
6
|
+
rpId = rpId || window.location.hostname;
|
|
7
|
+
const { host, protocol } = window.location;
|
|
8
|
+
const isNotHttp = protocol !== "https:" && protocol !== "http:"; //browser plugin
|
|
9
|
+
const isLocal = host.indexOf("localhost:") === 0;
|
|
10
|
+
|
|
11
|
+
challenge.options = challenge?.options || {};
|
|
12
|
+
challenge.options.rp = challenge.options.rp || {};
|
|
13
|
+
challenge.options.rp.id = rpId;
|
|
14
|
+
challenge.options.rpId = rpId;
|
|
15
|
+
|
|
16
|
+
if (isNotHttp || isLocal) {
|
|
17
|
+
if (challenge?.options?.rp?.id) {
|
|
18
|
+
delete challenge.options.rp.id;
|
|
19
|
+
}
|
|
20
|
+
if (challenge?.options?.rpId) {
|
|
21
|
+
delete challenge.options.rpId;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
challenge.options.timeout = 60000;
|
|
26
|
+
challenge.options.attestation = "none";
|
|
27
|
+
|
|
28
|
+
const user = challenge.options?.user || {};
|
|
29
|
+
if (type === "add") {
|
|
30
|
+
user.id = user.id || new TextEncoder().encode(userId);
|
|
31
|
+
user.name = fidoName;
|
|
32
|
+
user.displayName = fidoName;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
challenge.options.user = user;
|
|
36
|
+
return challenge;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const isSupportFido = (): boolean => {
|
|
40
|
+
if (typeof window !== "object") {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!window.isSecureContext) {
|
|
45
|
+
console.warn("WebAuthn requires a secure context (HTTPS or localhost)");
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const { navigator, PublicKeyCredential } = window;
|
|
50
|
+
|
|
51
|
+
if (!navigator?.credentials || !PublicKeyCredential) {
|
|
52
|
+
console.warn("WebAuthn API not supported");
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
if (typeof PublicKeyCredential?.isUserVerifyingPlatformAuthenticatorAvailable !== "function") {
|
|
58
|
+
console.warn("WebAuthn API not fully supported");
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (typeof PublicKeyCredential?.isConditionalMediationAvailable !== "function") {
|
|
63
|
+
console.warn("WebAuthn API not fully supported");
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.warn("Error checking WebAuthn support:", error);
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"lib": ["ES2020", "DOM"],
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"baseUrl": "./src"
|
|
13
|
+
},
|
|
14
|
+
"include": ["src"]
|
|
15
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineConfig } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: ["src/index.ts"],
|
|
5
|
+
format: ["esm", "cjs"],
|
|
6
|
+
dts: true,
|
|
7
|
+
treeshake: true,
|
|
8
|
+
clean: true,
|
|
9
|
+
platform: "browser",
|
|
10
|
+
external: [
|
|
11
|
+
"viem",
|
|
12
|
+
"axios",
|
|
13
|
+
"crypto",
|
|
14
|
+
"@tomo-inc/wallet-utils",
|
|
15
|
+
"@cubist-labs/cubesigner-sdk",
|
|
16
|
+
"@tomo-inc/cubist-sig-sdk",
|
|
17
|
+
],
|
|
18
|
+
outExtension({ format }) {
|
|
19
|
+
return {
|
|
20
|
+
js: format === "esm" ? ".js" : ".cjs",
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
});
|