@hyperledger/anoncreds-nodejs 0.3.5-alpha-20260107085331 → 0.4.0-alpha-20260212142546
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/NodeJSAnoncreds.d.ts +14 -55
- package/build/NodeJSAnoncreds.js +160 -130
- package/build/NodeJSAnoncreds.js.map +1 -1
- package/build/ffi/alloc.d.ts +10 -5
- package/build/ffi/alloc.js +32 -12
- package/build/ffi/alloc.js.map +1 -1
- package/build/ffi/conversion.d.ts +16 -7
- package/build/ffi/conversion.js +36 -5
- package/build/ffi/conversion.js.map +1 -1
- package/build/ffi/primitives.d.ts +11 -14
- package/build/ffi/primitives.js +35 -18
- package/build/ffi/primitives.js.map +1 -1
- package/build/ffi/serialize.d.ts +1 -18
- package/build/ffi/serialize.js +5 -16
- package/build/ffi/serialize.js.map +1 -1
- package/build/ffi/structures.d.ts +28 -119
- package/build/ffi/structures.js +29 -84
- package/build/ffi/structures.js.map +1 -1
- package/build/index.js.map +1 -1
- package/build/library/NativeBindingInterface.d.ts +1 -24
- package/build/library/bindings.d.ts +2 -253
- package/build/library/bindings.js +242 -135
- package/build/library/bindings.js.map +1 -1
- package/build/library/register.d.ts +2 -53
- package/build/library/register.js +27 -23
- package/build/library/register.js.map +1 -1
- package/package.json +6 -10
package/build/NodeJSAnoncreds.js
CHANGED
|
@@ -1,56 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NodeJSAnoncreds = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_util_1 = require("node:util");
|
|
5
5
|
const anoncreds_shared_1 = require("@hyperledger/anoncreds-shared");
|
|
6
6
|
const ffi_1 = require("./ffi");
|
|
7
7
|
const library_1 = require("./library");
|
|
8
|
-
function handleReturnPointer(returnValue
|
|
9
|
-
|
|
8
|
+
function handleReturnPointer(returnValue) {
|
|
9
|
+
const value = Array.isArray(returnValue) ? returnValue[0] : returnValue;
|
|
10
|
+
if (value === null || value === undefined) {
|
|
10
11
|
throw anoncreds_shared_1.AnoncredsError.customError({ message: 'Unexpected null pointer' });
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
if (cleanupCallback)
|
|
14
|
-
cleanupCallback(returnValue);
|
|
15
|
-
return ret;
|
|
13
|
+
return value;
|
|
16
14
|
}
|
|
17
15
|
class NodeJSAnoncreds {
|
|
18
|
-
handleError() {
|
|
19
|
-
const nativeError = (0, ffi_1.allocateStringBuffer)();
|
|
20
|
-
(0, library_1.getNativeAnoncreds)().anoncreds_get_current_error(nativeError);
|
|
21
|
-
const anoncredsErrorObject = JSON.parse(nativeError.deref());
|
|
22
|
-
if (anoncredsErrorObject.code === 0)
|
|
23
|
-
return;
|
|
24
|
-
throw new anoncreds_shared_1.AnoncredsError(anoncredsErrorObject);
|
|
25
|
-
}
|
|
26
16
|
get nativeAnoncreds() {
|
|
27
|
-
return (0, library_1.
|
|
17
|
+
return (0, library_1.getNativeAnonCreds)();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Fetch the error from the native library and throw it as a JS error
|
|
21
|
+
*
|
|
22
|
+
* NOTE:
|
|
23
|
+
* Checks whether the error code of the returned error matches the error code that was passed to the function.
|
|
24
|
+
* If it doesn't, we throw an error with the original errorCode, and a custom message explaining we weren't able
|
|
25
|
+
* to retrieve the error message from the native library. This should however not break functionality as long as
|
|
26
|
+
* error codes are used rather than error messages for error handling.
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
getAnoncredsError(errorCode) {
|
|
30
|
+
const error = this.getCurrentError();
|
|
31
|
+
if (error.code !== errorCode) {
|
|
32
|
+
return new anoncreds_shared_1.AnoncredsError({
|
|
33
|
+
code: errorCode,
|
|
34
|
+
message: 'Error details have already been overwritten on the native side, unable to retrieve error message for the error',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return new anoncreds_shared_1.AnoncredsError(error);
|
|
38
|
+
}
|
|
39
|
+
getCurrentError() {
|
|
40
|
+
const error = (0, ffi_1.allocateStringBuffer)();
|
|
41
|
+
this.nativeAnoncreds.anoncreds_get_current_error(error);
|
|
42
|
+
const serializedError = handleReturnPointer(error);
|
|
43
|
+
return JSON.parse(serializedError);
|
|
44
|
+
}
|
|
45
|
+
handleError(errorCode) {
|
|
46
|
+
if (errorCode === 0)
|
|
47
|
+
return;
|
|
48
|
+
throw this.getAnoncredsError(errorCode);
|
|
28
49
|
}
|
|
29
50
|
generateNonce() {
|
|
30
51
|
const ret = (0, ffi_1.allocateStringBuffer)();
|
|
31
|
-
this.nativeAnoncreds.anoncreds_generate_nonce(ret);
|
|
32
|
-
this.handleError();
|
|
52
|
+
const errorCode = this.nativeAnoncreds.anoncreds_generate_nonce(ret);
|
|
53
|
+
this.handleError(errorCode);
|
|
33
54
|
return handleReturnPointer(ret);
|
|
34
55
|
}
|
|
35
56
|
createSchema(options) {
|
|
36
57
|
const { name, version, issuerId, attributeNames } = (0, ffi_1.serializeArguments)(options);
|
|
37
58
|
const ret = (0, ffi_1.allocatePointer)();
|
|
38
|
-
this.nativeAnoncreds.anoncreds_create_schema(name, version, issuerId, attributeNames, ret);
|
|
39
|
-
this.handleError();
|
|
59
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_schema(name, version, issuerId, attributeNames, ret);
|
|
60
|
+
this.handleError(errorCode);
|
|
40
61
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
41
62
|
}
|
|
42
63
|
revocationRegistryDefinitionGetAttribute(options) {
|
|
43
64
|
const { objectHandle, name } = (0, ffi_1.serializeArguments)(options);
|
|
44
65
|
const ret = (0, ffi_1.allocateStringBuffer)();
|
|
45
|
-
this.nativeAnoncreds.anoncreds_revocation_registry_definition_get_attribute(objectHandle, name, ret);
|
|
46
|
-
this.handleError();
|
|
66
|
+
const errorCode = this.nativeAnoncreds.anoncreds_revocation_registry_definition_get_attribute(objectHandle, name, ret);
|
|
67
|
+
this.handleError(errorCode);
|
|
47
68
|
return handleReturnPointer(ret);
|
|
48
69
|
}
|
|
49
70
|
credentialGetAttribute(options) {
|
|
50
71
|
const { objectHandle, name } = (0, ffi_1.serializeArguments)(options);
|
|
51
72
|
const ret = (0, ffi_1.allocateStringBuffer)();
|
|
52
|
-
this.nativeAnoncreds.anoncreds_credential_get_attribute(objectHandle, name, ret);
|
|
53
|
-
this.handleError();
|
|
73
|
+
const errorCode = this.nativeAnoncreds.anoncreds_credential_get_attribute(objectHandle, name, ret);
|
|
74
|
+
this.handleError(errorCode);
|
|
54
75
|
return handleReturnPointer(ret);
|
|
55
76
|
}
|
|
56
77
|
createCredentialDefinition(options) {
|
|
@@ -58,8 +79,8 @@ class NodeJSAnoncreds {
|
|
|
58
79
|
const credentialDefinitionPtr = (0, ffi_1.allocatePointer)();
|
|
59
80
|
const credentialDefinitionPrivatePtr = (0, ffi_1.allocatePointer)();
|
|
60
81
|
const keyCorrectnessProofPtr = (0, ffi_1.allocatePointer)();
|
|
61
|
-
this.nativeAnoncreds.anoncreds_create_credential_definition(schemaId, schema, tag, issuerId, signatureType, supportRevocation, credentialDefinitionPtr, credentialDefinitionPrivatePtr, keyCorrectnessProofPtr);
|
|
62
|
-
this.handleError();
|
|
82
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_credential_definition(schemaId, schema, tag, issuerId, signatureType, supportRevocation, credentialDefinitionPtr, credentialDefinitionPrivatePtr, keyCorrectnessProofPtr);
|
|
83
|
+
this.handleError(errorCode);
|
|
63
84
|
return {
|
|
64
85
|
credentialDefinition: new anoncreds_shared_1.ObjectHandle(handleReturnPointer(credentialDefinitionPtr)),
|
|
65
86
|
credentialDefinitionPrivate: new anoncreds_shared_1.ObjectHandle(handleReturnPointer(credentialDefinitionPrivatePtr)),
|
|
@@ -67,22 +88,41 @@ class NodeJSAnoncreds {
|
|
|
67
88
|
};
|
|
68
89
|
}
|
|
69
90
|
createCredential(options) {
|
|
70
|
-
var _a;
|
|
71
91
|
const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest } = (0, ffi_1.serializeArguments)(options);
|
|
72
|
-
const attributeNames =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
92
|
+
const attributeNames = {
|
|
93
|
+
count: Object.keys(options.attributeRawValues).length,
|
|
94
|
+
data: Object.keys(options.attributeRawValues),
|
|
95
|
+
};
|
|
96
|
+
const attributeRawValues = {
|
|
97
|
+
count: Object.keys(options.attributeRawValues).length,
|
|
98
|
+
data: Object.values(options.attributeRawValues),
|
|
99
|
+
};
|
|
100
|
+
const attributeEncodedValues = options.attributeEncodedValues
|
|
101
|
+
? {
|
|
102
|
+
count: Object.keys(options.attributeEncodedValues).length,
|
|
103
|
+
data: Object.values(options.attributeEncodedValues),
|
|
104
|
+
}
|
|
105
|
+
: {};
|
|
106
|
+
let revocationConfiguration = null;
|
|
107
|
+
if (options.revocationConfiguration) {
|
|
108
|
+
const { revocationStatusList, revocationRegistryDefinitionPrivate, revocationRegistryDefinition, registryIndex } = (0, ffi_1.serializeArguments)(options.revocationConfiguration);
|
|
109
|
+
revocationConfiguration = {
|
|
110
|
+
reg_def: revocationRegistryDefinition,
|
|
111
|
+
reg_def_private: revocationRegistryDefinitionPrivate,
|
|
112
|
+
status_list: revocationStatusList,
|
|
113
|
+
reg_idx: registryIndex,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
76
116
|
const credentialPtr = (0, ffi_1.allocatePointer)();
|
|
77
|
-
this.nativeAnoncreds.anoncreds_create_credential(credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, attributeNames, attributeRawValues, attributeEncodedValues,
|
|
78
|
-
this.handleError();
|
|
117
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_credential(credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, attributeNames, attributeRawValues, attributeEncodedValues, revocationConfiguration, credentialPtr);
|
|
118
|
+
this.handleError(errorCode);
|
|
79
119
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(credentialPtr));
|
|
80
120
|
}
|
|
81
121
|
encodeCredentialAttributes(options) {
|
|
82
122
|
const { attributeRawValues } = (0, ffi_1.serializeArguments)(options);
|
|
83
123
|
const ret = (0, ffi_1.allocateStringBuffer)();
|
|
84
|
-
this.nativeAnoncreds.anoncreds_encode_credential_attributes(attributeRawValues, ret);
|
|
85
|
-
this.handleError();
|
|
124
|
+
const errorCode = this.nativeAnoncreds.anoncreds_encode_credential_attributes(attributeRawValues, ret);
|
|
125
|
+
this.handleError(errorCode);
|
|
86
126
|
const result = handleReturnPointer(ret);
|
|
87
127
|
return result.split(',');
|
|
88
128
|
}
|
|
@@ -90,23 +130,23 @@ class NodeJSAnoncreds {
|
|
|
90
130
|
var _a, _b;
|
|
91
131
|
const { credential, credentialRequestMetadata, linkSecret, credentialDefinition } = (0, ffi_1.serializeArguments)(options);
|
|
92
132
|
const ret = (0, ffi_1.allocatePointer)();
|
|
93
|
-
this.nativeAnoncreds.anoncreds_process_credential(credential, credentialRequestMetadata, linkSecret, credentialDefinition, (_b = (_a = options.revocationRegistryDefinition) === null || _a === void 0 ? void 0 : _a.handle) !== null && _b !== void 0 ? _b : 0, ret);
|
|
94
|
-
this.handleError();
|
|
133
|
+
const errorCode = this.nativeAnoncreds.anoncreds_process_credential(credential, credentialRequestMetadata, linkSecret, credentialDefinition, (_b = (_a = options.revocationRegistryDefinition) === null || _a === void 0 ? void 0 : _a.handle) !== null && _b !== void 0 ? _b : 0, ret);
|
|
134
|
+
this.handleError(errorCode);
|
|
95
135
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
96
136
|
}
|
|
97
137
|
createCredentialOffer(options) {
|
|
98
138
|
const { schemaId, credentialDefinitionId, keyCorrectnessProof } = (0, ffi_1.serializeArguments)(options);
|
|
99
139
|
const ret = (0, ffi_1.allocatePointer)();
|
|
100
|
-
this.nativeAnoncreds.anoncreds_create_credential_offer(schemaId, credentialDefinitionId, keyCorrectnessProof, ret);
|
|
101
|
-
this.handleError();
|
|
140
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_credential_offer(schemaId, credentialDefinitionId, keyCorrectnessProof, ret);
|
|
141
|
+
this.handleError(errorCode);
|
|
102
142
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
103
143
|
}
|
|
104
144
|
createCredentialRequest(options) {
|
|
105
145
|
const { entropy, proverDid, credentialDefinition, linkSecret, linkSecretId, credentialOffer } = (0, ffi_1.serializeArguments)(options);
|
|
106
146
|
const credentialRequestPtr = (0, ffi_1.allocatePointer)();
|
|
107
147
|
const credentialRequestMetadataPtr = (0, ffi_1.allocatePointer)();
|
|
108
|
-
this.nativeAnoncreds.anoncreds_create_credential_request(entropy, proverDid, credentialDefinition, linkSecret, linkSecretId, credentialOffer, credentialRequestPtr, credentialRequestMetadataPtr);
|
|
109
|
-
this.handleError();
|
|
148
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_credential_request(entropy, proverDid, credentialDefinition, linkSecret, linkSecretId, credentialOffer, credentialRequestPtr, credentialRequestMetadataPtr);
|
|
149
|
+
this.handleError(errorCode);
|
|
110
150
|
return {
|
|
111
151
|
credentialRequest: new anoncreds_shared_1.ObjectHandle(handleReturnPointer(credentialRequestPtr)),
|
|
112
152
|
credentialRequestMetadata: new anoncreds_shared_1.ObjectHandle(handleReturnPointer(credentialRequestMetadataPtr)),
|
|
@@ -114,64 +154,64 @@ class NodeJSAnoncreds {
|
|
|
114
154
|
}
|
|
115
155
|
createLinkSecret() {
|
|
116
156
|
const ret = (0, ffi_1.allocateStringBuffer)();
|
|
117
|
-
this.nativeAnoncreds.anoncreds_create_link_secret(ret);
|
|
118
|
-
this.handleError();
|
|
157
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_link_secret(ret);
|
|
158
|
+
this.handleError(errorCode);
|
|
119
159
|
return handleReturnPointer(ret);
|
|
120
160
|
}
|
|
121
161
|
createPresentation(options) {
|
|
122
162
|
const { presentationRequest, linkSecret } = (0, ffi_1.serializeArguments)(options);
|
|
123
|
-
const selfAttestNames =
|
|
163
|
+
const selfAttestNames = {
|
|
124
164
|
count: Object.keys(options.selfAttest).length,
|
|
125
165
|
data: Object.keys(options.selfAttest),
|
|
126
|
-
}
|
|
127
|
-
const selfAttestValues =
|
|
166
|
+
};
|
|
167
|
+
const selfAttestValues = {
|
|
128
168
|
count: Object.values(options.selfAttest).length,
|
|
129
169
|
data: Object.values(options.selfAttest),
|
|
130
|
-
}
|
|
170
|
+
};
|
|
131
171
|
const credentialEntryList = this.convertCredentialList(options.credentials);
|
|
132
172
|
const credentialProveList = this.convertCredentialProves(options.credentialsProve);
|
|
133
173
|
const { schemaIds, schemas } = this.convertSchemas(options.schemas);
|
|
134
174
|
const { credentialDefinitionIds, credentialDefinitions } = this.convertCredDefs(options.credentialDefinitions);
|
|
135
175
|
const ret = (0, ffi_1.allocatePointer)();
|
|
136
|
-
this.nativeAnoncreds.anoncreds_create_presentation(presentationRequest, credentialEntryList, credentialProveList, selfAttestNames, selfAttestValues, linkSecret, schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, ret);
|
|
137
|
-
this.handleError();
|
|
176
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_presentation(presentationRequest, credentialEntryList, credentialProveList, selfAttestNames, selfAttestValues, linkSecret, schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, ret);
|
|
177
|
+
this.handleError(errorCode);
|
|
138
178
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
139
179
|
}
|
|
140
180
|
verifyPresentation(options) {
|
|
141
181
|
const { presentation, presentationRequest, schemas, credentialDefinitions, revocationRegistryDefinitions, revocationStatusLists, revocationRegistryDefinitionIds, schemaIds, credentialDefinitionIds, } = (0, ffi_1.serializeArguments)(options);
|
|
142
182
|
const nonRevokedIntervalOverrideList = this.convertNonRevokedIntervalOverrides(options.nonRevokedIntervalOverrides);
|
|
143
183
|
const ret = (0, ffi_1.allocateInt8Buffer)();
|
|
144
|
-
this.nativeAnoncreds.anoncreds_verify_presentation(presentation, presentationRequest, schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, revocationRegistryDefinitions, revocationRegistryDefinitionIds, revocationStatusLists, nonRevokedIntervalOverrideList, ret);
|
|
145
|
-
this.handleError();
|
|
184
|
+
const errorCode = this.nativeAnoncreds.anoncreds_verify_presentation(presentation, presentationRequest, schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, revocationRegistryDefinitions !== null && revocationRegistryDefinitions !== void 0 ? revocationRegistryDefinitions : {}, revocationRegistryDefinitionIds !== null && revocationRegistryDefinitionIds !== void 0 ? revocationRegistryDefinitionIds : {}, revocationStatusLists !== null && revocationStatusLists !== void 0 ? revocationStatusLists : {}, nonRevokedIntervalOverrideList, ret);
|
|
185
|
+
this.handleError(errorCode);
|
|
146
186
|
return Boolean(handleReturnPointer(ret));
|
|
147
187
|
}
|
|
148
188
|
createRevocationStatusList(options) {
|
|
149
189
|
const { credentialDefinition, revocationRegistryDefinitionId, revocationRegistryDefinition, revocationRegistryDefinitionPrivate, issuerId, issuanceByDefault, timestamp, } = (0, ffi_1.serializeArguments)(options);
|
|
150
190
|
const ret = (0, ffi_1.allocatePointer)();
|
|
151
|
-
this.nativeAnoncreds.anoncreds_create_revocation_status_list(credentialDefinition, revocationRegistryDefinitionId, revocationRegistryDefinition, revocationRegistryDefinitionPrivate, issuerId, issuanceByDefault, timestamp !== null && timestamp !== void 0 ? timestamp : -1, ret);
|
|
152
|
-
this.handleError();
|
|
191
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_revocation_status_list(credentialDefinition, revocationRegistryDefinitionId, revocationRegistryDefinition, revocationRegistryDefinitionPrivate, issuerId, issuanceByDefault, timestamp !== null && timestamp !== void 0 ? timestamp : -1, ret);
|
|
192
|
+
this.handleError(errorCode);
|
|
153
193
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
154
194
|
}
|
|
155
195
|
updateRevocationStatusListTimestampOnly(options) {
|
|
156
196
|
const { currentRevocationStatusList, timestamp } = (0, ffi_1.serializeArguments)(options);
|
|
157
197
|
const ret = (0, ffi_1.allocatePointer)();
|
|
158
|
-
this.nativeAnoncreds.anoncreds_update_revocation_status_list_timestamp_only(timestamp, currentRevocationStatusList, ret);
|
|
159
|
-
this.handleError();
|
|
198
|
+
const errorCode = this.nativeAnoncreds.anoncreds_update_revocation_status_list_timestamp_only(timestamp, currentRevocationStatusList, ret);
|
|
199
|
+
this.handleError(errorCode);
|
|
160
200
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
161
201
|
}
|
|
162
202
|
updateRevocationStatusList(options) {
|
|
163
203
|
const { credentialDefinition, revocationRegistryDefinition, revocationRegistryDefinitionPrivate, currentRevocationStatusList, issued, revoked, timestamp, } = (0, ffi_1.serializeArguments)(options);
|
|
164
204
|
const ret = (0, ffi_1.allocatePointer)();
|
|
165
|
-
this.nativeAnoncreds.anoncreds_update_revocation_status_list(credentialDefinition, revocationRegistryDefinition, revocationRegistryDefinitionPrivate, currentRevocationStatusList, issued, revoked, timestamp !== null && timestamp !== void 0 ? timestamp : -1, ret);
|
|
166
|
-
this.handleError();
|
|
205
|
+
const errorCode = this.nativeAnoncreds.anoncreds_update_revocation_status_list(credentialDefinition, revocationRegistryDefinition, revocationRegistryDefinitionPrivate, currentRevocationStatusList, issued !== null && issued !== void 0 ? issued : {}, revoked !== null && revoked !== void 0 ? revoked : {}, timestamp !== null && timestamp !== void 0 ? timestamp : -1, ret);
|
|
206
|
+
this.handleError(errorCode);
|
|
167
207
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
168
208
|
}
|
|
169
209
|
createRevocationRegistryDefinition(options) {
|
|
170
210
|
const { credentialDefinition, credentialDefinitionId, tag, revocationRegistryType, issuerId, maximumCredentialNumber, tailsDirectoryPath, } = (0, ffi_1.serializeArguments)(options);
|
|
171
211
|
const revocationRegistryDefinitionPtr = (0, ffi_1.allocatePointer)();
|
|
172
212
|
const revocationRegistryDefinitionPrivate = (0, ffi_1.allocatePointer)();
|
|
173
|
-
this.nativeAnoncreds.anoncreds_create_revocation_registry_def(credentialDefinition, credentialDefinitionId, issuerId, tag, revocationRegistryType, maximumCredentialNumber, tailsDirectoryPath, revocationRegistryDefinitionPtr, revocationRegistryDefinitionPrivate);
|
|
174
|
-
this.handleError();
|
|
213
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_revocation_registry_def(credentialDefinition, credentialDefinitionId, issuerId, tag, revocationRegistryType, maximumCredentialNumber, tailsDirectoryPath, revocationRegistryDefinitionPtr, revocationRegistryDefinitionPrivate);
|
|
214
|
+
this.handleError(errorCode);
|
|
175
215
|
return {
|
|
176
216
|
revocationRegistryDefinition: new anoncreds_shared_1.ObjectHandle(handleReturnPointer(revocationRegistryDefinitionPtr)),
|
|
177
217
|
revocationRegistryDefinitionPrivate: new anoncreds_shared_1.ObjectHandle(handleReturnPointer(revocationRegistryDefinitionPrivate)),
|
|
@@ -183,27 +223,26 @@ class NodeJSAnoncreds {
|
|
|
183
223
|
const oldRevocationState = (_a = options.oldRevocationState) !== null && _a !== void 0 ? _a : new anoncreds_shared_1.ObjectHandle(0);
|
|
184
224
|
const oldRevocationStatusList = (_b = options.oldRevocationStatusList) !== null && _b !== void 0 ? _b : new anoncreds_shared_1.ObjectHandle(0);
|
|
185
225
|
const ret = (0, ffi_1.allocatePointer)();
|
|
186
|
-
this.nativeAnoncreds.anoncreds_create_or_update_revocation_state(revocationRegistryDefinition, revocationStatusList, revocationRegistryIndex, tailsPath, oldRevocationState.handle, oldRevocationStatusList.handle, ret);
|
|
187
|
-
this.handleError();
|
|
226
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_or_update_revocation_state(revocationRegistryDefinition, revocationStatusList, revocationRegistryIndex, tailsPath, oldRevocationState.handle, oldRevocationStatusList.handle, ret);
|
|
227
|
+
this.handleError(errorCode);
|
|
188
228
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
189
229
|
}
|
|
190
230
|
createW3cCredential(options) {
|
|
191
|
-
var _a;
|
|
192
231
|
const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, w3cVersion } = (0, ffi_1.serializeArguments)(options);
|
|
193
232
|
const attributeNames = this.convertAttributeNames(options.attributeRawValues);
|
|
194
233
|
const attributeRawValues = this.convertAttributeRawValues(options.attributeRawValues);
|
|
195
234
|
const revocationConfiguration = this.convertRevocationConfiguration(options.revocationConfiguration);
|
|
196
235
|
const credentialPtr = (0, ffi_1.allocatePointer)();
|
|
197
|
-
this.nativeAnoncreds.anoncreds_create_w3c_credential(credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, attributeNames, attributeRawValues,
|
|
198
|
-
this.handleError();
|
|
236
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_w3c_credential(credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, attributeNames, attributeRawValues, revocationConfiguration !== null && revocationConfiguration !== void 0 ? revocationConfiguration : 0, w3cVersion, credentialPtr);
|
|
237
|
+
this.handleError(errorCode);
|
|
199
238
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(credentialPtr));
|
|
200
239
|
}
|
|
201
240
|
processW3cCredential(options) {
|
|
202
241
|
var _a, _b;
|
|
203
242
|
const { credential, credentialRequestMetadata, linkSecret, credentialDefinition } = (0, ffi_1.serializeArguments)(options);
|
|
204
243
|
const ret = (0, ffi_1.allocatePointer)();
|
|
205
|
-
this.nativeAnoncreds.anoncreds_process_w3c_credential(credential, credentialRequestMetadata, linkSecret, credentialDefinition, (_b = (_a = options.revocationRegistryDefinition) === null || _a === void 0 ? void 0 : _a.handle) !== null && _b !== void 0 ? _b : 0, ret);
|
|
206
|
-
this.handleError();
|
|
244
|
+
const errorCode = this.nativeAnoncreds.anoncreds_process_w3c_credential(credential, credentialRequestMetadata, linkSecret, credentialDefinition, (_b = (_a = options.revocationRegistryDefinition) === null || _a === void 0 ? void 0 : _a.handle) !== null && _b !== void 0 ? _b : 0, ret);
|
|
245
|
+
this.handleError(errorCode);
|
|
207
246
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
208
247
|
}
|
|
209
248
|
createW3cPresentation(options) {
|
|
@@ -213,44 +252,44 @@ class NodeJSAnoncreds {
|
|
|
213
252
|
const { schemaIds, schemas } = this.convertSchemas(options.schemas);
|
|
214
253
|
const { credentialDefinitionIds, credentialDefinitions } = this.convertCredDefs(options.credentialDefinitions);
|
|
215
254
|
const ret = (0, ffi_1.allocatePointer)();
|
|
216
|
-
this.nativeAnoncreds.anoncreds_create_w3c_presentation(presentationRequest, credentialEntryList, credentialProveList, linkSecret, schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, w3cVersion, ret);
|
|
217
|
-
this.handleError();
|
|
255
|
+
const errorCode = this.nativeAnoncreds.anoncreds_create_w3c_presentation(presentationRequest, credentialEntryList, credentialProveList, linkSecret, schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, w3cVersion, ret);
|
|
256
|
+
this.handleError(errorCode);
|
|
218
257
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
219
258
|
}
|
|
220
259
|
verifyW3cPresentation(options) {
|
|
221
260
|
const { presentation, presentationRequest, schemas, credentialDefinitions, revocationRegistryDefinitions, revocationStatusLists, revocationRegistryDefinitionIds, schemaIds, credentialDefinitionIds, } = (0, ffi_1.serializeArguments)(options);
|
|
222
261
|
const nonRevokedIntervalOverrideList = this.convertNonRevokedIntervalOverrides(options.nonRevokedIntervalOverrides);
|
|
223
262
|
const ret = (0, ffi_1.allocateInt8Buffer)();
|
|
224
|
-
this.nativeAnoncreds.anoncreds_verify_w3c_presentation(presentation, presentationRequest, schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, revocationRegistryDefinitions, revocationRegistryDefinitionIds, revocationStatusLists, nonRevokedIntervalOverrideList, ret);
|
|
225
|
-
this.handleError();
|
|
263
|
+
const errorCode = this.nativeAnoncreds.anoncreds_verify_w3c_presentation(presentation, presentationRequest, schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, revocationRegistryDefinitions !== null && revocationRegistryDefinitions !== void 0 ? revocationRegistryDefinitions : {}, revocationRegistryDefinitionIds !== null && revocationRegistryDefinitionIds !== void 0 ? revocationRegistryDefinitionIds : {}, revocationStatusLists !== null && revocationStatusLists !== void 0 ? revocationStatusLists : {}, nonRevokedIntervalOverrideList, ret);
|
|
264
|
+
this.handleError(errorCode);
|
|
226
265
|
return Boolean(handleReturnPointer(ret));
|
|
227
266
|
}
|
|
228
267
|
credentialToW3c(options) {
|
|
229
268
|
const { objectHandle, issuerId, w3cVersion } = (0, ffi_1.serializeArguments)(options);
|
|
230
269
|
const ret = (0, ffi_1.allocatePointer)();
|
|
231
|
-
this.nativeAnoncreds.anoncreds_credential_to_w3c(objectHandle, issuerId, w3cVersion, ret);
|
|
232
|
-
this.handleError();
|
|
270
|
+
const errorCode = this.nativeAnoncreds.anoncreds_credential_to_w3c(objectHandle, issuerId, w3cVersion, ret);
|
|
271
|
+
this.handleError(errorCode);
|
|
233
272
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
234
273
|
}
|
|
235
274
|
credentialFromW3c(options) {
|
|
236
275
|
const { objectHandle } = (0, ffi_1.serializeArguments)(options);
|
|
237
276
|
const ret = (0, ffi_1.allocatePointer)();
|
|
238
|
-
this.nativeAnoncreds.anoncreds_credential_from_w3c(objectHandle, ret);
|
|
239
|
-
this.handleError();
|
|
277
|
+
const errorCode = this.nativeAnoncreds.anoncreds_credential_from_w3c(objectHandle, ret);
|
|
278
|
+
this.handleError(errorCode);
|
|
240
279
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
241
280
|
}
|
|
242
281
|
w3cCredentialGetIntegrityProofDetails(options) {
|
|
243
282
|
const { objectHandle } = (0, ffi_1.serializeArguments)(options);
|
|
244
283
|
const ret = (0, ffi_1.allocatePointer)();
|
|
245
|
-
this.nativeAnoncreds.anoncreds_w3c_credential_get_integrity_proof_details(objectHandle, ret);
|
|
246
|
-
this.handleError();
|
|
284
|
+
const errorCode = this.nativeAnoncreds.anoncreds_w3c_credential_get_integrity_proof_details(objectHandle, ret);
|
|
285
|
+
this.handleError(errorCode);
|
|
247
286
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
248
287
|
}
|
|
249
288
|
w3cCredentialProofGetAttribute(options) {
|
|
250
289
|
const { objectHandle, name } = (0, ffi_1.serializeArguments)(options);
|
|
251
290
|
const ret = (0, ffi_1.allocateStringBuffer)();
|
|
252
|
-
this.nativeAnoncreds.anoncreds_w3c_credential_proof_get_attribute(objectHandle, name, ret);
|
|
253
|
-
this.handleError();
|
|
291
|
+
const errorCode = this.nativeAnoncreds.anoncreds_w3c_credential_proof_get_attribute(objectHandle, name, ret);
|
|
292
|
+
this.handleError(errorCode);
|
|
254
293
|
return handleReturnPointer(ret);
|
|
255
294
|
}
|
|
256
295
|
w3cCredentialFromJson(options) {
|
|
@@ -263,21 +302,14 @@ class NodeJSAnoncreds {
|
|
|
263
302
|
return this.nativeAnoncreds.anoncreds_version();
|
|
264
303
|
}
|
|
265
304
|
setDefaultLogger() {
|
|
266
|
-
this.nativeAnoncreds.anoncreds_set_default_logger();
|
|
267
|
-
this.handleError();
|
|
268
|
-
}
|
|
269
|
-
// This should be called when a function returns a non-zero code
|
|
270
|
-
getCurrentError() {
|
|
271
|
-
const ret = (0, ffi_1.allocateStringBuffer)();
|
|
272
|
-
this.nativeAnoncreds.anoncreds_get_current_error(ret);
|
|
273
|
-
this.handleError();
|
|
274
|
-
return handleReturnPointer(ret);
|
|
305
|
+
const errorCode = this.nativeAnoncreds.anoncreds_set_default_logger();
|
|
306
|
+
this.handleError(errorCode);
|
|
275
307
|
}
|
|
276
|
-
objectFromJson(
|
|
308
|
+
objectFromJson(cb, options) {
|
|
277
309
|
const ret = (0, ffi_1.allocatePointer)();
|
|
278
|
-
const byteBuffer =
|
|
279
|
-
|
|
280
|
-
|
|
310
|
+
const byteBuffer = new node_util_1.TextEncoder().encode(options.json);
|
|
311
|
+
const errorCode = cb({ data: byteBuffer, len: byteBuffer.length }, ret);
|
|
312
|
+
this.handleError(errorCode);
|
|
281
313
|
return new anoncreds_shared_1.ObjectHandle(handleReturnPointer(ret));
|
|
282
314
|
}
|
|
283
315
|
presentationRequestFromJson(options) {
|
|
@@ -326,78 +358,76 @@ class NodeJSAnoncreds {
|
|
|
326
358
|
return this.objectFromJson(this.nativeAnoncreds.anoncreds_key_correctness_proof_from_json, options);
|
|
327
359
|
}
|
|
328
360
|
getJson(options) {
|
|
329
|
-
const ret = (0, ffi_1.allocateByteBuffer)();
|
|
330
361
|
const { objectHandle } = (0, ffi_1.serializeArguments)(options);
|
|
331
|
-
|
|
332
|
-
this.
|
|
362
|
+
const ret = (0, ffi_1.allocateByteBuffer)();
|
|
363
|
+
const errorCode = this.nativeAnoncreds.anoncreds_object_get_json(objectHandle, ret);
|
|
364
|
+
this.handleError(errorCode);
|
|
333
365
|
const returnValue = handleReturnPointer(ret);
|
|
334
|
-
const jsonAsArray =
|
|
335
|
-
const output = new
|
|
336
|
-
this.nativeAnoncreds.anoncreds_buffer_free(returnValue
|
|
366
|
+
const jsonAsArray = (0, ffi_1.byteBufferToUint8Array)(returnValue);
|
|
367
|
+
const output = new node_util_1.TextDecoder().decode(jsonAsArray);
|
|
368
|
+
this.nativeAnoncreds.anoncreds_buffer_free(returnValue);
|
|
337
369
|
return output;
|
|
338
370
|
}
|
|
339
371
|
getTypeName(options) {
|
|
340
372
|
const { objectHandle } = (0, ffi_1.serializeArguments)(options);
|
|
341
373
|
const ret = (0, ffi_1.allocateStringBuffer)();
|
|
342
|
-
this.nativeAnoncreds.anoncreds_object_get_type_name(objectHandle, ret);
|
|
343
|
-
this.handleError();
|
|
374
|
+
const errorCode = this.nativeAnoncreds.anoncreds_object_get_type_name(objectHandle, ret);
|
|
375
|
+
this.handleError(errorCode);
|
|
344
376
|
return handleReturnPointer(ret);
|
|
345
377
|
}
|
|
346
378
|
objectFree(options) {
|
|
347
379
|
this.nativeAnoncreds.anoncreds_object_free(options.objectHandle.handle);
|
|
348
|
-
this.handleError();
|
|
349
380
|
}
|
|
350
381
|
convertCredentialList(credentials) {
|
|
351
382
|
const credentialEntries = credentials.map((value) => {
|
|
352
383
|
var _a, _b, _c;
|
|
353
|
-
return (
|
|
384
|
+
return ({
|
|
354
385
|
credential: value.credential.handle,
|
|
355
386
|
timestamp: (_a = value.timestamp) !== null && _a !== void 0 ? _a : -1,
|
|
356
387
|
rev_state: (_c = (_b = value.revocationState) === null || _b === void 0 ? void 0 : _b.handle) !== null && _c !== void 0 ? _c : 0,
|
|
357
388
|
});
|
|
358
389
|
});
|
|
359
|
-
return
|
|
390
|
+
return {
|
|
360
391
|
count: credentialEntries.length,
|
|
361
392
|
data: credentialEntries,
|
|
362
|
-
}
|
|
393
|
+
};
|
|
363
394
|
}
|
|
364
395
|
convertCredentialProves(credentialsProve) {
|
|
365
396
|
const credentialProves = credentialsProve.map((value) => {
|
|
366
397
|
const { entryIndex: entry_idx, isPredicate: is_predicate, reveal, referent } = (0, ffi_1.serializeArguments)(value);
|
|
367
|
-
return
|
|
398
|
+
return { entry_idx, referent, is_predicate, reveal };
|
|
368
399
|
});
|
|
369
|
-
return
|
|
400
|
+
return {
|
|
370
401
|
count: credentialProves.length,
|
|
371
402
|
data: credentialProves,
|
|
372
|
-
}
|
|
403
|
+
};
|
|
373
404
|
}
|
|
374
405
|
convertSchemas(schemas) {
|
|
375
406
|
const schemaKeys = Object.keys(schemas);
|
|
376
|
-
const schemaIds =
|
|
407
|
+
const schemaIds = {
|
|
377
408
|
count: schemaKeys.length,
|
|
378
409
|
data: schemaKeys,
|
|
379
|
-
}
|
|
410
|
+
};
|
|
380
411
|
const schemaValues = Object.values(schemas);
|
|
381
|
-
const schemasList = (0, ffi_1.ObjectHandleListStruct)({
|
|
382
|
-
count: schemaValues.length,
|
|
383
|
-
data: (0, ffi_1.ObjectHandleArray)(schemaValues.map((o) => o.handle)),
|
|
384
|
-
});
|
|
385
412
|
return {
|
|
386
413
|
schemaIds,
|
|
387
|
-
schemas:
|
|
414
|
+
schemas: {
|
|
415
|
+
count: schemaValues.length,
|
|
416
|
+
data: schemaValues.map((o) => o.handle),
|
|
417
|
+
},
|
|
388
418
|
};
|
|
389
419
|
}
|
|
390
420
|
convertCredDefs(credentialDefinitions) {
|
|
391
421
|
const credentialDefinitionKeys = Object.keys(credentialDefinitions);
|
|
392
|
-
const credentialDefinitionIds =
|
|
422
|
+
const credentialDefinitionIds = {
|
|
393
423
|
count: credentialDefinitionKeys.length,
|
|
394
424
|
data: credentialDefinitionKeys,
|
|
395
|
-
}
|
|
425
|
+
};
|
|
396
426
|
const credentialDefinitionValues = Object.values(credentialDefinitions);
|
|
397
|
-
const credentialDefinitionsList =
|
|
427
|
+
const credentialDefinitionsList = {
|
|
398
428
|
count: credentialDefinitionValues.length,
|
|
399
|
-
data:
|
|
400
|
-
}
|
|
429
|
+
data: credentialDefinitionValues.map((o) => o.handle),
|
|
430
|
+
};
|
|
401
431
|
return {
|
|
402
432
|
credentialDefinitionIds,
|
|
403
433
|
credentialDefinitions: credentialDefinitionsList,
|
|
@@ -407,46 +437,46 @@ class NodeJSAnoncreds {
|
|
|
407
437
|
var _a;
|
|
408
438
|
const nativeNonRevokedIntervalOverrides = nonRevokedIntervalOverrides === null || nonRevokedIntervalOverrides === void 0 ? void 0 : nonRevokedIntervalOverrides.map((value) => {
|
|
409
439
|
const { requestedFromTimestamp, revocationRegistryDefinitionId, overrideRevocationStatusListTimestamp } = (0, ffi_1.serializeArguments)(value);
|
|
410
|
-
return
|
|
440
|
+
return {
|
|
411
441
|
rev_reg_def_id: revocationRegistryDefinitionId,
|
|
412
442
|
requested_from_ts: requestedFromTimestamp,
|
|
413
443
|
override_rev_status_list_ts: overrideRevocationStatusListTimestamp,
|
|
414
|
-
}
|
|
444
|
+
};
|
|
415
445
|
});
|
|
416
|
-
return
|
|
446
|
+
return {
|
|
417
447
|
count: (_a = nonRevokedIntervalOverrides === null || nonRevokedIntervalOverrides === void 0 ? void 0 : nonRevokedIntervalOverrides.length) !== null && _a !== void 0 ? _a : 0,
|
|
418
448
|
data: nativeNonRevokedIntervalOverrides,
|
|
419
|
-
}
|
|
449
|
+
};
|
|
420
450
|
}
|
|
421
451
|
convertAttributeNames(attributeRawValues) {
|
|
422
|
-
return
|
|
452
|
+
return {
|
|
423
453
|
count: Object.keys(attributeRawValues).length,
|
|
424
454
|
data: Object.keys(attributeRawValues),
|
|
425
|
-
}
|
|
455
|
+
};
|
|
426
456
|
}
|
|
427
457
|
convertAttributeRawValues(attributeRawValues) {
|
|
428
|
-
return
|
|
458
|
+
return {
|
|
429
459
|
count: Object.keys(attributeRawValues).length,
|
|
430
460
|
data: Object.values(attributeRawValues),
|
|
431
|
-
}
|
|
461
|
+
};
|
|
432
462
|
}
|
|
433
463
|
convertAttributeEncodedValues(attributeEncodedValues) {
|
|
434
464
|
return attributeEncodedValues
|
|
435
|
-
?
|
|
465
|
+
? {
|
|
436
466
|
count: Object.keys(attributeEncodedValues).length,
|
|
437
467
|
data: Object.values(attributeEncodedValues),
|
|
438
|
-
}
|
|
468
|
+
}
|
|
439
469
|
: undefined;
|
|
440
470
|
}
|
|
441
471
|
convertRevocationConfiguration(revocationConfiguration) {
|
|
442
472
|
if (revocationConfiguration) {
|
|
443
473
|
const { revocationRegistryDefinition, revocationRegistryDefinitionPrivate, revocationStatusList, registryIndex } = (0, ffi_1.serializeArguments)(revocationConfiguration);
|
|
444
|
-
return
|
|
474
|
+
return {
|
|
445
475
|
reg_def: revocationRegistryDefinition,
|
|
446
476
|
reg_def_private: revocationRegistryDefinitionPrivate,
|
|
447
477
|
status_list: revocationStatusList,
|
|
448
478
|
reg_idx: registryIndex,
|
|
449
|
-
}
|
|
479
|
+
};
|
|
450
480
|
}
|
|
451
481
|
}
|
|
452
482
|
}
|