@worldcoin/idkit-core 1.0.0-alpha.6 → 1.0.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/build/index.cjs +277 -0
- package/build/index.d.cts +60 -0
- package/build/lib/hashing.cjs +82 -0
- package/build/lib/hashing.d.cts +20 -0
- package/package.json +5 -4
package/build/index.cjs
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
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["Device"] = "device";
|
|
61
|
+
return CredentialType2;
|
|
62
|
+
})(CredentialType || {});
|
|
63
|
+
var VerificationLevel = /* @__PURE__ */ ((VerificationLevel2) => {
|
|
64
|
+
VerificationLevel2["Lite"] = "lite";
|
|
65
|
+
VerificationLevel2["Orb"] = "orb";
|
|
66
|
+
return VerificationLevel2;
|
|
67
|
+
})(VerificationLevel || {});
|
|
68
|
+
|
|
69
|
+
// src/bridge.ts
|
|
70
|
+
var import_zustand = require("zustand");
|
|
71
|
+
|
|
72
|
+
// src/lib/hashing.ts
|
|
73
|
+
var import_buffer = require("buffer/index.js");
|
|
74
|
+
var import_viem = require("viem");
|
|
75
|
+
function hashToField(input) {
|
|
76
|
+
if ((0, import_viem.isBytes)(input) || (0, import_viem.isHex)(input))
|
|
77
|
+
return hashEncodedBytes(input);
|
|
78
|
+
return hashString(input);
|
|
79
|
+
}
|
|
80
|
+
function packAndEncode(input) {
|
|
81
|
+
const [types, values] = input.reduce(
|
|
82
|
+
([types2, values2], [type, value]) => {
|
|
83
|
+
types2.push(type);
|
|
84
|
+
values2.push(value);
|
|
85
|
+
return [types2, values2];
|
|
86
|
+
},
|
|
87
|
+
[[], []]
|
|
88
|
+
);
|
|
89
|
+
return hashEncodedBytes((0, import_viem.encodePacked)(types, values));
|
|
90
|
+
}
|
|
91
|
+
function hashString(input) {
|
|
92
|
+
const bytesInput = import_buffer.Buffer.from(input);
|
|
93
|
+
return hashEncodedBytes(bytesInput);
|
|
94
|
+
}
|
|
95
|
+
function hashEncodedBytes(input) {
|
|
96
|
+
const hash = BigInt((0, import_viem.keccak256)(input)) >> 8n;
|
|
97
|
+
const rawDigest = hash.toString(16);
|
|
98
|
+
return { hash, digest: `0x${rawDigest.padStart(64, "0")}` };
|
|
99
|
+
}
|
|
100
|
+
var generateSignal = (signal) => {
|
|
101
|
+
if (!signal || typeof signal === "string")
|
|
102
|
+
return hashToField(signal ?? "");
|
|
103
|
+
return packAndEncode(signal.types.map((type, index) => [type, signal.values[index]]));
|
|
104
|
+
};
|
|
105
|
+
var encodeAction = (action) => {
|
|
106
|
+
if (!action)
|
|
107
|
+
return "";
|
|
108
|
+
if (typeof action === "string")
|
|
109
|
+
return action;
|
|
110
|
+
return action.types.map((type, index) => `${type}(${action.values[index]})`).join(",");
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// src/lib/utils.ts
|
|
114
|
+
var import_buffer2 = require("buffer/index.js");
|
|
115
|
+
var DEFAULT_VERIFICATION_LEVEL = "orb" /* Orb */;
|
|
116
|
+
var buffer_encode = (buffer) => {
|
|
117
|
+
return import_buffer2.Buffer.from(buffer).toString("base64");
|
|
118
|
+
};
|
|
119
|
+
var buffer_decode = (encoded) => {
|
|
120
|
+
return import_buffer2.Buffer.from(encoded, "base64");
|
|
121
|
+
};
|
|
122
|
+
var verification_level_to_credential_types = (verification_level) => {
|
|
123
|
+
switch (verification_level) {
|
|
124
|
+
case "lite" /* Lite */:
|
|
125
|
+
return ["orb" /* Orb */, "device" /* Device */];
|
|
126
|
+
case "orb" /* Orb */:
|
|
127
|
+
return ["orb" /* Orb */];
|
|
128
|
+
default:
|
|
129
|
+
throw new Error(`Unknown verification level: ${verification_level}`);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var credential_type_to_verification_level = (credential_type) => {
|
|
133
|
+
switch (credential_type) {
|
|
134
|
+
case "orb" /* Orb */:
|
|
135
|
+
return "orb" /* Orb */;
|
|
136
|
+
case "device" /* Device */:
|
|
137
|
+
return "lite" /* Lite */;
|
|
138
|
+
default:
|
|
139
|
+
throw new Error(`Unknown credential_type: ${credential_type}`);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// src/lib/crypto.ts
|
|
144
|
+
var encoder = new TextEncoder();
|
|
145
|
+
var decoder = new TextDecoder();
|
|
146
|
+
var generateKey = async () => {
|
|
147
|
+
return {
|
|
148
|
+
iv: window.crypto.getRandomValues(new Uint8Array(12)),
|
|
149
|
+
key: await window.crypto.subtle.generateKey({ name: "AES-GCM", length: 256 }, true, ["encrypt", "decrypt"])
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
var exportKey = async (key) => {
|
|
153
|
+
return buffer_encode(await window.crypto.subtle.exportKey("raw", key));
|
|
154
|
+
};
|
|
155
|
+
var encryptRequest = async (key, iv, request) => {
|
|
156
|
+
return {
|
|
157
|
+
iv: buffer_encode(iv),
|
|
158
|
+
payload: buffer_encode(
|
|
159
|
+
await window.crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, encoder.encode(request))
|
|
160
|
+
)
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
var decryptResponse = async (key, iv, payload) => {
|
|
164
|
+
return decoder.decode(await window.crypto.subtle.decrypt({ name: "AES-GCM", iv }, key, buffer_decode(payload)));
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/bridge.ts
|
|
168
|
+
var DEFAULT_BRIDGE_URL = "https://bridge.worldcoin.org";
|
|
169
|
+
var useWorldBridgeStore = (0, import_zustand.create)((set, get) => ({
|
|
170
|
+
iv: null,
|
|
171
|
+
key: null,
|
|
172
|
+
result: null,
|
|
173
|
+
errorCode: null,
|
|
174
|
+
requestId: null,
|
|
175
|
+
connectorURI: null,
|
|
176
|
+
bridge_url: DEFAULT_BRIDGE_URL,
|
|
177
|
+
verificationState: "loading_widget" /* PreparingClient */,
|
|
178
|
+
createClient: async ({ bridge_url, app_id, verification_level, action_description, action, signal }) => {
|
|
179
|
+
const { key, iv } = await generateKey();
|
|
180
|
+
const res = await fetch(`${bridge_url ?? DEFAULT_BRIDGE_URL}/request`, {
|
|
181
|
+
method: "POST",
|
|
182
|
+
headers: { "Content-Type": "application/json" },
|
|
183
|
+
body: JSON.stringify(
|
|
184
|
+
await encryptRequest(
|
|
185
|
+
key,
|
|
186
|
+
iv,
|
|
187
|
+
JSON.stringify({
|
|
188
|
+
app_id,
|
|
189
|
+
action_description,
|
|
190
|
+
action: encodeAction(action),
|
|
191
|
+
signal: generateSignal(signal).digest,
|
|
192
|
+
credential_types: verification_level_to_credential_types(
|
|
193
|
+
verification_level ?? DEFAULT_VERIFICATION_LEVEL
|
|
194
|
+
),
|
|
195
|
+
verification_level: verification_level ?? DEFAULT_VERIFICATION_LEVEL
|
|
196
|
+
})
|
|
197
|
+
)
|
|
198
|
+
)
|
|
199
|
+
});
|
|
200
|
+
if (!res.ok) {
|
|
201
|
+
set({ verificationState: "failed" /* Failed */ });
|
|
202
|
+
throw new Error("Failed to create client");
|
|
203
|
+
}
|
|
204
|
+
const { request_id } = await res.json();
|
|
205
|
+
set({
|
|
206
|
+
iv,
|
|
207
|
+
key,
|
|
208
|
+
requestId: request_id,
|
|
209
|
+
bridge_url: bridge_url ?? DEFAULT_BRIDGE_URL,
|
|
210
|
+
verificationState: "awaiting_connection" /* WaitingForConnection */,
|
|
211
|
+
connectorURI: `https://worldcoin.org/verify?t=wld&i=${request_id}&k=${encodeURIComponent(
|
|
212
|
+
await exportKey(key)
|
|
213
|
+
)}${bridge_url && bridge_url !== DEFAULT_BRIDGE_URL ? `&b=${encodeURIComponent(bridge_url)}` : ""}`
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
pollForUpdates: async () => {
|
|
217
|
+
const key = get().key;
|
|
218
|
+
if (!key)
|
|
219
|
+
throw new Error("No keypair found. Please call `createClient` first.");
|
|
220
|
+
const res = await fetch(`${get().bridge_url}/response/${get().requestId}`);
|
|
221
|
+
if (!res.ok) {
|
|
222
|
+
return set({
|
|
223
|
+
errorCode: "connection_failed" /* ConnectionFailed */,
|
|
224
|
+
verificationState: "failed" /* Failed */
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
const { response, status } = await res.json();
|
|
228
|
+
if (status != "completed" /* Completed */) {
|
|
229
|
+
return set({
|
|
230
|
+
verificationState: status == "retrieved" /* Retrieved */ ? "awaiting_app" /* WaitingForApp */ : "awaiting_connection" /* WaitingForConnection */
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
let result = JSON.parse(
|
|
234
|
+
await decryptResponse(key, buffer_decode(response.iv), response.payload)
|
|
235
|
+
);
|
|
236
|
+
if ("error_code" in result) {
|
|
237
|
+
return set({
|
|
238
|
+
errorCode: result.error_code,
|
|
239
|
+
verificationState: "failed" /* Failed */
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
if ("credential_type" in result) {
|
|
243
|
+
result = {
|
|
244
|
+
verification_level: credential_type_to_verification_level(result.credential_type),
|
|
245
|
+
...result
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
set({
|
|
249
|
+
result,
|
|
250
|
+
key: null,
|
|
251
|
+
requestId: null,
|
|
252
|
+
connectorURI: null,
|
|
253
|
+
verificationState: "confirmed" /* Confirmed */
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
reset: () => {
|
|
257
|
+
set({
|
|
258
|
+
iv: null,
|
|
259
|
+
key: null,
|
|
260
|
+
result: null,
|
|
261
|
+
errorCode: null,
|
|
262
|
+
requestId: null,
|
|
263
|
+
connectorURI: null,
|
|
264
|
+
verificationState: "loading_widget" /* PreparingClient */
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}));
|
|
268
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
269
|
+
0 && (module.exports = {
|
|
270
|
+
AppErrorCodes,
|
|
271
|
+
CredentialType,
|
|
272
|
+
DEFAULT_VERIFICATION_LEVEL,
|
|
273
|
+
VerificationLevel,
|
|
274
|
+
VerificationState,
|
|
275
|
+
useWorldBridgeStore,
|
|
276
|
+
verification_level_to_credential_types
|
|
277
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { V as VerificationLevel, I as IDKitConfig } from './config-a2bbeb0d.js';
|
|
2
|
+
export { A as AbiEncodedValue, C as CredentialType } from './config-a2bbeb0d.js';
|
|
3
|
+
import * as zustand from 'zustand';
|
|
4
|
+
|
|
5
|
+
declare enum AppErrorCodes {
|
|
6
|
+
ConnectionFailed = "connection_failed",
|
|
7
|
+
VerificationRejected = "verification_rejected",
|
|
8
|
+
MaxVerificationsReached = "max_verifications_reached",
|
|
9
|
+
CredentialUnavailable = "credential_unavailable",
|
|
10
|
+
MalformedRequest = "malformed_request",
|
|
11
|
+
InvalidNetwork = "invalid_network",
|
|
12
|
+
InclusionProofFailed = "inclusion_proof_failed",
|
|
13
|
+
InclusionProofPending = "inclusion_proof_pending",
|
|
14
|
+
UnexpectedResponse = "unexpected_response",// NOTE: when the World app returns an unexpected response
|
|
15
|
+
FailedByHostApp = "failed_by_host_app",// NOTE: Host app failed/rejected verification (does not come from World App / simulator)
|
|
16
|
+
GenericError = "generic_error"
|
|
17
|
+
}
|
|
18
|
+
declare enum VerificationState {
|
|
19
|
+
PreparingClient = "loading_widget",
|
|
20
|
+
WaitingForConnection = "awaiting_connection",// Awaiting connection from the wallet
|
|
21
|
+
WaitingForApp = "awaiting_app",// Awaiting user confirmation in wallet
|
|
22
|
+
Confirmed = "confirmed",
|
|
23
|
+
Failed = "failed"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface ISuccessResult {
|
|
27
|
+
proof: string;
|
|
28
|
+
merkle_root: string;
|
|
29
|
+
nullifier_hash: string;
|
|
30
|
+
verification_level: VerificationLevel;
|
|
31
|
+
}
|
|
32
|
+
interface IErrorState {
|
|
33
|
+
code: AppErrorCodes;
|
|
34
|
+
message?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type WorldBridgeStore = {
|
|
38
|
+
bridge_url: string;
|
|
39
|
+
iv: Uint8Array | null;
|
|
40
|
+
key: CryptoKey | null;
|
|
41
|
+
requestId: string | null;
|
|
42
|
+
connectorURI: string | null;
|
|
43
|
+
result: ISuccessResult | null;
|
|
44
|
+
errorCode: AppErrorCodes | null;
|
|
45
|
+
verificationState: VerificationState;
|
|
46
|
+
createClient: (config: IDKitConfig) => Promise<void>;
|
|
47
|
+
pollForUpdates: () => Promise<void>;
|
|
48
|
+
reset: () => void;
|
|
49
|
+
};
|
|
50
|
+
declare const useWorldBridgeStore: zustand.UseBoundStore<zustand.StoreApi<WorldBridgeStore>>;
|
|
51
|
+
|
|
52
|
+
declare const DEFAULT_VERIFICATION_LEVEL = VerificationLevel.Orb;
|
|
53
|
+
/**
|
|
54
|
+
* @dev use to convert verification level to accepted credential types for proof request
|
|
55
|
+
* @param verification_level
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
declare const verification_level_to_credential_types: (verification_level: VerificationLevel) => string[];
|
|
59
|
+
|
|
60
|
+
export { AppErrorCodes, DEFAULT_VERIFICATION_LEVEL, IDKitConfig, IErrorState, ISuccessResult, VerificationLevel, VerificationState, WorldBridgeStore, useWorldBridgeStore, verification_level_to_credential_types };
|
|
@@ -0,0 +1,82 @@
|
|
|
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/lib/hashing.ts
|
|
21
|
+
var hashing_exports = {};
|
|
22
|
+
__export(hashing_exports, {
|
|
23
|
+
encodeAction: () => encodeAction,
|
|
24
|
+
generateSignal: () => generateSignal,
|
|
25
|
+
hashToField: () => hashToField,
|
|
26
|
+
packAndEncode: () => packAndEncode,
|
|
27
|
+
solidityEncode: () => solidityEncode
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(hashing_exports);
|
|
30
|
+
var import_buffer = require("buffer/index.js");
|
|
31
|
+
var import_viem = require("viem");
|
|
32
|
+
function hashToField(input) {
|
|
33
|
+
if ((0, import_viem.isBytes)(input) || (0, import_viem.isHex)(input))
|
|
34
|
+
return hashEncodedBytes(input);
|
|
35
|
+
return hashString(input);
|
|
36
|
+
}
|
|
37
|
+
function packAndEncode(input) {
|
|
38
|
+
const [types, values] = input.reduce(
|
|
39
|
+
([types2, values2], [type, value]) => {
|
|
40
|
+
types2.push(type);
|
|
41
|
+
values2.push(value);
|
|
42
|
+
return [types2, values2];
|
|
43
|
+
},
|
|
44
|
+
[[], []]
|
|
45
|
+
);
|
|
46
|
+
return hashEncodedBytes((0, import_viem.encodePacked)(types, values));
|
|
47
|
+
}
|
|
48
|
+
function hashString(input) {
|
|
49
|
+
const bytesInput = import_buffer.Buffer.from(input);
|
|
50
|
+
return hashEncodedBytes(bytesInput);
|
|
51
|
+
}
|
|
52
|
+
function hashEncodedBytes(input) {
|
|
53
|
+
const hash = BigInt((0, import_viem.keccak256)(input)) >> 8n;
|
|
54
|
+
const rawDigest = hash.toString(16);
|
|
55
|
+
return { hash, digest: `0x${rawDigest.padStart(64, "0")}` };
|
|
56
|
+
}
|
|
57
|
+
var solidityEncode = (types, values) => {
|
|
58
|
+
if (types.length !== values.length) {
|
|
59
|
+
throw new Error("Types and values arrays must have the same length.");
|
|
60
|
+
}
|
|
61
|
+
return { types, values };
|
|
62
|
+
};
|
|
63
|
+
var generateSignal = (signal) => {
|
|
64
|
+
if (!signal || typeof signal === "string")
|
|
65
|
+
return hashToField(signal ?? "");
|
|
66
|
+
return packAndEncode(signal.types.map((type, index) => [type, signal.values[index]]));
|
|
67
|
+
};
|
|
68
|
+
var encodeAction = (action) => {
|
|
69
|
+
if (!action)
|
|
70
|
+
return "";
|
|
71
|
+
if (typeof action === "string")
|
|
72
|
+
return action;
|
|
73
|
+
return action.types.map((type, index) => `${type}(${action.values[index]})`).join(",");
|
|
74
|
+
};
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
encodeAction,
|
|
78
|
+
generateSignal,
|
|
79
|
+
hashToField,
|
|
80
|
+
packAndEncode,
|
|
81
|
+
solidityEncode
|
|
82
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { A as AbiEncodedValue, I as IDKitConfig } from '../config-a2bbeb0d.js';
|
|
2
|
+
|
|
3
|
+
interface HashFunctionOutput {
|
|
4
|
+
hash: bigint;
|
|
5
|
+
digest: `0x${string}`;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Hashes an input using the `keccak256` hashing function used across the World ID protocol, to be used as
|
|
9
|
+
* a ZKP input. The function will try to determine the best hashing mechanism, if the string already looks like hex-encoded
|
|
10
|
+
* bytes (e.g. `0x0000000000000000000000000000000000000000`), it will be hashed directly.
|
|
11
|
+
* @param input Any string, hex-like string, bytes represented as a hex string.
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
declare function hashToField(input: Uint8Array | string): HashFunctionOutput;
|
|
15
|
+
declare function packAndEncode(input: [string, unknown][]): HashFunctionOutput;
|
|
16
|
+
declare const solidityEncode: (types: string[], values: unknown[]) => AbiEncodedValue;
|
|
17
|
+
declare const generateSignal: (signal: IDKitConfig['signal']) => HashFunctionOutput;
|
|
18
|
+
declare const encodeAction: (action: IDKitConfig['action']) => string;
|
|
19
|
+
|
|
20
|
+
export { HashFunctionOutput, encodeAction, generateSignal, hashToField, packAndEncode, solidityEncode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@worldcoin/idkit-core",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"homepage": "https://docs.worldcoin.org/id/idkit",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
16
|
"import": "./build/index.js",
|
|
17
|
-
"types": "./build/index.d.ts"
|
|
17
|
+
"types": "./build/index.d.ts",
|
|
18
|
+
"require": "./build/index.cjs"
|
|
18
19
|
},
|
|
19
20
|
"./hashing": {
|
|
20
21
|
"import": "./build/lib/hashing.js",
|
|
21
|
-
"types": "./build/lib/hashing.d.ts"
|
|
22
|
+
"types": "./build/lib/hashing.d.ts",
|
|
23
|
+
"require": "./build/lib/hashing.cjs"
|
|
22
24
|
}
|
|
23
25
|
},
|
|
24
26
|
"typesVersions": {
|
|
@@ -27,7 +29,6 @@
|
|
|
27
29
|
"./build/lib/hashing.d.ts"
|
|
28
30
|
],
|
|
29
31
|
"*": [
|
|
30
|
-
"./build/*/index.d.ts",
|
|
31
32
|
"./build/index.d.ts"
|
|
32
33
|
]
|
|
33
34
|
}
|