@hyperledger/anoncreds-nodejs 0.5.0-alpha-20261027093135 → 0.5.0-alpha-20261027201040
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.d.mts +273 -0
- package/build/index.mjs +871 -0
- package/build/index.mjs.map +1 -0
- package/package.json +16 -8
- package/build/NodeJSAnoncreds.d.ts +0 -267
- package/build/NodeJSAnoncreds.js +0 -479
- package/build/NodeJSAnoncreds.js.map +0 -1
- package/build/ffi/alloc.d.ts +0 -10
- package/build/ffi/alloc.js +0 -38
- package/build/ffi/alloc.js.map +0 -1
- package/build/ffi/conversion.d.ts +0 -17
- package/build/ffi/conversion.js +0 -39
- package/build/ffi/conversion.js.map +0 -1
- package/build/ffi/index.d.ts +0 -5
- package/build/ffi/index.js +0 -22
- package/build/ffi/index.js.map +0 -1
- package/build/ffi/primitives.d.ts +0 -11
- package/build/ffi/primitives.js +0 -48
- package/build/ffi/primitives.js.map +0 -1
- package/build/ffi/serialize.d.ts +0 -1
- package/build/ffi/serialize.js +0 -46
- package/build/ffi/serialize.js.map +0 -1
- package/build/ffi/structures.d.ts +0 -27
- package/build/ffi/structures.js +0 -59
- package/build/ffi/structures.js.map +0 -1
- package/build/index.d.ts +0 -3
- package/build/index.js +0 -23
- package/build/index.js.map +0 -1
- package/build/library/NativeBindingInterface.d.ts +0 -2
- package/build/library/NativeBindingInterface.js +0 -3
- package/build/library/NativeBindingInterface.js.map +0 -1
- package/build/library/bindings.d.ts +0 -4
- package/build/library/bindings.js +0 -352
- package/build/library/bindings.js.map +0 -1
- package/build/library/index.d.ts +0 -3
- package/build/library/index.js +0 -20
- package/build/library/index.js.map +0 -1
- package/build/library/register.d.ts +0 -2
- package/build/library/register.js +0 -66
- package/build/library/register.js.map +0 -1
package/build/index.mjs
ADDED
|
@@ -0,0 +1,871 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { AnoncredsError, NativeAnoncreds, ObjectHandle } from "@hyperledger/anoncreds-shared";
|
|
3
|
+
import { TextEncoder } from "node:util";
|
|
4
|
+
import koffi, * as koffi$1 from "koffi";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
export * from "@hyperledger/anoncreds-shared";
|
|
9
|
+
// src/ffi/alloc.ts
|
|
10
|
+
const allocatePointer = () => {
|
|
11
|
+
return [void 0];
|
|
12
|
+
};
|
|
13
|
+
const allocateStringBuffer = () => {
|
|
14
|
+
return [void 0];
|
|
15
|
+
};
|
|
16
|
+
const allocateInt8Buffer = () => {
|
|
17
|
+
return [0];
|
|
18
|
+
};
|
|
19
|
+
const allocateByteBuffer = () => {
|
|
20
|
+
return {};
|
|
21
|
+
};
|
|
22
|
+
// src/ffi/conversion.ts
|
|
23
|
+
const stringListToStringListStruct = (stringList) => {
|
|
24
|
+
return {
|
|
25
|
+
count: stringList.length,
|
|
26
|
+
data: stringList
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const byteBufferToString = (byteBuffer) => koffi.decode.string(byteBuffer.data, byteBuffer.len);
|
|
30
|
+
const objectHandleListToObjectHandleListStruct = (objectHandleList) => {
|
|
31
|
+
return {
|
|
32
|
+
count: objectHandleList.length,
|
|
33
|
+
data: objectHandleList.map((h) => h.handle)
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const i32ListToI32ListStruct = (i32List) => {
|
|
37
|
+
return {
|
|
38
|
+
count: i32List.length,
|
|
39
|
+
data: i32List
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
// src/ffi/primitives.ts
|
|
43
|
+
const FFI_UINT8 = koffi$1.types.uint8_t;
|
|
44
|
+
koffi$1.types.uint64_t;
|
|
45
|
+
const FFI_USIZE = koffi$1.types.size_t;
|
|
46
|
+
const FFI_INT8 = koffi$1.types.int8_t;
|
|
47
|
+
const FFI_INT32 = koffi$1.types.int32_t;
|
|
48
|
+
const FFI_INT64 = koffi$1.types.int64_t;
|
|
49
|
+
const FFI_STRING = koffi$1.types.string;
|
|
50
|
+
const FFI_VOID = koffi$1.types.void;
|
|
51
|
+
let freeAnoncredsString;
|
|
52
|
+
const setFreeAnoncredsString = (free) => {
|
|
53
|
+
freeAnoncredsString = free;
|
|
54
|
+
};
|
|
55
|
+
const FFI_ANONCREDS_STRING = koffi$1.disposable("anoncreds_string", FFI_STRING, (pointer) => {
|
|
56
|
+
if (!pointer) return;
|
|
57
|
+
if (!freeAnoncredsString) throw new Error("Cannot free an AnonCreds string before the AnonCreds library is loaded");
|
|
58
|
+
freeAnoncredsString(pointer);
|
|
59
|
+
});
|
|
60
|
+
const FFI_OBJECT_HANDLE = FFI_USIZE;
|
|
61
|
+
const FFI_ERROR_CODE = FFI_INT64;
|
|
62
|
+
// src/ffi/serialize.ts
|
|
63
|
+
const serialize = (arg) => {
|
|
64
|
+
switch (typeof arg) {
|
|
65
|
+
case "undefined": return null;
|
|
66
|
+
case "boolean": return Number(arg);
|
|
67
|
+
case "string": return arg;
|
|
68
|
+
case "number": return arg;
|
|
69
|
+
case "function": return arg;
|
|
70
|
+
case "object":
|
|
71
|
+
if (arg instanceof ObjectHandle) return arg.handle;
|
|
72
|
+
if (Array.isArray(arg)) {
|
|
73
|
+
if (arg.every((it) => typeof it === "string")) return stringListToStringListStruct(arg);
|
|
74
|
+
if (arg.every((it) => it instanceof ObjectHandle)) return objectHandleListToObjectHandleListStruct(arg);
|
|
75
|
+
if (arg.every((it) => typeof it === "number")) return i32ListToI32ListStruct(arg);
|
|
76
|
+
}
|
|
77
|
+
return JSON.stringify(arg);
|
|
78
|
+
default: throw new Error("could not serialize value");
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const serializeArguments = (args) => {
|
|
82
|
+
const retVal = {};
|
|
83
|
+
for (const [key, val] of Object.entries(args)) retVal[key] = serialize(val);
|
|
84
|
+
return retVal;
|
|
85
|
+
};
|
|
86
|
+
// src/ffi/structures.ts
|
|
87
|
+
const ByteBufferStruct = koffi.struct("ByteBufferStruct", {
|
|
88
|
+
len: FFI_INT64,
|
|
89
|
+
data: koffi.pointer(FFI_UINT8)
|
|
90
|
+
});
|
|
91
|
+
const StringListStruct = koffi.struct("StringListStruct", {
|
|
92
|
+
count: FFI_USIZE,
|
|
93
|
+
data: koffi.pointer(FFI_STRING)
|
|
94
|
+
});
|
|
95
|
+
const I32ListStruct = koffi.struct("I32ListStruct", {
|
|
96
|
+
count: FFI_USIZE,
|
|
97
|
+
data: koffi.pointer(FFI_INT32)
|
|
98
|
+
});
|
|
99
|
+
const CredRevInfoStruct = koffi.struct("CredRevInfoStruct", {
|
|
100
|
+
reg_def: FFI_OBJECT_HANDLE,
|
|
101
|
+
reg_def_private: FFI_OBJECT_HANDLE,
|
|
102
|
+
status_list: FFI_OBJECT_HANDLE,
|
|
103
|
+
reg_idx: FFI_INT64
|
|
104
|
+
});
|
|
105
|
+
const CredentialEntryStruct = koffi.struct("CredentialEntryStruct", {
|
|
106
|
+
credential: FFI_OBJECT_HANDLE,
|
|
107
|
+
timestamp: FFI_INT32,
|
|
108
|
+
rev_state: FFI_OBJECT_HANDLE
|
|
109
|
+
});
|
|
110
|
+
const CredentialEntryStructList = koffi.struct("CredentialEntryStructList", {
|
|
111
|
+
count: FFI_USIZE,
|
|
112
|
+
data: koffi.pointer(CredentialEntryStruct)
|
|
113
|
+
});
|
|
114
|
+
const CredentialProveStruct = koffi.struct("CredentialProveStruct", {
|
|
115
|
+
entry_idx: FFI_INT64,
|
|
116
|
+
referent: FFI_STRING,
|
|
117
|
+
is_predicate: FFI_INT8,
|
|
118
|
+
reveal: FFI_INT8
|
|
119
|
+
});
|
|
120
|
+
const CredentialProveStructList = koffi.struct("CredentialProveStructList", {
|
|
121
|
+
count: FFI_USIZE,
|
|
122
|
+
data: koffi.pointer(CredentialProveStruct)
|
|
123
|
+
});
|
|
124
|
+
const ObjectHandleStructList = koffi.struct("ObjectHandleStructList", {
|
|
125
|
+
count: FFI_USIZE,
|
|
126
|
+
data: koffi.pointer(FFI_OBJECT_HANDLE)
|
|
127
|
+
});
|
|
128
|
+
const NonrevokedIntervalOverrideStruct = koffi.struct("NonrevokedIntervalOverrideStruct", {
|
|
129
|
+
rev_reg_def_id: FFI_STRING,
|
|
130
|
+
requested_from_ts: FFI_INT32,
|
|
131
|
+
override_rev_status_list_ts: FFI_INT32
|
|
132
|
+
});
|
|
133
|
+
const NonrevokedIntervalOverrideStructList = koffi.struct("NonrevokedIntervalOverrideStructList", {
|
|
134
|
+
count: FFI_USIZE,
|
|
135
|
+
data: koffi.pointer(NonrevokedIntervalOverrideStruct)
|
|
136
|
+
});
|
|
137
|
+
// src/library/bindings.ts
|
|
138
|
+
const nativeBindings = {
|
|
139
|
+
anoncreds_version: [FFI_ANONCREDS_STRING, []],
|
|
140
|
+
anoncreds_set_default_logger: [FFI_ERROR_CODE, []],
|
|
141
|
+
anoncreds_get_current_error: [FFI_ERROR_CODE, [koffi$1.out(koffi$1.pointer(FFI_ANONCREDS_STRING))]],
|
|
142
|
+
anoncreds_generate_nonce: [FFI_ERROR_CODE, [koffi$1.out(koffi$1.pointer(FFI_ANONCREDS_STRING))]],
|
|
143
|
+
anoncreds_buffer_free: [FFI_VOID, [ByteBufferStruct]],
|
|
144
|
+
anoncreds_string_free: [FFI_VOID, [koffi$1.pointer(FFI_VOID)]],
|
|
145
|
+
anoncreds_object_free: [FFI_VOID, [FFI_OBJECT_HANDLE]],
|
|
146
|
+
anoncreds_object_get_json: [FFI_ERROR_CODE, [FFI_OBJECT_HANDLE, koffi$1.out(koffi$1.pointer(ByteBufferStruct))]],
|
|
147
|
+
anoncreds_object_get_type_name: [FFI_ERROR_CODE, [FFI_OBJECT_HANDLE, koffi$1.out(koffi$1.pointer(FFI_ANONCREDS_STRING))]],
|
|
148
|
+
anoncreds_create_schema: [FFI_ERROR_CODE, [
|
|
149
|
+
FFI_STRING,
|
|
150
|
+
FFI_STRING,
|
|
151
|
+
FFI_STRING,
|
|
152
|
+
StringListStruct,
|
|
153
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
154
|
+
]],
|
|
155
|
+
anoncreds_schema_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
156
|
+
anoncreds_create_credential_definition: [FFI_ERROR_CODE, [
|
|
157
|
+
FFI_STRING,
|
|
158
|
+
FFI_OBJECT_HANDLE,
|
|
159
|
+
FFI_STRING,
|
|
160
|
+
FFI_STRING,
|
|
161
|
+
FFI_STRING,
|
|
162
|
+
FFI_INT8,
|
|
163
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE)),
|
|
164
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE)),
|
|
165
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
166
|
+
]],
|
|
167
|
+
anoncreds_credential_definition_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
168
|
+
anoncreds_credential_definition_private_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
169
|
+
anoncreds_key_correctness_proof_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
170
|
+
anoncreds_create_revocation_registry_def: [FFI_ERROR_CODE, [
|
|
171
|
+
FFI_OBJECT_HANDLE,
|
|
172
|
+
FFI_STRING,
|
|
173
|
+
FFI_STRING,
|
|
174
|
+
FFI_STRING,
|
|
175
|
+
FFI_STRING,
|
|
176
|
+
FFI_INT64,
|
|
177
|
+
FFI_STRING,
|
|
178
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE)),
|
|
179
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
180
|
+
]],
|
|
181
|
+
anoncreds_revocation_registry_definition_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
182
|
+
anoncreds_revocation_registry_definition_private_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
183
|
+
anoncreds_revocation_registry_definition_get_attribute: [FFI_ERROR_CODE, [
|
|
184
|
+
FFI_OBJECT_HANDLE,
|
|
185
|
+
FFI_STRING,
|
|
186
|
+
koffi$1.out(koffi$1.pointer(FFI_ANONCREDS_STRING))
|
|
187
|
+
]],
|
|
188
|
+
anoncreds_revocation_registry_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
189
|
+
anoncreds_create_revocation_status_list: [FFI_ERROR_CODE, [
|
|
190
|
+
FFI_OBJECT_HANDLE,
|
|
191
|
+
FFI_STRING,
|
|
192
|
+
FFI_OBJECT_HANDLE,
|
|
193
|
+
FFI_OBJECT_HANDLE,
|
|
194
|
+
FFI_STRING,
|
|
195
|
+
FFI_INT8,
|
|
196
|
+
FFI_INT64,
|
|
197
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
198
|
+
]],
|
|
199
|
+
anoncreds_update_revocation_status_list: [FFI_ERROR_CODE, [
|
|
200
|
+
FFI_OBJECT_HANDLE,
|
|
201
|
+
FFI_OBJECT_HANDLE,
|
|
202
|
+
FFI_OBJECT_HANDLE,
|
|
203
|
+
FFI_OBJECT_HANDLE,
|
|
204
|
+
I32ListStruct,
|
|
205
|
+
I32ListStruct,
|
|
206
|
+
FFI_INT64,
|
|
207
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
208
|
+
]],
|
|
209
|
+
anoncreds_update_revocation_status_list_timestamp_only: [FFI_ERROR_CODE, [
|
|
210
|
+
FFI_INT64,
|
|
211
|
+
FFI_OBJECT_HANDLE,
|
|
212
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
213
|
+
]],
|
|
214
|
+
anoncreds_revocation_status_list_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
215
|
+
anoncreds_create_or_update_revocation_state: [FFI_ERROR_CODE, [
|
|
216
|
+
FFI_OBJECT_HANDLE,
|
|
217
|
+
FFI_OBJECT_HANDLE,
|
|
218
|
+
FFI_INT64,
|
|
219
|
+
FFI_STRING,
|
|
220
|
+
FFI_OBJECT_HANDLE,
|
|
221
|
+
FFI_OBJECT_HANDLE,
|
|
222
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
223
|
+
]],
|
|
224
|
+
anoncreds_revocation_state_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
225
|
+
anoncreds_create_link_secret: [FFI_ERROR_CODE, [koffi$1.out(koffi$1.pointer(FFI_ANONCREDS_STRING))]],
|
|
226
|
+
anoncreds_create_credential_offer: [FFI_ERROR_CODE, [
|
|
227
|
+
FFI_STRING,
|
|
228
|
+
FFI_STRING,
|
|
229
|
+
FFI_OBJECT_HANDLE,
|
|
230
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
231
|
+
]],
|
|
232
|
+
anoncreds_credential_offer_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
233
|
+
anoncreds_create_credential_request: [FFI_ERROR_CODE, [
|
|
234
|
+
FFI_STRING,
|
|
235
|
+
FFI_STRING,
|
|
236
|
+
FFI_OBJECT_HANDLE,
|
|
237
|
+
FFI_STRING,
|
|
238
|
+
FFI_STRING,
|
|
239
|
+
FFI_OBJECT_HANDLE,
|
|
240
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE)),
|
|
241
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
242
|
+
]],
|
|
243
|
+
anoncreds_credential_request_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
244
|
+
anoncreds_credential_request_metadata_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
245
|
+
anoncreds_create_credential: [FFI_ERROR_CODE, [
|
|
246
|
+
FFI_OBJECT_HANDLE,
|
|
247
|
+
FFI_OBJECT_HANDLE,
|
|
248
|
+
FFI_OBJECT_HANDLE,
|
|
249
|
+
FFI_OBJECT_HANDLE,
|
|
250
|
+
StringListStruct,
|
|
251
|
+
StringListStruct,
|
|
252
|
+
StringListStruct,
|
|
253
|
+
koffi$1.pointer(CredRevInfoStruct),
|
|
254
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
255
|
+
]],
|
|
256
|
+
anoncreds_credential_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
257
|
+
anoncreds_credential_get_attribute: [FFI_ERROR_CODE, [
|
|
258
|
+
FFI_OBJECT_HANDLE,
|
|
259
|
+
FFI_STRING,
|
|
260
|
+
koffi$1.out(koffi$1.pointer(FFI_ANONCREDS_STRING))
|
|
261
|
+
]],
|
|
262
|
+
anoncreds_process_credential: [FFI_ERROR_CODE, [
|
|
263
|
+
FFI_OBJECT_HANDLE,
|
|
264
|
+
FFI_OBJECT_HANDLE,
|
|
265
|
+
FFI_STRING,
|
|
266
|
+
FFI_OBJECT_HANDLE,
|
|
267
|
+
FFI_OBJECT_HANDLE,
|
|
268
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
269
|
+
]],
|
|
270
|
+
anoncreds_encode_credential_attributes: [FFI_ERROR_CODE, [StringListStruct, koffi$1.out(koffi$1.pointer(FFI_ANONCREDS_STRING))]],
|
|
271
|
+
anoncreds_create_w3c_credential: [FFI_ERROR_CODE, [
|
|
272
|
+
FFI_OBJECT_HANDLE,
|
|
273
|
+
FFI_OBJECT_HANDLE,
|
|
274
|
+
FFI_OBJECT_HANDLE,
|
|
275
|
+
FFI_OBJECT_HANDLE,
|
|
276
|
+
StringListStruct,
|
|
277
|
+
StringListStruct,
|
|
278
|
+
koffi$1.pointer(CredRevInfoStruct),
|
|
279
|
+
FFI_STRING,
|
|
280
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
281
|
+
]],
|
|
282
|
+
anoncreds_w3c_credential_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
283
|
+
anoncreds_credential_to_w3c: [FFI_ERROR_CODE, [
|
|
284
|
+
FFI_OBJECT_HANDLE,
|
|
285
|
+
FFI_STRING,
|
|
286
|
+
FFI_STRING,
|
|
287
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
288
|
+
]],
|
|
289
|
+
anoncreds_credential_from_w3c: [FFI_ERROR_CODE, [FFI_OBJECT_HANDLE, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
290
|
+
anoncreds_process_w3c_credential: [FFI_ERROR_CODE, [
|
|
291
|
+
FFI_OBJECT_HANDLE,
|
|
292
|
+
FFI_OBJECT_HANDLE,
|
|
293
|
+
FFI_STRING,
|
|
294
|
+
FFI_OBJECT_HANDLE,
|
|
295
|
+
FFI_OBJECT_HANDLE,
|
|
296
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
297
|
+
]],
|
|
298
|
+
anoncreds_w3c_credential_get_integrity_proof_details: [FFI_ERROR_CODE, [FFI_OBJECT_HANDLE, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
299
|
+
anoncreds_w3c_credential_proof_get_attribute: [FFI_ERROR_CODE, [
|
|
300
|
+
FFI_OBJECT_HANDLE,
|
|
301
|
+
FFI_STRING,
|
|
302
|
+
koffi$1.out(koffi$1.pointer(FFI_ANONCREDS_STRING))
|
|
303
|
+
]],
|
|
304
|
+
anoncreds_presentation_request_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
305
|
+
anoncreds_create_presentation: [FFI_ERROR_CODE, [
|
|
306
|
+
FFI_OBJECT_HANDLE,
|
|
307
|
+
CredentialEntryStructList,
|
|
308
|
+
CredentialProveStructList,
|
|
309
|
+
StringListStruct,
|
|
310
|
+
StringListStruct,
|
|
311
|
+
FFI_STRING,
|
|
312
|
+
ObjectHandleStructList,
|
|
313
|
+
StringListStruct,
|
|
314
|
+
ObjectHandleStructList,
|
|
315
|
+
StringListStruct,
|
|
316
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
317
|
+
]],
|
|
318
|
+
anoncreds_presentation_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
319
|
+
anoncreds_verify_presentation: [FFI_ERROR_CODE, [
|
|
320
|
+
FFI_OBJECT_HANDLE,
|
|
321
|
+
FFI_OBJECT_HANDLE,
|
|
322
|
+
ObjectHandleStructList,
|
|
323
|
+
StringListStruct,
|
|
324
|
+
ObjectHandleStructList,
|
|
325
|
+
StringListStruct,
|
|
326
|
+
ObjectHandleStructList,
|
|
327
|
+
StringListStruct,
|
|
328
|
+
ObjectHandleStructList,
|
|
329
|
+
NonrevokedIntervalOverrideStructList,
|
|
330
|
+
koffi$1.out(koffi$1.pointer(FFI_INT8))
|
|
331
|
+
]],
|
|
332
|
+
anoncreds_create_w3c_presentation: [FFI_ERROR_CODE, [
|
|
333
|
+
FFI_OBJECT_HANDLE,
|
|
334
|
+
CredentialEntryStructList,
|
|
335
|
+
CredentialProveStructList,
|
|
336
|
+
FFI_STRING,
|
|
337
|
+
ObjectHandleStructList,
|
|
338
|
+
StringListStruct,
|
|
339
|
+
ObjectHandleStructList,
|
|
340
|
+
StringListStruct,
|
|
341
|
+
FFI_STRING,
|
|
342
|
+
koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))
|
|
343
|
+
]],
|
|
344
|
+
anoncreds_w3c_presentation_from_json: [FFI_ERROR_CODE, [ByteBufferStruct, koffi$1.out(koffi$1.pointer(FFI_OBJECT_HANDLE))]],
|
|
345
|
+
anoncreds_verify_w3c_presentation: [FFI_ERROR_CODE, [
|
|
346
|
+
FFI_OBJECT_HANDLE,
|
|
347
|
+
FFI_OBJECT_HANDLE,
|
|
348
|
+
ObjectHandleStructList,
|
|
349
|
+
StringListStruct,
|
|
350
|
+
ObjectHandleStructList,
|
|
351
|
+
StringListStruct,
|
|
352
|
+
ObjectHandleStructList,
|
|
353
|
+
StringListStruct,
|
|
354
|
+
ObjectHandleStructList,
|
|
355
|
+
NonrevokedIntervalOverrideStructList,
|
|
356
|
+
koffi$1.out(koffi$1.pointer(FFI_INT8))
|
|
357
|
+
]]
|
|
358
|
+
};
|
|
359
|
+
// src/library/register.ts
|
|
360
|
+
const LIBNAME = "anoncreds";
|
|
361
|
+
const ENV_VAR = "LIB_ANONCREDS_PATH";
|
|
362
|
+
const extensions = {
|
|
363
|
+
darwin: {
|
|
364
|
+
prefix: "lib",
|
|
365
|
+
extension: ".dylib"
|
|
366
|
+
},
|
|
367
|
+
linux: {
|
|
368
|
+
prefix: "lib",
|
|
369
|
+
extension: ".so"
|
|
370
|
+
},
|
|
371
|
+
win32: { extension: ".dll" }
|
|
372
|
+
};
|
|
373
|
+
const libPaths = {
|
|
374
|
+
darwin: [
|
|
375
|
+
"/usr/local/lib/",
|
|
376
|
+
"/usr/lib/",
|
|
377
|
+
"/opt/homebrew/opt/"
|
|
378
|
+
],
|
|
379
|
+
linux: ["/usr/lib/", "/usr/local/lib/"],
|
|
380
|
+
win32: ["c:\\windows\\system32\\"]
|
|
381
|
+
};
|
|
382
|
+
const doesPathExist = fs.existsSync;
|
|
383
|
+
const getLibrary = () => {
|
|
384
|
+
const platform = os.platform();
|
|
385
|
+
if (platform !== "linux" && platform !== "win32" && platform !== "darwin") throw new Error(`Unsupported platform: ${platform}. linux, win32 and darwin are supported.`);
|
|
386
|
+
const pathFromEnvironment = process.env[ENV_VAR];
|
|
387
|
+
const platformPaths = libPaths[platform];
|
|
388
|
+
try {
|
|
389
|
+
const packageRoot = path.dirname(createRequire(import.meta.url).resolve("@hyperledger/anoncreds-nodejs/package.json"));
|
|
390
|
+
platformPaths.unshift(path.join(packageRoot, "native"));
|
|
391
|
+
} catch {}
|
|
392
|
+
if (pathFromEnvironment) platformPaths.unshift(pathFromEnvironment);
|
|
393
|
+
const libraries = platformPaths.map((p) => path.join(p, `${extensions[platform].prefix ?? ""}${LIBNAME}${extensions[platform].extension}`));
|
|
394
|
+
if (!libraries.some((libraryPath) => doesPathExist(libraryPath))) throw new Error(`Could not find ${LIBNAME} with these paths: ${libraries.join(" ")}`);
|
|
395
|
+
const validLibraryPath = libraries.find((l) => doesPathExist(l));
|
|
396
|
+
const lib = koffi.load(validLibraryPath);
|
|
397
|
+
const methods = {};
|
|
398
|
+
for (const [name, [returnType, argumentTypes]] of Object.entries(nativeBindings)) methods[name] = lib.func(name, returnType, argumentTypes);
|
|
399
|
+
setFreeAnoncredsString((pointer) => methods.anoncreds_string_free?.(pointer));
|
|
400
|
+
return methods;
|
|
401
|
+
};
|
|
402
|
+
let nativeAnonCreds;
|
|
403
|
+
const getNativeAnonCreds = () => {
|
|
404
|
+
if (!nativeAnonCreds) nativeAnonCreds = getLibrary();
|
|
405
|
+
return nativeAnonCreds;
|
|
406
|
+
};
|
|
407
|
+
// src/NodeJSAnoncreds.ts
|
|
408
|
+
function handleReturnPointer(returnValue) {
|
|
409
|
+
const value = Array.isArray(returnValue) ? returnValue[0] : returnValue;
|
|
410
|
+
if (value === null || value === void 0) throw AnoncredsError.customError({ message: "Unexpected null pointer" });
|
|
411
|
+
return value;
|
|
412
|
+
}
|
|
413
|
+
var NodeJSAnoncreds = class {
|
|
414
|
+
get nativeAnoncreds() {
|
|
415
|
+
return getNativeAnonCreds();
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Fetch the error from the native library and throw it as a JS error
|
|
419
|
+
*
|
|
420
|
+
* NOTE:
|
|
421
|
+
* Checks whether the error code of the returned error matches the error code that was passed to the function.
|
|
422
|
+
* If it doesn't, we throw an error with the original errorCode, and a custom message explaining we weren't able
|
|
423
|
+
* to retrieve the error message from the native library. This should however not break functionality as long as
|
|
424
|
+
* error codes are used rather than error messages for error handling.
|
|
425
|
+
*
|
|
426
|
+
*/
|
|
427
|
+
getAnoncredsError(errorCode) {
|
|
428
|
+
const error = this.getCurrentError();
|
|
429
|
+
if (error.code !== errorCode) return new AnoncredsError({
|
|
430
|
+
code: errorCode,
|
|
431
|
+
message: "Error details have already been overwritten on the native side, unable to retrieve error message for the error"
|
|
432
|
+
});
|
|
433
|
+
return new AnoncredsError(error);
|
|
434
|
+
}
|
|
435
|
+
getCurrentError() {
|
|
436
|
+
const error = allocateStringBuffer();
|
|
437
|
+
this.nativeAnoncreds.anoncreds_get_current_error(error);
|
|
438
|
+
const serializedError = handleReturnPointer(error);
|
|
439
|
+
return JSON.parse(serializedError);
|
|
440
|
+
}
|
|
441
|
+
handleError(errorCode) {
|
|
442
|
+
if (errorCode === 0) return;
|
|
443
|
+
throw this.getAnoncredsError(errorCode);
|
|
444
|
+
}
|
|
445
|
+
generateNonce() {
|
|
446
|
+
const ret = allocateStringBuffer();
|
|
447
|
+
const errorCode = this.nativeAnoncreds.anoncreds_generate_nonce(ret);
|
|
448
|
+
this.handleError(errorCode);
|
|
449
|
+
return handleReturnPointer(ret);
|
|
450
|
+
}
|
|
451
|
+
createSchema(options) {
|
|
452
|
+
const { name, version, issuerId, attributeNames } = serializeArguments(options);
|
|
453
|
+
const ret = allocatePointer();
|
|
454
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_schema(name, version, issuerId, attributeNames, ret);
|
|
455
|
+
this.handleError(errorCode);
|
|
456
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
457
|
+
}
|
|
458
|
+
revocationRegistryDefinitionGetAttribute(options) {
|
|
459
|
+
const { objectHandle, name } = serializeArguments(options);
|
|
460
|
+
const ret = allocateStringBuffer();
|
|
461
|
+
const errorCode = this.nativeAnoncreds.anoncreds_revocation_registry_definition_get_attribute(objectHandle, name, ret);
|
|
462
|
+
this.handleError(errorCode);
|
|
463
|
+
return handleReturnPointer(ret);
|
|
464
|
+
}
|
|
465
|
+
credentialGetAttribute(options) {
|
|
466
|
+
const { objectHandle, name } = serializeArguments(options);
|
|
467
|
+
const ret = allocateStringBuffer();
|
|
468
|
+
const errorCode = this.nativeAnoncreds.anoncreds_credential_get_attribute(objectHandle, name, ret);
|
|
469
|
+
this.handleError(errorCode);
|
|
470
|
+
return (Array.isArray(ret) ? ret[0] : ret) ?? null;
|
|
471
|
+
}
|
|
472
|
+
createCredentialDefinition(options) {
|
|
473
|
+
const { schemaId, issuerId, schema, tag, signatureType, supportRevocation } = serializeArguments(options);
|
|
474
|
+
const credentialDefinitionPtr = allocatePointer();
|
|
475
|
+
const credentialDefinitionPrivatePtr = allocatePointer();
|
|
476
|
+
const keyCorrectnessProofPtr = allocatePointer();
|
|
477
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_credential_definition(schemaId, schema, tag, issuerId, signatureType, supportRevocation, credentialDefinitionPtr, credentialDefinitionPrivatePtr, keyCorrectnessProofPtr);
|
|
478
|
+
this.handleError(errorCode);
|
|
479
|
+
return {
|
|
480
|
+
credentialDefinition: new ObjectHandle(handleReturnPointer(credentialDefinitionPtr)),
|
|
481
|
+
credentialDefinitionPrivate: new ObjectHandle(handleReturnPointer(credentialDefinitionPrivatePtr)),
|
|
482
|
+
keyCorrectnessProof: new ObjectHandle(handleReturnPointer(keyCorrectnessProofPtr))
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
createCredential(options) {
|
|
486
|
+
const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest } = serializeArguments(options);
|
|
487
|
+
const attributeNames = {
|
|
488
|
+
count: Object.keys(options.attributeRawValues).length,
|
|
489
|
+
data: Object.keys(options.attributeRawValues)
|
|
490
|
+
};
|
|
491
|
+
const attributeRawValues = {
|
|
492
|
+
count: Object.keys(options.attributeRawValues).length,
|
|
493
|
+
data: Object.values(options.attributeRawValues)
|
|
494
|
+
};
|
|
495
|
+
const attributeEncodedValues = options.attributeEncodedValues ? {
|
|
496
|
+
count: Object.keys(options.attributeEncodedValues).length,
|
|
497
|
+
data: Object.values(options.attributeEncodedValues)
|
|
498
|
+
} : {};
|
|
499
|
+
let revocationConfiguration = null;
|
|
500
|
+
if (options.revocationConfiguration) {
|
|
501
|
+
const { revocationStatusList, revocationRegistryDefinitionPrivate, revocationRegistryDefinition, registryIndex } = serializeArguments(options.revocationConfiguration);
|
|
502
|
+
revocationConfiguration = {
|
|
503
|
+
reg_def: revocationRegistryDefinition,
|
|
504
|
+
reg_def_private: revocationRegistryDefinitionPrivate,
|
|
505
|
+
status_list: revocationStatusList,
|
|
506
|
+
reg_idx: registryIndex
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
const credentialPtr = allocatePointer();
|
|
510
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_credential(credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, attributeNames, attributeRawValues, attributeEncodedValues, revocationConfiguration, credentialPtr);
|
|
511
|
+
this.handleError(errorCode);
|
|
512
|
+
return new ObjectHandle(handleReturnPointer(credentialPtr));
|
|
513
|
+
}
|
|
514
|
+
encodeCredentialAttributes(options) {
|
|
515
|
+
const { attributeRawValues } = serializeArguments(options);
|
|
516
|
+
const ret = allocateStringBuffer();
|
|
517
|
+
const errorCode = this.nativeAnoncreds.anoncreds_encode_credential_attributes(attributeRawValues, ret);
|
|
518
|
+
this.handleError(errorCode);
|
|
519
|
+
return handleReturnPointer(ret).split(",");
|
|
520
|
+
}
|
|
521
|
+
processCredential(options) {
|
|
522
|
+
const { credential, credentialRequestMetadata, linkSecret, credentialDefinition } = serializeArguments(options);
|
|
523
|
+
const ret = allocatePointer();
|
|
524
|
+
const errorCode = this.nativeAnoncreds.anoncreds_process_credential(credential, credentialRequestMetadata, linkSecret, credentialDefinition, options.revocationRegistryDefinition?.handle ?? 0, ret);
|
|
525
|
+
this.handleError(errorCode);
|
|
526
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
527
|
+
}
|
|
528
|
+
createCredentialOffer(options) {
|
|
529
|
+
const { schemaId, credentialDefinitionId, keyCorrectnessProof } = serializeArguments(options);
|
|
530
|
+
const ret = allocatePointer();
|
|
531
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_credential_offer(schemaId, credentialDefinitionId, keyCorrectnessProof, ret);
|
|
532
|
+
this.handleError(errorCode);
|
|
533
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
534
|
+
}
|
|
535
|
+
createCredentialRequest(options) {
|
|
536
|
+
const { entropy, proverDid, credentialDefinition, linkSecret, linkSecretId, credentialOffer } = serializeArguments(options);
|
|
537
|
+
const credentialRequestPtr = allocatePointer();
|
|
538
|
+
const credentialRequestMetadataPtr = allocatePointer();
|
|
539
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_credential_request(entropy, proverDid, credentialDefinition, linkSecret, linkSecretId, credentialOffer, credentialRequestPtr, credentialRequestMetadataPtr);
|
|
540
|
+
this.handleError(errorCode);
|
|
541
|
+
return {
|
|
542
|
+
credentialRequest: new ObjectHandle(handleReturnPointer(credentialRequestPtr)),
|
|
543
|
+
credentialRequestMetadata: new ObjectHandle(handleReturnPointer(credentialRequestMetadataPtr))
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
createLinkSecret() {
|
|
547
|
+
const ret = allocateStringBuffer();
|
|
548
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_link_secret(ret);
|
|
549
|
+
this.handleError(errorCode);
|
|
550
|
+
return handleReturnPointer(ret);
|
|
551
|
+
}
|
|
552
|
+
createPresentation(options) {
|
|
553
|
+
const { presentationRequest, linkSecret } = serializeArguments(options);
|
|
554
|
+
const selfAttestNames = {
|
|
555
|
+
count: Object.keys(options.selfAttest).length,
|
|
556
|
+
data: Object.keys(options.selfAttest)
|
|
557
|
+
};
|
|
558
|
+
const selfAttestValues = {
|
|
559
|
+
count: Object.values(options.selfAttest).length,
|
|
560
|
+
data: Object.values(options.selfAttest)
|
|
561
|
+
};
|
|
562
|
+
const credentialEntryList = this.convertCredentialList(options.credentials);
|
|
563
|
+
const credentialProveList = this.convertCredentialProves(options.credentialsProve);
|
|
564
|
+
const { schemaIds, schemas } = this.convertSchemas(options.schemas);
|
|
565
|
+
const { credentialDefinitionIds, credentialDefinitions } = this.convertCredDefs(options.credentialDefinitions);
|
|
566
|
+
const ret = allocatePointer();
|
|
567
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_presentation(presentationRequest, credentialEntryList, credentialProveList, selfAttestNames, selfAttestValues, linkSecret, schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, ret);
|
|
568
|
+
this.handleError(errorCode);
|
|
569
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
570
|
+
}
|
|
571
|
+
verifyPresentation(options) {
|
|
572
|
+
const { presentation, presentationRequest, schemas, credentialDefinitions, revocationRegistryDefinitions, revocationStatusLists, revocationRegistryDefinitionIds, schemaIds, credentialDefinitionIds } = serializeArguments(options);
|
|
573
|
+
const nonRevokedIntervalOverrideList = this.convertNonRevokedIntervalOverrides(options.nonRevokedIntervalOverrides);
|
|
574
|
+
const ret = allocateInt8Buffer();
|
|
575
|
+
const errorCode = this.nativeAnoncreds.anoncreds_verify_presentation(presentation, presentationRequest, schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, revocationRegistryDefinitions ?? {}, revocationRegistryDefinitionIds ?? {}, revocationStatusLists ?? {}, nonRevokedIntervalOverrideList, ret);
|
|
576
|
+
this.handleError(errorCode);
|
|
577
|
+
return Boolean(handleReturnPointer(ret));
|
|
578
|
+
}
|
|
579
|
+
createRevocationStatusList(options) {
|
|
580
|
+
const { credentialDefinition, revocationRegistryDefinitionId, revocationRegistryDefinition, revocationRegistryDefinitionPrivate, issuerId, issuanceByDefault, timestamp } = serializeArguments(options);
|
|
581
|
+
const ret = allocatePointer();
|
|
582
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_revocation_status_list(credentialDefinition, revocationRegistryDefinitionId, revocationRegistryDefinition, revocationRegistryDefinitionPrivate, issuerId, issuanceByDefault, timestamp ?? -1, ret);
|
|
583
|
+
this.handleError(errorCode);
|
|
584
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
585
|
+
}
|
|
586
|
+
updateRevocationStatusListTimestampOnly(options) {
|
|
587
|
+
const { currentRevocationStatusList, timestamp } = serializeArguments(options);
|
|
588
|
+
const ret = allocatePointer();
|
|
589
|
+
const errorCode = this.nativeAnoncreds.anoncreds_update_revocation_status_list_timestamp_only(timestamp, currentRevocationStatusList, ret);
|
|
590
|
+
this.handleError(errorCode);
|
|
591
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
592
|
+
}
|
|
593
|
+
updateRevocationStatusList(options) {
|
|
594
|
+
const { credentialDefinition, revocationRegistryDefinition, revocationRegistryDefinitionPrivate, currentRevocationStatusList, issued, revoked, timestamp } = serializeArguments(options);
|
|
595
|
+
const ret = allocatePointer();
|
|
596
|
+
const errorCode = this.nativeAnoncreds.anoncreds_update_revocation_status_list(credentialDefinition, revocationRegistryDefinition, revocationRegistryDefinitionPrivate, currentRevocationStatusList, issued ?? {}, revoked ?? {}, timestamp ?? -1, ret);
|
|
597
|
+
this.handleError(errorCode);
|
|
598
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
599
|
+
}
|
|
600
|
+
createRevocationRegistryDefinition(options) {
|
|
601
|
+
const { credentialDefinition, credentialDefinitionId, tag, revocationRegistryType, issuerId, maximumCredentialNumber, tailsDirectoryPath } = serializeArguments(options);
|
|
602
|
+
const revocationRegistryDefinitionPtr = allocatePointer();
|
|
603
|
+
const revocationRegistryDefinitionPrivate = allocatePointer();
|
|
604
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_revocation_registry_def(credentialDefinition, credentialDefinitionId, issuerId, tag, revocationRegistryType, maximumCredentialNumber, tailsDirectoryPath, revocationRegistryDefinitionPtr, revocationRegistryDefinitionPrivate);
|
|
605
|
+
this.handleError(errorCode);
|
|
606
|
+
return {
|
|
607
|
+
revocationRegistryDefinition: new ObjectHandle(handleReturnPointer(revocationRegistryDefinitionPtr)),
|
|
608
|
+
revocationRegistryDefinitionPrivate: new ObjectHandle(handleReturnPointer(revocationRegistryDefinitionPrivate))
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
createOrUpdateRevocationState(options) {
|
|
612
|
+
const { revocationRegistryDefinition, revocationStatusList, revocationRegistryIndex, tailsPath } = serializeArguments(options);
|
|
613
|
+
const oldRevocationState = options.oldRevocationState ?? new ObjectHandle(0);
|
|
614
|
+
const oldRevocationStatusList = options.oldRevocationStatusList ?? new ObjectHandle(0);
|
|
615
|
+
const ret = allocatePointer();
|
|
616
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_or_update_revocation_state(revocationRegistryDefinition, revocationStatusList, revocationRegistryIndex, tailsPath, oldRevocationState.handle, oldRevocationStatusList.handle, ret);
|
|
617
|
+
this.handleError(errorCode);
|
|
618
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
619
|
+
}
|
|
620
|
+
createW3cCredential(options) {
|
|
621
|
+
const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, w3cVersion } = serializeArguments(options);
|
|
622
|
+
const attributeNames = this.convertAttributeNames(options.attributeRawValues);
|
|
623
|
+
const attributeRawValues = this.convertAttributeRawValues(options.attributeRawValues);
|
|
624
|
+
const revocationConfiguration = this.convertRevocationConfiguration(options.revocationConfiguration);
|
|
625
|
+
const credentialPtr = allocatePointer();
|
|
626
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_w3c_credential(credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, attributeNames, attributeRawValues, revocationConfiguration ?? 0, w3cVersion, credentialPtr);
|
|
627
|
+
this.handleError(errorCode);
|
|
628
|
+
return new ObjectHandle(handleReturnPointer(credentialPtr));
|
|
629
|
+
}
|
|
630
|
+
processW3cCredential(options) {
|
|
631
|
+
const { credential, credentialRequestMetadata, linkSecret, credentialDefinition } = serializeArguments(options);
|
|
632
|
+
const ret = allocatePointer();
|
|
633
|
+
const errorCode = this.nativeAnoncreds.anoncreds_process_w3c_credential(credential, credentialRequestMetadata, linkSecret, credentialDefinition, options.revocationRegistryDefinition?.handle ?? 0, ret);
|
|
634
|
+
this.handleError(errorCode);
|
|
635
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
636
|
+
}
|
|
637
|
+
createW3cPresentation(options) {
|
|
638
|
+
const { presentationRequest, linkSecret, w3cVersion } = serializeArguments(options);
|
|
639
|
+
const credentialEntryList = this.convertCredentialList(options.credentials);
|
|
640
|
+
const credentialProveList = this.convertCredentialProves(options.credentialsProve);
|
|
641
|
+
const { schemaIds, schemas } = this.convertSchemas(options.schemas);
|
|
642
|
+
const { credentialDefinitionIds, credentialDefinitions } = this.convertCredDefs(options.credentialDefinitions);
|
|
643
|
+
const ret = allocatePointer();
|
|
644
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_w3c_presentation(presentationRequest, credentialEntryList, credentialProveList, linkSecret, schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, w3cVersion, ret);
|
|
645
|
+
this.handleError(errorCode);
|
|
646
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
647
|
+
}
|
|
648
|
+
verifyW3cPresentation(options) {
|
|
649
|
+
const { presentation, presentationRequest, schemas, credentialDefinitions, revocationRegistryDefinitions, revocationStatusLists, revocationRegistryDefinitionIds, schemaIds, credentialDefinitionIds } = serializeArguments(options);
|
|
650
|
+
const nonRevokedIntervalOverrideList = this.convertNonRevokedIntervalOverrides(options.nonRevokedIntervalOverrides);
|
|
651
|
+
const ret = allocateInt8Buffer();
|
|
652
|
+
const errorCode = this.nativeAnoncreds.anoncreds_verify_w3c_presentation(presentation, presentationRequest, schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, revocationRegistryDefinitions ?? {}, revocationRegistryDefinitionIds ?? {}, revocationStatusLists ?? {}, nonRevokedIntervalOverrideList, ret);
|
|
653
|
+
this.handleError(errorCode);
|
|
654
|
+
return Boolean(handleReturnPointer(ret));
|
|
655
|
+
}
|
|
656
|
+
credentialToW3c(options) {
|
|
657
|
+
const { objectHandle, issuerId, w3cVersion } = serializeArguments(options);
|
|
658
|
+
const ret = allocatePointer();
|
|
659
|
+
const errorCode = this.nativeAnoncreds.anoncreds_credential_to_w3c(objectHandle, issuerId, w3cVersion, ret);
|
|
660
|
+
this.handleError(errorCode);
|
|
661
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
662
|
+
}
|
|
663
|
+
credentialFromW3c(options) {
|
|
664
|
+
const { objectHandle } = serializeArguments(options);
|
|
665
|
+
const ret = allocatePointer();
|
|
666
|
+
const errorCode = this.nativeAnoncreds.anoncreds_credential_from_w3c(objectHandle, ret);
|
|
667
|
+
this.handleError(errorCode);
|
|
668
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
669
|
+
}
|
|
670
|
+
w3cCredentialGetIntegrityProofDetails(options) {
|
|
671
|
+
const { objectHandle } = serializeArguments(options);
|
|
672
|
+
const ret = allocatePointer();
|
|
673
|
+
const errorCode = this.nativeAnoncreds.anoncreds_w3c_credential_get_integrity_proof_details(objectHandle, ret);
|
|
674
|
+
this.handleError(errorCode);
|
|
675
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
676
|
+
}
|
|
677
|
+
w3cCredentialProofGetAttribute(options) {
|
|
678
|
+
const { objectHandle, name } = serializeArguments(options);
|
|
679
|
+
const ret = allocateStringBuffer();
|
|
680
|
+
const errorCode = this.nativeAnoncreds.anoncreds_w3c_credential_proof_get_attribute(objectHandle, name, ret);
|
|
681
|
+
this.handleError(errorCode);
|
|
682
|
+
return (Array.isArray(ret) ? ret[0] : ret) ?? null;
|
|
683
|
+
}
|
|
684
|
+
w3cCredentialFromJson(options) {
|
|
685
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_w3c_credential_from_json, options);
|
|
686
|
+
}
|
|
687
|
+
w3cPresentationFromJson(options) {
|
|
688
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_w3c_presentation_from_json, options);
|
|
689
|
+
}
|
|
690
|
+
version() {
|
|
691
|
+
return this.nativeAnoncreds.anoncreds_version();
|
|
692
|
+
}
|
|
693
|
+
setDefaultLogger() {
|
|
694
|
+
const errorCode = this.nativeAnoncreds.anoncreds_set_default_logger();
|
|
695
|
+
this.handleError(errorCode);
|
|
696
|
+
}
|
|
697
|
+
objectFromJson(cb, options) {
|
|
698
|
+
const ret = allocatePointer();
|
|
699
|
+
const byteBuffer = new TextEncoder().encode(options.json);
|
|
700
|
+
const errorCode = cb({
|
|
701
|
+
data: byteBuffer,
|
|
702
|
+
len: byteBuffer.length
|
|
703
|
+
}, ret);
|
|
704
|
+
this.handleError(errorCode);
|
|
705
|
+
return new ObjectHandle(handleReturnPointer(ret));
|
|
706
|
+
}
|
|
707
|
+
presentationRequestFromJson(options) {
|
|
708
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_presentation_request_from_json, options);
|
|
709
|
+
}
|
|
710
|
+
credentialRequestFromJson(options) {
|
|
711
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_credential_request_from_json, options);
|
|
712
|
+
}
|
|
713
|
+
credentialRequestMetadataFromJson(options) {
|
|
714
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_credential_request_metadata_from_json, options);
|
|
715
|
+
}
|
|
716
|
+
revocationRegistryDefinitionFromJson(options) {
|
|
717
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_revocation_registry_definition_from_json, options);
|
|
718
|
+
}
|
|
719
|
+
revocationRegistryFromJson(options) {
|
|
720
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_revocation_registry_from_json, options);
|
|
721
|
+
}
|
|
722
|
+
revocationStatusListFromJson(options) {
|
|
723
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_revocation_status_list_from_json, options);
|
|
724
|
+
}
|
|
725
|
+
revocationStateFromJson(options) {
|
|
726
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_revocation_state_from_json, options);
|
|
727
|
+
}
|
|
728
|
+
presentationFromJson(options) {
|
|
729
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_presentation_from_json, options);
|
|
730
|
+
}
|
|
731
|
+
credentialOfferFromJson(options) {
|
|
732
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_credential_offer_from_json, options);
|
|
733
|
+
}
|
|
734
|
+
schemaFromJson(options) {
|
|
735
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_schema_from_json, options);
|
|
736
|
+
}
|
|
737
|
+
credentialFromJson(options) {
|
|
738
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_credential_from_json, options);
|
|
739
|
+
}
|
|
740
|
+
revocationRegistryDefinitionPrivateFromJson(options) {
|
|
741
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_revocation_registry_definition_private_from_json, options);
|
|
742
|
+
}
|
|
743
|
+
credentialDefinitionFromJson(options) {
|
|
744
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_credential_definition_from_json, options);
|
|
745
|
+
}
|
|
746
|
+
credentialDefinitionPrivateFromJson(options) {
|
|
747
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_credential_definition_private_from_json, options);
|
|
748
|
+
}
|
|
749
|
+
keyCorrectnessProofFromJson(options) {
|
|
750
|
+
return this.objectFromJson(this.nativeAnoncreds.anoncreds_key_correctness_proof_from_json, options);
|
|
751
|
+
}
|
|
752
|
+
getJson(options) {
|
|
753
|
+
const { objectHandle } = serializeArguments(options);
|
|
754
|
+
const ret = allocateByteBuffer();
|
|
755
|
+
const errorCode = this.nativeAnoncreds.anoncreds_object_get_json(objectHandle, ret);
|
|
756
|
+
this.handleError(errorCode);
|
|
757
|
+
const returnValue = handleReturnPointer(ret);
|
|
758
|
+
const output = byteBufferToString(returnValue);
|
|
759
|
+
this.nativeAnoncreds.anoncreds_buffer_free(returnValue);
|
|
760
|
+
return output;
|
|
761
|
+
}
|
|
762
|
+
getTypeName(options) {
|
|
763
|
+
const { objectHandle } = serializeArguments(options);
|
|
764
|
+
const ret = allocateStringBuffer();
|
|
765
|
+
const errorCode = this.nativeAnoncreds.anoncreds_object_get_type_name(objectHandle, ret);
|
|
766
|
+
this.handleError(errorCode);
|
|
767
|
+
return handleReturnPointer(ret);
|
|
768
|
+
}
|
|
769
|
+
objectFree(options) {
|
|
770
|
+
this.nativeAnoncreds.anoncreds_object_free(options.objectHandle.handle);
|
|
771
|
+
}
|
|
772
|
+
convertCredentialList(credentials) {
|
|
773
|
+
const credentialEntries = credentials.map((value) => ({
|
|
774
|
+
credential: value.credential.handle,
|
|
775
|
+
timestamp: value.timestamp ?? -1,
|
|
776
|
+
rev_state: value.revocationState?.handle ?? 0
|
|
777
|
+
}));
|
|
778
|
+
return {
|
|
779
|
+
count: credentialEntries.length,
|
|
780
|
+
data: credentialEntries
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
convertCredentialProves(credentialsProve) {
|
|
784
|
+
const credentialProves = credentialsProve.map((value) => {
|
|
785
|
+
const { entryIndex: entry_idx, isPredicate: is_predicate, reveal, referent } = serializeArguments(value);
|
|
786
|
+
return {
|
|
787
|
+
entry_idx,
|
|
788
|
+
referent,
|
|
789
|
+
is_predicate,
|
|
790
|
+
reveal
|
|
791
|
+
};
|
|
792
|
+
});
|
|
793
|
+
return {
|
|
794
|
+
count: credentialProves.length,
|
|
795
|
+
data: credentialProves
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
convertSchemas(schemas) {
|
|
799
|
+
const schemaKeys = Object.keys(schemas);
|
|
800
|
+
const schemaIds = {
|
|
801
|
+
count: schemaKeys.length,
|
|
802
|
+
data: schemaKeys
|
|
803
|
+
};
|
|
804
|
+
const schemaValues = Object.values(schemas);
|
|
805
|
+
return {
|
|
806
|
+
schemaIds,
|
|
807
|
+
schemas: {
|
|
808
|
+
count: schemaValues.length,
|
|
809
|
+
data: schemaValues.map((o) => o.handle)
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
convertCredDefs(credentialDefinitions) {
|
|
814
|
+
const credentialDefinitionKeys = Object.keys(credentialDefinitions);
|
|
815
|
+
const credentialDefinitionIds = {
|
|
816
|
+
count: credentialDefinitionKeys.length,
|
|
817
|
+
data: credentialDefinitionKeys
|
|
818
|
+
};
|
|
819
|
+
const credentialDefinitionValues = Object.values(credentialDefinitions);
|
|
820
|
+
return {
|
|
821
|
+
credentialDefinitionIds,
|
|
822
|
+
credentialDefinitions: {
|
|
823
|
+
count: credentialDefinitionValues.length,
|
|
824
|
+
data: credentialDefinitionValues.map((o) => o.handle)
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
convertNonRevokedIntervalOverrides(nonRevokedIntervalOverrides) {
|
|
829
|
+
const nativeNonRevokedIntervalOverrides = nonRevokedIntervalOverrides?.map((value) => {
|
|
830
|
+
const { requestedFromTimestamp, revocationRegistryDefinitionId, overrideRevocationStatusListTimestamp } = serializeArguments(value);
|
|
831
|
+
return {
|
|
832
|
+
rev_reg_def_id: revocationRegistryDefinitionId,
|
|
833
|
+
requested_from_ts: requestedFromTimestamp,
|
|
834
|
+
override_rev_status_list_ts: overrideRevocationStatusListTimestamp
|
|
835
|
+
};
|
|
836
|
+
});
|
|
837
|
+
return {
|
|
838
|
+
count: nonRevokedIntervalOverrides?.length ?? 0,
|
|
839
|
+
data: nativeNonRevokedIntervalOverrides
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
convertAttributeNames(attributeRawValues) {
|
|
843
|
+
return {
|
|
844
|
+
count: Object.keys(attributeRawValues).length,
|
|
845
|
+
data: Object.keys(attributeRawValues)
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
convertAttributeRawValues(attributeRawValues) {
|
|
849
|
+
return {
|
|
850
|
+
count: Object.keys(attributeRawValues).length,
|
|
851
|
+
data: Object.values(attributeRawValues)
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
convertRevocationConfiguration(revocationConfiguration) {
|
|
855
|
+
if (revocationConfiguration) {
|
|
856
|
+
const { revocationRegistryDefinition, revocationRegistryDefinitionPrivate, revocationStatusList, registryIndex } = serializeArguments(revocationConfiguration);
|
|
857
|
+
return {
|
|
858
|
+
reg_def: revocationRegistryDefinition,
|
|
859
|
+
reg_def_private: revocationRegistryDefinitionPrivate,
|
|
860
|
+
status_list: revocationStatusList,
|
|
861
|
+
reg_idx: registryIndex
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
// src/index.ts
|
|
867
|
+
const anoncredsNodeJS = new NodeJSAnoncreds();
|
|
868
|
+
NativeAnoncreds.register(anoncredsNodeJS);
|
|
869
|
+
export { anoncredsNodeJS };
|
|
870
|
+
|
|
871
|
+
//# sourceMappingURL=index.mjs.map
|