@worldcoin/idkit-core 2.0.2 → 4.0.0-dev.777cdbe
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/README.md +101 -0
- package/dist/idkit_wasm_bg.wasm +0 -0
- package/dist/index.cjs +2113 -0
- package/dist/index.d.cts +763 -0
- package/dist/index.d.ts +763 -0
- package/dist/index.js +2098 -0
- package/package.json +34 -62
- package/LICENSE +0 -7
- package/build/chunk-HZ2SQA5V.js +0 -50
- package/build/config-fuwC_Hia.d.cts +0 -41
- package/build/config-fuwC_Hia.d.ts +0 -41
- package/build/index.cjs +0 -331
- package/build/index.d.cts +0 -30
- package/build/index.d.ts +0 -30
- package/build/index.js +0 -266
- package/build/lib/backend.cjs +0 -70
- package/build/lib/backend.d.cts +0 -12
- package/build/lib/backend.d.ts +0 -12
- package/build/lib/backend.js +0 -30
- package/build/lib/hashing.cjs +0 -78
- package/build/lib/hashing.d.cts +0 -21
- package/build/lib/hashing.d.ts +0 -21
- package/build/lib/hashing.js +0 -14
- package/build/result-BZ4QXOc2.d.cts +0 -35
- package/build/result-CqgtArQe.d.ts +0 -35
package/package.json
CHANGED
|
@@ -1,78 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@worldcoin/idkit-core",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"private": false,
|
|
7
|
-
"description": "The identity SDK. Privacy-preserving identity and proof of personhood with World ID.",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/worldcoin/idkit-js",
|
|
11
|
-
"directory": "packages/core"
|
|
12
|
-
},
|
|
3
|
+
"version": "4.0.0-dev.777cdbe",
|
|
4
|
+
"description": "Core IDKit SDK for World ID - Pure TypeScript, no dependencies",
|
|
13
5
|
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
14
9
|
"exports": {
|
|
15
10
|
".": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"require": "./
|
|
19
|
-
},
|
|
20
|
-
"./hashing": {
|
|
21
|
-
"import": "./build/lib/hashing.js",
|
|
22
|
-
"types": "./build/lib/hashing.d.ts",
|
|
23
|
-
"require": "./build/lib/hashing.cjs"
|
|
24
|
-
},
|
|
25
|
-
"./backend": {
|
|
26
|
-
"import": "./build/lib/backend.js",
|
|
27
|
-
"types": "./build/lib/backend.d.ts",
|
|
28
|
-
"require": "./build/lib/backend.cjs"
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
29
14
|
}
|
|
30
15
|
},
|
|
31
|
-
"typesVersions": {
|
|
32
|
-
"*": {
|
|
33
|
-
"backend": [
|
|
34
|
-
"./build/lib/backend.d.ts"
|
|
35
|
-
],
|
|
36
|
-
"hashing": [
|
|
37
|
-
"./build/lib/hashing.d.ts"
|
|
38
|
-
],
|
|
39
|
-
"*": [
|
|
40
|
-
"./build/index.d.ts"
|
|
41
|
-
]
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
"publishConfig": {
|
|
45
|
-
"access": "public"
|
|
46
|
-
},
|
|
47
|
-
"engines": {
|
|
48
|
-
"node": ">=12.4"
|
|
49
|
-
},
|
|
50
16
|
"files": [
|
|
51
|
-
"
|
|
52
|
-
"README.md"
|
|
17
|
+
"dist"
|
|
53
18
|
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build:wasm": "cd ../../../ && ./scripts/build-wasm.sh",
|
|
21
|
+
"build:ts": "tsup",
|
|
22
|
+
"build": "npm run build:wasm && npm run build:ts",
|
|
23
|
+
"dev": "tsup --watch",
|
|
24
|
+
"type-check": "tsc --noEmit",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:watch": "vitest",
|
|
27
|
+
"test:coverage": "vitest run --coverage"
|
|
28
|
+
},
|
|
54
29
|
"keywords": [
|
|
30
|
+
"worldcoin",
|
|
31
|
+
"world-id",
|
|
32
|
+
"idkit",
|
|
55
33
|
"identity",
|
|
56
|
-
"ID",
|
|
57
|
-
"web3",
|
|
58
34
|
"proof-of-personhood",
|
|
59
|
-
"
|
|
35
|
+
"zero-knowledge"
|
|
60
36
|
],
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
"
|
|
37
|
+
"author": "Tools for Humanity",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/worldcoin/idkit"
|
|
66
42
|
},
|
|
67
43
|
"devDependencies": {
|
|
68
|
-
"@
|
|
69
|
-
"@
|
|
70
|
-
"tsup": "^8.1
|
|
71
|
-
"typescript": "^5.3
|
|
72
|
-
|
|
73
|
-
"scripts": {
|
|
74
|
-
"build": "tsup",
|
|
75
|
-
"dev": "tsup --watch",
|
|
76
|
-
"lint": "eslint src --ext .ts"
|
|
44
|
+
"@types/node": "^20.19.30",
|
|
45
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
46
|
+
"tsup": "^8.5.1",
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"vitest": "^4.0.18"
|
|
77
49
|
}
|
|
78
|
-
}
|
|
50
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2022 Worldcoin Foundation
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/build/chunk-HZ2SQA5V.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// src/lib/hashing.ts
|
|
2
|
-
import { Buffer } from "buffer/index.js";
|
|
3
|
-
import { AbiParameters, Bytes, Hex, Hash } from "ox";
|
|
4
|
-
function hashToField(input) {
|
|
5
|
-
if (Bytes.validate(input) || Hex.validate(input)) return hashEncodedBytes(input);
|
|
6
|
-
return hashString(input);
|
|
7
|
-
}
|
|
8
|
-
function packAndEncode(input) {
|
|
9
|
-
const [types, values] = input.reduce(
|
|
10
|
-
([types2, values2], [type, value]) => {
|
|
11
|
-
types2.push(type);
|
|
12
|
-
values2.push(value);
|
|
13
|
-
return [types2, values2];
|
|
14
|
-
},
|
|
15
|
-
[[], []]
|
|
16
|
-
);
|
|
17
|
-
return hashEncodedBytes(AbiParameters.encodePacked(types, values));
|
|
18
|
-
}
|
|
19
|
-
function hashString(input) {
|
|
20
|
-
const bytesInput = Buffer.from(input);
|
|
21
|
-
return hashEncodedBytes(bytesInput);
|
|
22
|
-
}
|
|
23
|
-
function hashEncodedBytes(input) {
|
|
24
|
-
const hash = BigInt(Hash.keccak256(input, { as: "Hex" })) >> 8n;
|
|
25
|
-
const rawDigest = hash.toString(16);
|
|
26
|
-
return { hash, digest: `0x${rawDigest.padStart(64, "0")}` };
|
|
27
|
-
}
|
|
28
|
-
var solidityEncode = (types, values) => {
|
|
29
|
-
if (types.length !== values.length) {
|
|
30
|
-
throw new Error("Types and values arrays must have the same length.");
|
|
31
|
-
}
|
|
32
|
-
return { types, values };
|
|
33
|
-
};
|
|
34
|
-
var generateSignal = (signal) => {
|
|
35
|
-
if (!signal || typeof signal === "string") return hashToField(signal ?? "");
|
|
36
|
-
return packAndEncode(signal.types.map((type, index) => [type, signal.values[index]]));
|
|
37
|
-
};
|
|
38
|
-
var encodeAction = (action) => {
|
|
39
|
-
if (!action) return "";
|
|
40
|
-
if (typeof action === "string") return action;
|
|
41
|
-
return action.types.map((type, index) => `${type}(${action.values[index]})`).join(",");
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export {
|
|
45
|
-
hashToField,
|
|
46
|
-
packAndEncode,
|
|
47
|
-
solidityEncode,
|
|
48
|
-
generateSignal,
|
|
49
|
-
encodeAction
|
|
50
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
declare const brand: unique symbol;
|
|
2
|
-
type Brand<T, TBrand extends string> = T & {
|
|
3
|
-
[brand]: TBrand;
|
|
4
|
-
};
|
|
5
|
-
type AbiEncodedValue = Brand<{
|
|
6
|
-
types: string[];
|
|
7
|
-
values: unknown[];
|
|
8
|
-
}, 'AbiEncodedValue'>;
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated in IDKit@1.0.0, use VerificationLevel instead
|
|
11
|
-
*/
|
|
12
|
-
declare enum CredentialType {
|
|
13
|
-
Orb = "orb",
|
|
14
|
-
SecureDocument = "secure_document",
|
|
15
|
-
Document = "document",
|
|
16
|
-
Device = "device"
|
|
17
|
-
}
|
|
18
|
-
declare enum VerificationLevel {
|
|
19
|
-
Orb = "orb",
|
|
20
|
-
SecureDocument = "secure_document",
|
|
21
|
-
Document = "document",
|
|
22
|
-
Device = "device"
|
|
23
|
-
}
|
|
24
|
-
type IDKitConfig = {
|
|
25
|
-
/** Unique identifier for the app verifying the action. This should be the app ID obtained from the Developer Portal. */
|
|
26
|
-
app_id: `app_${string}`;
|
|
27
|
-
/** Identifier for the action the user is performing. Should be left blank for [Sign in with Worldcoin](https://docs.world.org/id/sign-in). */
|
|
28
|
-
action: AbiEncodedValue | string;
|
|
29
|
-
/** The description of the specific action (shown to users in World App). Only recommended for actions created on-the-fly. */
|
|
30
|
-
action_description?: string;
|
|
31
|
-
/** Encodes data into a proof that must match when validating. Read more on the [On-chain section](https://docs.world.org/advanced/on-chain). */
|
|
32
|
-
signal?: AbiEncodedValue | string;
|
|
33
|
-
/** URL to a third-party bridge to use when connecting to the World App. Optional. */
|
|
34
|
-
bridge_url?: string;
|
|
35
|
-
/** The minimum required level of verification. Defaults to "orb". */
|
|
36
|
-
verification_level?: VerificationLevel;
|
|
37
|
-
/** Whether the app is a partner app and should allow deferred verification. Defaults to false. */
|
|
38
|
-
partner?: boolean;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export { type AbiEncodedValue as A, CredentialType as C, type IDKitConfig as I, VerificationLevel as V };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
declare const brand: unique symbol;
|
|
2
|
-
type Brand<T, TBrand extends string> = T & {
|
|
3
|
-
[brand]: TBrand;
|
|
4
|
-
};
|
|
5
|
-
type AbiEncodedValue = Brand<{
|
|
6
|
-
types: string[];
|
|
7
|
-
values: unknown[];
|
|
8
|
-
}, 'AbiEncodedValue'>;
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated in IDKit@1.0.0, use VerificationLevel instead
|
|
11
|
-
*/
|
|
12
|
-
declare enum CredentialType {
|
|
13
|
-
Orb = "orb",
|
|
14
|
-
SecureDocument = "secure_document",
|
|
15
|
-
Document = "document",
|
|
16
|
-
Device = "device"
|
|
17
|
-
}
|
|
18
|
-
declare enum VerificationLevel {
|
|
19
|
-
Orb = "orb",
|
|
20
|
-
SecureDocument = "secure_document",
|
|
21
|
-
Document = "document",
|
|
22
|
-
Device = "device"
|
|
23
|
-
}
|
|
24
|
-
type IDKitConfig = {
|
|
25
|
-
/** Unique identifier for the app verifying the action. This should be the app ID obtained from the Developer Portal. */
|
|
26
|
-
app_id: `app_${string}`;
|
|
27
|
-
/** Identifier for the action the user is performing. Should be left blank for [Sign in with Worldcoin](https://docs.world.org/id/sign-in). */
|
|
28
|
-
action: AbiEncodedValue | string;
|
|
29
|
-
/** The description of the specific action (shown to users in World App). Only recommended for actions created on-the-fly. */
|
|
30
|
-
action_description?: string;
|
|
31
|
-
/** Encodes data into a proof that must match when validating. Read more on the [On-chain section](https://docs.world.org/advanced/on-chain). */
|
|
32
|
-
signal?: AbiEncodedValue | string;
|
|
33
|
-
/** URL to a third-party bridge to use when connecting to the World App. Optional. */
|
|
34
|
-
bridge_url?: string;
|
|
35
|
-
/** The minimum required level of verification. Defaults to "orb". */
|
|
36
|
-
verification_level?: VerificationLevel;
|
|
37
|
-
/** Whether the app is a partner app and should allow deferred verification. Defaults to false. */
|
|
38
|
-
partner?: boolean;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export { type AbiEncodedValue as A, CredentialType as C, type IDKitConfig as I, VerificationLevel as V };
|
package/build/index.cjs
DELETED
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
AppErrorCodes: () => AppErrorCodes,
|
|
24
|
-
CredentialType: () => CredentialType,
|
|
25
|
-
DEFAULT_VERIFICATION_LEVEL: () => DEFAULT_VERIFICATION_LEVEL,
|
|
26
|
-
VerificationLevel: () => VerificationLevel,
|
|
27
|
-
VerificationState: () => VerificationState,
|
|
28
|
-
useWorldBridgeStore: () => useWorldBridgeStore,
|
|
29
|
-
verification_level_to_credential_types: () => verification_level_to_credential_types
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(src_exports);
|
|
32
|
-
|
|
33
|
-
// src/types/bridge.ts
|
|
34
|
-
var AppErrorCodes = /* @__PURE__ */ ((AppErrorCodes2) => {
|
|
35
|
-
AppErrorCodes2["ConnectionFailed"] = "connection_failed";
|
|
36
|
-
AppErrorCodes2["VerificationRejected"] = "verification_rejected";
|
|
37
|
-
AppErrorCodes2["MaxVerificationsReached"] = "max_verifications_reached";
|
|
38
|
-
AppErrorCodes2["CredentialUnavailable"] = "credential_unavailable";
|
|
39
|
-
AppErrorCodes2["MalformedRequest"] = "malformed_request";
|
|
40
|
-
AppErrorCodes2["InvalidNetwork"] = "invalid_network";
|
|
41
|
-
AppErrorCodes2["InclusionProofFailed"] = "inclusion_proof_failed";
|
|
42
|
-
AppErrorCodes2["InclusionProofPending"] = "inclusion_proof_pending";
|
|
43
|
-
AppErrorCodes2["UnexpectedResponse"] = "unexpected_response";
|
|
44
|
-
AppErrorCodes2["FailedByHostApp"] = "failed_by_host_app";
|
|
45
|
-
AppErrorCodes2["GenericError"] = "generic_error";
|
|
46
|
-
return AppErrorCodes2;
|
|
47
|
-
})(AppErrorCodes || {});
|
|
48
|
-
var VerificationState = /* @__PURE__ */ ((VerificationState2) => {
|
|
49
|
-
VerificationState2["PreparingClient"] = "loading_widget";
|
|
50
|
-
VerificationState2["WaitingForConnection"] = "awaiting_connection";
|
|
51
|
-
VerificationState2["WaitingForApp"] = "awaiting_app";
|
|
52
|
-
VerificationState2["Confirmed"] = "confirmed";
|
|
53
|
-
VerificationState2["Failed"] = "failed";
|
|
54
|
-
return VerificationState2;
|
|
55
|
-
})(VerificationState || {});
|
|
56
|
-
|
|
57
|
-
// src/types/config.ts
|
|
58
|
-
var CredentialType = /* @__PURE__ */ ((CredentialType2) => {
|
|
59
|
-
CredentialType2["Orb"] = "orb";
|
|
60
|
-
CredentialType2["SecureDocument"] = "secure_document";
|
|
61
|
-
CredentialType2["Document"] = "document";
|
|
62
|
-
CredentialType2["Device"] = "device";
|
|
63
|
-
return CredentialType2;
|
|
64
|
-
})(CredentialType || {});
|
|
65
|
-
var VerificationLevel = /* @__PURE__ */ ((VerificationLevel2) => {
|
|
66
|
-
VerificationLevel2["Orb"] = "orb";
|
|
67
|
-
VerificationLevel2["SecureDocument"] = "secure_document";
|
|
68
|
-
VerificationLevel2["Document"] = "document";
|
|
69
|
-
VerificationLevel2["Device"] = "device";
|
|
70
|
-
return VerificationLevel2;
|
|
71
|
-
})(VerificationLevel || {});
|
|
72
|
-
|
|
73
|
-
// src/bridge.ts
|
|
74
|
-
var import_zustand = require("zustand");
|
|
75
|
-
|
|
76
|
-
// src/lib/validation.ts
|
|
77
|
-
function validate_bridge_url(bridge_url, is_staging) {
|
|
78
|
-
try {
|
|
79
|
-
new URL(bridge_url);
|
|
80
|
-
} catch (e) {
|
|
81
|
-
return { valid: false, errors: ["Failed to parse Bridge URL."] };
|
|
82
|
-
}
|
|
83
|
-
const test_url = new URL(bridge_url);
|
|
84
|
-
const errors = [];
|
|
85
|
-
if (is_staging && ["localhost", "127.0.0.1"].includes(test_url.hostname)) {
|
|
86
|
-
console.log("Using staging app_id with localhost bridge_url. Skipping validation.");
|
|
87
|
-
return { valid: true };
|
|
88
|
-
}
|
|
89
|
-
if (test_url.protocol !== "https:") {
|
|
90
|
-
errors.push("Bridge URL must use HTTPS.");
|
|
91
|
-
}
|
|
92
|
-
if (test_url.port) {
|
|
93
|
-
errors.push("Bridge URL must use the default port (443).");
|
|
94
|
-
}
|
|
95
|
-
if (test_url.pathname !== "/") {
|
|
96
|
-
errors.push("Bridge URL must not have a path.");
|
|
97
|
-
}
|
|
98
|
-
if (test_url.search) {
|
|
99
|
-
errors.push("Bridge URL must not have query parameters.");
|
|
100
|
-
}
|
|
101
|
-
if (test_url.hash) {
|
|
102
|
-
errors.push("Bridge URL must not have a fragment.");
|
|
103
|
-
}
|
|
104
|
-
if (!test_url.hostname.endsWith(".worldcoin.org") && !test_url.hostname.endsWith(".toolsforhumanity.com")) {
|
|
105
|
-
console.warn(
|
|
106
|
-
"Bridge URL should be a subdomain of worldcoin.org or toolsforhumanity.com. The user's identity wallet may refuse to connect. This is a temporary measure and may be removed in the future."
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
if (errors.length) {
|
|
110
|
-
return { valid: false, errors };
|
|
111
|
-
}
|
|
112
|
-
return { valid: true };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// src/lib/hashing.ts
|
|
116
|
-
var import_buffer = require("buffer/index.js");
|
|
117
|
-
var import_ox = require("ox");
|
|
118
|
-
function hashToField(input) {
|
|
119
|
-
if (import_ox.Bytes.validate(input) || import_ox.Hex.validate(input)) return hashEncodedBytes(input);
|
|
120
|
-
return hashString(input);
|
|
121
|
-
}
|
|
122
|
-
function packAndEncode(input) {
|
|
123
|
-
const [types, values] = input.reduce(
|
|
124
|
-
([types2, values2], [type, value]) => {
|
|
125
|
-
types2.push(type);
|
|
126
|
-
values2.push(value);
|
|
127
|
-
return [types2, values2];
|
|
128
|
-
},
|
|
129
|
-
[[], []]
|
|
130
|
-
);
|
|
131
|
-
return hashEncodedBytes(import_ox.AbiParameters.encodePacked(types, values));
|
|
132
|
-
}
|
|
133
|
-
function hashString(input) {
|
|
134
|
-
const bytesInput = import_buffer.Buffer.from(input);
|
|
135
|
-
return hashEncodedBytes(bytesInput);
|
|
136
|
-
}
|
|
137
|
-
function hashEncodedBytes(input) {
|
|
138
|
-
const hash = BigInt(import_ox.Hash.keccak256(input, { as: "Hex" })) >> 8n;
|
|
139
|
-
const rawDigest = hash.toString(16);
|
|
140
|
-
return { hash, digest: `0x${rawDigest.padStart(64, "0")}` };
|
|
141
|
-
}
|
|
142
|
-
var generateSignal = (signal) => {
|
|
143
|
-
if (!signal || typeof signal === "string") return hashToField(signal ?? "");
|
|
144
|
-
return packAndEncode(signal.types.map((type, index) => [type, signal.values[index]]));
|
|
145
|
-
};
|
|
146
|
-
var encodeAction = (action) => {
|
|
147
|
-
if (!action) return "";
|
|
148
|
-
if (typeof action === "string") return action;
|
|
149
|
-
return action.types.map((type, index) => `${type}(${action.values[index]})`).join(",");
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
// src/lib/utils.ts
|
|
153
|
-
var import_buffer2 = require("buffer/index.js");
|
|
154
|
-
var DEFAULT_VERIFICATION_LEVEL = "orb" /* Orb */;
|
|
155
|
-
var buffer_encode = (buffer) => {
|
|
156
|
-
return import_buffer2.Buffer.from(buffer).toString("base64");
|
|
157
|
-
};
|
|
158
|
-
var buffer_decode = (encoded) => {
|
|
159
|
-
return import_buffer2.Buffer.from(encoded, "base64");
|
|
160
|
-
};
|
|
161
|
-
var verification_level_to_credential_types = (verification_level) => {
|
|
162
|
-
switch (verification_level) {
|
|
163
|
-
case "device" /* Device */:
|
|
164
|
-
return ["orb" /* Orb */, "device" /* Device */];
|
|
165
|
-
case "document" /* Document */:
|
|
166
|
-
return ["document" /* Document */, "secure_document" /* SecureDocument */, "orb" /* Orb */];
|
|
167
|
-
case "secure_document" /* SecureDocument */:
|
|
168
|
-
return ["secure_document" /* SecureDocument */, "orb" /* Orb */];
|
|
169
|
-
case "orb" /* Orb */:
|
|
170
|
-
return ["orb" /* Orb */];
|
|
171
|
-
default:
|
|
172
|
-
throw new Error(`Unknown verification level: ${verification_level}`);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
var credential_type_to_verification_level = (credential_type) => {
|
|
176
|
-
switch (credential_type) {
|
|
177
|
-
case "orb" /* Orb */:
|
|
178
|
-
return "orb" /* Orb */;
|
|
179
|
-
case "secure_document" /* SecureDocument */:
|
|
180
|
-
return "secure_document" /* SecureDocument */;
|
|
181
|
-
case "document" /* Document */:
|
|
182
|
-
return "document" /* Document */;
|
|
183
|
-
case "device" /* Device */:
|
|
184
|
-
return "device" /* Device */;
|
|
185
|
-
default:
|
|
186
|
-
throw new Error(`Unknown credential_type: ${credential_type}`);
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
// src/lib/crypto.ts
|
|
191
|
-
var encoder = new TextEncoder();
|
|
192
|
-
var decoder = new TextDecoder();
|
|
193
|
-
var generateKey = async () => {
|
|
194
|
-
return {
|
|
195
|
-
iv: window.crypto.getRandomValues(new Uint8Array(12)),
|
|
196
|
-
key: await window.crypto.subtle.generateKey({ name: "AES-GCM", length: 256 }, true, ["encrypt", "decrypt"])
|
|
197
|
-
};
|
|
198
|
-
};
|
|
199
|
-
var exportKey = async (key) => {
|
|
200
|
-
return buffer_encode(await window.crypto.subtle.exportKey("raw", key));
|
|
201
|
-
};
|
|
202
|
-
var encryptRequest = async (key, iv, request) => {
|
|
203
|
-
return {
|
|
204
|
-
iv: buffer_encode(iv),
|
|
205
|
-
payload: buffer_encode(
|
|
206
|
-
await window.crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, encoder.encode(request))
|
|
207
|
-
)
|
|
208
|
-
};
|
|
209
|
-
};
|
|
210
|
-
var decryptResponse = async (key, iv, payload) => {
|
|
211
|
-
return decoder.decode(await window.crypto.subtle.decrypt({ name: "AES-GCM", iv }, key, buffer_decode(payload)));
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
// src/bridge.ts
|
|
215
|
-
var DEFAULT_BRIDGE_URL = "https://bridge.worldcoin.org";
|
|
216
|
-
var useWorldBridgeStore = (0, import_zustand.create)((set, get) => ({
|
|
217
|
-
iv: null,
|
|
218
|
-
key: null,
|
|
219
|
-
result: null,
|
|
220
|
-
errorCode: null,
|
|
221
|
-
requestId: null,
|
|
222
|
-
connectorURI: null,
|
|
223
|
-
bridge_url: DEFAULT_BRIDGE_URL,
|
|
224
|
-
verificationState: "loading_widget" /* PreparingClient */,
|
|
225
|
-
createClient: async ({ bridge_url, app_id, verification_level, action_description, action, signal, partner }) => {
|
|
226
|
-
const { key, iv } = await generateKey();
|
|
227
|
-
if (bridge_url) {
|
|
228
|
-
const validation = validate_bridge_url(bridge_url, app_id.includes("staging"));
|
|
229
|
-
if (!validation.valid) {
|
|
230
|
-
console.error(validation.errors.join("\n"));
|
|
231
|
-
set({ verificationState: "failed" /* Failed */ });
|
|
232
|
-
throw new Error("Invalid bridge_url. Please check the console for more details.");
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
const res = await fetch(new URL("/request", bridge_url ?? DEFAULT_BRIDGE_URL), {
|
|
236
|
-
method: "POST",
|
|
237
|
-
headers: { "Content-Type": "application/json" },
|
|
238
|
-
body: JSON.stringify(
|
|
239
|
-
await encryptRequest(
|
|
240
|
-
key,
|
|
241
|
-
iv,
|
|
242
|
-
JSON.stringify({
|
|
243
|
-
app_id,
|
|
244
|
-
action_description,
|
|
245
|
-
action: encodeAction(action),
|
|
246
|
-
signal: generateSignal(signal).digest,
|
|
247
|
-
credential_types: verification_level_to_credential_types(
|
|
248
|
-
verification_level ?? DEFAULT_VERIFICATION_LEVEL
|
|
249
|
-
),
|
|
250
|
-
verification_level: verification_level ?? DEFAULT_VERIFICATION_LEVEL
|
|
251
|
-
})
|
|
252
|
-
)
|
|
253
|
-
)
|
|
254
|
-
});
|
|
255
|
-
if (!res.ok) {
|
|
256
|
-
set({ verificationState: "failed" /* Failed */ });
|
|
257
|
-
throw new Error("Failed to create client");
|
|
258
|
-
}
|
|
259
|
-
const { request_id } = await res.json();
|
|
260
|
-
set({
|
|
261
|
-
iv,
|
|
262
|
-
key,
|
|
263
|
-
requestId: request_id,
|
|
264
|
-
bridge_url: bridge_url ?? DEFAULT_BRIDGE_URL,
|
|
265
|
-
verificationState: "awaiting_connection" /* WaitingForConnection */,
|
|
266
|
-
connectorURI: `https://world.org/verify?t=wld&i=${request_id}&k=${encodeURIComponent(
|
|
267
|
-
await exportKey(key)
|
|
268
|
-
)}${bridge_url && bridge_url !== DEFAULT_BRIDGE_URL ? `&b=${encodeURIComponent(bridge_url)}` : ""}${partner ? `&partner=${encodeURIComponent(true)}` : ""}`
|
|
269
|
-
});
|
|
270
|
-
},
|
|
271
|
-
pollForUpdates: async () => {
|
|
272
|
-
const key = get().key;
|
|
273
|
-
if (!key) throw new Error("No keypair found. Please call `createClient` first.");
|
|
274
|
-
const res = await fetch(new URL(`/response/${get().requestId}`, get().bridge_url));
|
|
275
|
-
if (!res.ok) {
|
|
276
|
-
return set({
|
|
277
|
-
errorCode: "connection_failed" /* ConnectionFailed */,
|
|
278
|
-
verificationState: "failed" /* Failed */
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
const { response, status } = await res.json();
|
|
282
|
-
if (status != "completed" /* Completed */) {
|
|
283
|
-
return set({
|
|
284
|
-
verificationState: status == "retrieved" /* Retrieved */ ? "awaiting_app" /* WaitingForApp */ : "awaiting_connection" /* WaitingForConnection */
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
let result = JSON.parse(
|
|
288
|
-
await decryptResponse(key, buffer_decode(response.iv), response.payload)
|
|
289
|
-
);
|
|
290
|
-
if ("error_code" in result) {
|
|
291
|
-
return set({
|
|
292
|
-
errorCode: result.error_code,
|
|
293
|
-
verificationState: "failed" /* Failed */
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
if ("credential_type" in result) {
|
|
297
|
-
result = {
|
|
298
|
-
verification_level: credential_type_to_verification_level(result.credential_type),
|
|
299
|
-
...result
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
set({
|
|
303
|
-
result,
|
|
304
|
-
key: null,
|
|
305
|
-
requestId: null,
|
|
306
|
-
connectorURI: null,
|
|
307
|
-
verificationState: "confirmed" /* Confirmed */
|
|
308
|
-
});
|
|
309
|
-
},
|
|
310
|
-
reset: () => {
|
|
311
|
-
set({
|
|
312
|
-
iv: null,
|
|
313
|
-
key: null,
|
|
314
|
-
result: null,
|
|
315
|
-
errorCode: null,
|
|
316
|
-
requestId: null,
|
|
317
|
-
connectorURI: null,
|
|
318
|
-
verificationState: "loading_widget" /* PreparingClient */
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
}));
|
|
322
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
323
|
-
0 && (module.exports = {
|
|
324
|
-
AppErrorCodes,
|
|
325
|
-
CredentialType,
|
|
326
|
-
DEFAULT_VERIFICATION_LEVEL,
|
|
327
|
-
VerificationLevel,
|
|
328
|
-
VerificationState,
|
|
329
|
-
useWorldBridgeStore,
|
|
330
|
-
verification_level_to_credential_types
|
|
331
|
-
});
|
package/build/index.d.cts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { I as ISuccessResult, A as AppErrorCodes, V as VerificationState } from './result-BZ4QXOc2.cjs';
|
|
2
|
-
export { a as IErrorState } from './result-BZ4QXOc2.cjs';
|
|
3
|
-
import { I as IDKitConfig, V as VerificationLevel } from './config-fuwC_Hia.cjs';
|
|
4
|
-
export { A as AbiEncodedValue, C as CredentialType } from './config-fuwC_Hia.cjs';
|
|
5
|
-
import * as zustand from 'zustand';
|
|
6
|
-
|
|
7
|
-
type WorldBridgeStore = {
|
|
8
|
-
bridge_url: string;
|
|
9
|
-
iv: Uint8Array | null;
|
|
10
|
-
key: CryptoKey | null;
|
|
11
|
-
requestId: string | null;
|
|
12
|
-
connectorURI: string | null;
|
|
13
|
-
result: ISuccessResult | null;
|
|
14
|
-
errorCode: AppErrorCodes | null;
|
|
15
|
-
verificationState: VerificationState;
|
|
16
|
-
createClient: (config: IDKitConfig) => Promise<void>;
|
|
17
|
-
pollForUpdates: () => Promise<void>;
|
|
18
|
-
reset: () => void;
|
|
19
|
-
};
|
|
20
|
-
declare const useWorldBridgeStore: zustand.UseBoundStore<zustand.StoreApi<WorldBridgeStore>>;
|
|
21
|
-
|
|
22
|
-
declare const DEFAULT_VERIFICATION_LEVEL = VerificationLevel.Orb;
|
|
23
|
-
/**
|
|
24
|
-
* @dev use to convert verification level to accepted credential types for proof request
|
|
25
|
-
* @param verification_level
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
declare const verification_level_to_credential_types: (verification_level: VerificationLevel) => string[];
|
|
29
|
-
|
|
30
|
-
export { AppErrorCodes, DEFAULT_VERIFICATION_LEVEL, IDKitConfig, ISuccessResult, VerificationLevel, VerificationState, type WorldBridgeStore, useWorldBridgeStore, verification_level_to_credential_types };
|
package/build/index.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { I as ISuccessResult, A as AppErrorCodes, V as VerificationState } from './result-CqgtArQe.js';
|
|
2
|
-
export { a as IErrorState } from './result-CqgtArQe.js';
|
|
3
|
-
import { I as IDKitConfig, V as VerificationLevel } from './config-fuwC_Hia.js';
|
|
4
|
-
export { A as AbiEncodedValue, C as CredentialType } from './config-fuwC_Hia.js';
|
|
5
|
-
import * as zustand from 'zustand';
|
|
6
|
-
|
|
7
|
-
type WorldBridgeStore = {
|
|
8
|
-
bridge_url: string;
|
|
9
|
-
iv: Uint8Array | null;
|
|
10
|
-
key: CryptoKey | null;
|
|
11
|
-
requestId: string | null;
|
|
12
|
-
connectorURI: string | null;
|
|
13
|
-
result: ISuccessResult | null;
|
|
14
|
-
errorCode: AppErrorCodes | null;
|
|
15
|
-
verificationState: VerificationState;
|
|
16
|
-
createClient: (config: IDKitConfig) => Promise<void>;
|
|
17
|
-
pollForUpdates: () => Promise<void>;
|
|
18
|
-
reset: () => void;
|
|
19
|
-
};
|
|
20
|
-
declare const useWorldBridgeStore: zustand.UseBoundStore<zustand.StoreApi<WorldBridgeStore>>;
|
|
21
|
-
|
|
22
|
-
declare const DEFAULT_VERIFICATION_LEVEL = VerificationLevel.Orb;
|
|
23
|
-
/**
|
|
24
|
-
* @dev use to convert verification level to accepted credential types for proof request
|
|
25
|
-
* @param verification_level
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
declare const verification_level_to_credential_types: (verification_level: VerificationLevel) => string[];
|
|
29
|
-
|
|
30
|
-
export { AppErrorCodes, DEFAULT_VERIFICATION_LEVEL, IDKitConfig, ISuccessResult, VerificationLevel, VerificationState, type WorldBridgeStore, useWorldBridgeStore, verification_level_to_credential_types };
|