@verii/verii-issuing 1.1.0-pre.1761078749 → 1.1.0-pre.1761633504

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verii/verii-issuing",
3
- "version": "1.1.0-pre.1761078749",
3
+ "version": "1.1.0-pre.1761633504",
4
4
  "description": "Verii Issuing Package",
5
5
  "repository": "https://github.com/LFDT-Verii/core",
6
6
  "main": "src/index.js",
@@ -18,23 +18,23 @@
18
18
  "author": "Andres Olave",
19
19
  "license": "Apache-2.0",
20
20
  "dependencies": {
21
- "@verii/blockchain-functions": "1.1.0-pre.1761078749",
22
- "@verii/common-functions": "1.1.0-pre.1761078749",
23
- "@verii/crypto": "1.1.0-pre.1761078749",
24
- "@verii/did-doc": "1.1.0-pre.1761078749",
25
- "@verii/jwt": "1.1.0-pre.1761078749",
26
- "@verii/metadata-registration": "1.1.0-pre.1761078749",
27
- "@verii/vc-checks": "1.1.0-pre.1761078749",
21
+ "@verii/blockchain-functions": "1.1.0-pre.1761633504",
22
+ "@verii/common-functions": "1.1.0-pre.1761633504",
23
+ "@verii/crypto": "1.1.0-pre.1761633504",
24
+ "@verii/did-doc": "1.1.0-pre.1761633504",
25
+ "@verii/jwt": "1.1.0-pre.1761633504",
26
+ "@verii/metadata-registration": "1.1.0-pre.1761633504",
27
+ "@verii/vc-checks": "1.1.0-pre.1761633504",
28
28
  "canonicalize": "2.1.0",
29
29
  "eth-url-parser": "1.0.4",
30
30
  "fast-shuffle": "6.1.1",
31
31
  "lodash": "^4.17.21"
32
32
  },
33
33
  "devDependencies": {
34
- "@verii/contract-permissions": "1.1.0-pre.1761078749",
35
- "@verii/http-client": "1.1.0-pre.1761078749",
36
- "@verii/test-regexes": "1.1.0-pre.1761078749",
37
- "@verii/tests-helpers": "1.1.0-pre.1761078749",
34
+ "@verii/contract-permissions": "1.1.0-pre.1761633504",
35
+ "@verii/http-client": "1.1.0-pre.1761633504",
36
+ "@verii/test-regexes": "1.1.0-pre.1761633504",
37
+ "@verii/tests-helpers": "1.1.0-pre.1761633504",
38
38
  "eslint": "8.57.1",
39
39
  "eslint-config-airbnb-base": "14.2.1",
40
40
  "eslint-config-prettier": "8.10.2",
@@ -56,5 +56,5 @@
56
56
  "lib"
57
57
  ]
58
58
  },
59
- "gitHead": "271e13259106a059ac269b208323fd99046f263e"
59
+ "gitHead": "2d03f7696df04682866781b65f0ce2a6bb939c34"
60
60
  }
@@ -34,7 +34,7 @@ const { VelocityRevocationListType } = require('@verii/vc-checks');
34
34
  * @param {Context} context context
35
35
  * @returns {JsonLdCredential} a json-ld formatted unsigned credential
36
36
  */
37
- const prepareJsonLdCredential = (
37
+ const buildJsonLdCredential = (
38
38
  issuer,
39
39
  credentialSubjectId,
40
40
  offer,
@@ -215,5 +215,5 @@ const buildCredentialTypeJsonLdContext = (credentialTypeMetadata) =>
215
215
  : [];
216
216
 
217
217
  module.exports = {
218
- prepareJsonLdCredential,
218
+ buildJsonLdCredential,
219
219
  };
@@ -26,9 +26,10 @@ const { jsonLdToUnsignedVcJwtContent, jwtSign } = require('@verii/jwt');
26
26
  const { extractCredentialType } = require('@verii/vc-checks');
27
27
  const { hashOffer } = require('./hash-offer');
28
28
  const { buildRevocationUrl } = require('../adapters/build-revocation-url');
29
- const { prepareJsonLdCredential } = require('./prepare-jsonld-credential');
29
+ const { buildJsonLdCredential } = require('./build-jsonld-credential');
30
30
 
31
- /** @import { Issuer, AllocationListEntry, CredentialOffer, CredentialMetadata, CredentialTypeMetadata, Context } from "../types/types" */
31
+ // eslint-disable-next-line max-len
32
+ /** @import { Issuer, AllocationListEntry, CredentialOffer, CredentialMetadata, CredentialTypeMetadata, Context, JsonLdCredential } from "../types/types" */
32
33
 
33
34
  /**
34
35
  * Builds the VCs
@@ -39,9 +40,9 @@ const { prepareJsonLdCredential } = require('./prepare-jsonld-credential');
39
40
  * @param {AllocationListEntry[]} revocationListEntries revocation list entries
40
41
  * @param {{[Name: string]: CredentialTypeMetadata}} credentialTypesMap the credential types
41
42
  * @param {Context} context the context
42
- * @returns {Promise<{metadata: CredentialMetadata, vcJwt: string}[]>} the vc and its metadata
43
+ * @returns {Promise<{vcJwt: string, jsonLdCredential: JsonLdCredential, metadata: CredentialMetadata}[]>} the vc and its metadata
43
44
  */
44
- const buildVerifiableCredentials = async (
45
+ const prepareJwtVcs = async (
45
46
  offers,
46
47
  credentialSubjectId,
47
48
  issuer,
@@ -78,7 +79,7 @@ const buildVerifiableCredentials = async (
78
79
  issuer,
79
80
  context
80
81
  );
81
- const jsonLdCredential = prepareJsonLdCredential(
82
+ const jsonLdCredential = buildJsonLdCredential(
82
83
  issuer,
83
84
  credentialSubjectId,
84
85
  offer,
@@ -113,4 +114,4 @@ const buildVelocityCredentialMetadataDID = (entry, issuer, contentHash) =>
113
114
  entry.index
114
115
  }:${contentHash}`;
115
116
 
116
- module.exports = { buildVerifiableCredentials };
117
+ module.exports = { prepareJwtVcs };
@@ -14,15 +14,13 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- const { filter, flow, map } = require('lodash/fp');
17
+ const { map } = require('lodash/fp');
18
18
  const { allocateListEntries } = require('./allocate-list-entries');
19
19
  const {
20
20
  initCredentialMetadataContract,
21
21
  } = require('./adapters/init-credential-metadata-contract');
22
22
  const { createRevocationList } = require('./adapters/create-revocation-list');
23
- const {
24
- buildVerifiableCredentials,
25
- } = require('./domain/build-verifiable-credentials');
23
+ const { prepareJwtVcs } = require('./domain/prepare-jwt-vcs');
26
24
 
27
25
  const REVOCATION_LIST_SIZE = 10240;
28
26
  const METADATA_LIST_SIZE = 10000;
@@ -30,31 +28,51 @@ const METADATA_LIST_SIZE = 10000;
30
28
  /** @import { Issuer, AllocationListEntry, CredentialOffer, CredentialMetadata, CredentialTypeMetadata, Context } from "../types/types" */
31
29
 
32
30
  /**
33
- * Prepares verifiable credentials from local offers without anchoring them to the blockchain.
34
- * Current assumption is that offers contain all required fields including @context, type, contentHash
31
+ * Prepares, signs and anchors a verifiable credential from a credential offer.
35
32
  * @param {CredentialOffer[]} offers array of offers
36
33
  * @param {string} credentialSubjectId optional field if credential subject needs to be bound into the offer
37
34
  * @param {{[Name: string]: CredentialTypeMetadata}} credentialTypesMap the credential types metadata
38
35
  * @param {Issuer} issuer the issuer
39
36
  * @param {Context} context the context
40
- * @returns {Promise<{vcs: object[], revocationListEntries: object[]}>} Returns prepared credentials and revocation list entries
37
+ * @returns {Promise<string[]>} Returns signed credentials for each offer in vc-jwt format
41
38
  */
42
- const prepareVeriiVerifiableCredentials = async (
39
+ const issueVeriiCredentials = async (
43
40
  offers,
44
41
  credentialSubjectId,
45
42
  credentialTypesMap,
46
43
  issuer,
47
44
  context
48
45
  ) => {
49
- // pre-allocate list entries using internal tables/collections
50
- const revocationListEntries = await allocateListEntries(
51
- offers.length,
46
+ const vcs = await signVeriiCredentials(
47
+ offers,
48
+ credentialSubjectId,
49
+ credentialTypesMap,
52
50
  issuer,
53
- 'revocationListAllocations',
54
- REVOCATION_LIST_SIZE,
55
51
  context
56
52
  );
57
53
 
54
+ await anchorVeriiCredentials(map('metadata', vcs), issuer, context);
55
+
56
+ return map('vcJwt', vcs);
57
+ };
58
+
59
+ /**
60
+ * Prepares and signs verifiable credentials from local offers without anchoring them to the blockchain.
61
+ * Assumption is that credential offers contain all required fields including @context, type, contentHash
62
+ * @param {CredentialOffer[]} offers array of offers
63
+ * @param {string} credentialSubjectId optional field if credential subject needs to be bound into the offer
64
+ * @param {{[Name: string]: CredentialTypeMetadata}} credentialTypesMap the credential types metadata
65
+ * @param {Issuer} issuer the issuer
66
+ * @param {Context} context the context
67
+ * @returns {Promise<{vcJwt: string, metadata: CredentialMetadata}[]>} Returns array of signed vcs (in jwt format) and their metadata
68
+ */
69
+ const signVeriiCredentials = async (
70
+ offers,
71
+ credentialSubjectId,
72
+ credentialTypesMap,
73
+ issuer,
74
+ context
75
+ ) => {
58
76
  const metadataEntries = await allocateListEntries(
59
77
  offers.length,
60
78
  issuer,
@@ -62,9 +80,29 @@ const prepareVeriiVerifiableCredentials = async (
62
80
  METADATA_LIST_SIZE,
63
81
  context
64
82
  );
83
+ const newMetadataListEntry = getNewListEntry(metadataEntries);
84
+ if (newMetadataListEntry != null) {
85
+ const { createList } = await initCredentialMetadataContract(
86
+ issuer,
87
+ context
88
+ );
89
+ await createList(newMetadataListEntry.listId);
90
+ }
91
+
92
+ // pre-allocate list entries using internal tables/collections
93
+ const revocationListEntries = await allocateListEntries(
94
+ offers.length,
95
+ issuer,
96
+ 'revocationListAllocations',
97
+ REVOCATION_LIST_SIZE,
98
+ context
99
+ );
100
+ const newRevocationListEntry = getNewListEntry(revocationListEntries);
101
+ if (newRevocationListEntry != null) {
102
+ await createRevocationList(newRevocationListEntry.listId, issuer, context);
103
+ }
65
104
 
66
- // build credential and metadata
67
- const vcs = await buildVerifiableCredentials(
105
+ return prepareJwtVcs(
68
106
  offers,
69
107
  credentialSubjectId,
70
108
  issuer,
@@ -73,85 +111,30 @@ const prepareVeriiVerifiableCredentials = async (
73
111
  credentialTypesMap,
74
112
  context
75
113
  );
76
-
77
- return { vcs, revocationListEntries };
78
114
  };
79
115
 
80
116
  /**
81
- * Anchors prepared verifiable credentials to the blockchain.
82
- * @param {object[]} vcs array of verifiable credentials
83
- * @param {object[]} revocationListEntries array of revocation list entries
117
+ * Anchors prepared verifiable credentials to the blockchain using their credential metadata.
118
+ * @param {CredentialMetadata[]} credentialMetadatas array of verifiable credential metadata
84
119
  * @param {Issuer} issuer the issuer
85
120
  * @param {Context} context the context
86
- * @returns {Promise<string[]>} Returns signed credentials for each offer in vc-jwt format
87
121
  */
88
- const anchorVeriiVerifiableCredentials = async (
89
- vcs,
90
- revocationListEntries,
91
- issuer,
92
- context
93
- ) => {
94
- // create any necessary revocation lists on dlt
95
- await Promise.all(
96
- flow(
97
- filter({ isNewList: true }),
98
- map((entry) => createRevocationList(entry.listId, issuer, context))
99
- )(revocationListEntries)
100
- );
101
-
102
- const { addEntry, createList } = await initCredentialMetadataContract(
103
- issuer,
104
- context
105
- );
106
-
107
- // create any necessary metadata lists on dlt
108
- await Promise.all(
109
- flow(
110
- filter({ metadata: { isNewList: true } }),
111
- map(({ metadata: { listId } }) => createList(listId, issuer, context))
112
- )(vcs)
113
- );
122
+ const anchorVeriiCredentials = async (credentialMetadatas, issuer, context) => {
123
+ const { addEntry } = await initCredentialMetadataContract(issuer, context);
114
124
 
115
125
  // create credential metadata entries on dlt
116
- await Promise.all(map(({ metadata }) => addEntry(metadata), vcs));
117
-
118
- return map('vcJwt', vcs);
126
+ await Promise.all(map((metadata) => addEntry(metadata), credentialMetadatas));
119
127
  };
120
128
 
121
129
  /**
122
- * Creates verifiable credential from a local offer. Current assumption is that offers contain all required fields
123
- * including @context, type, contentHash
124
- * @param {CredentialOffer[]} offers array of offers
125
- * @param {string} credentialSubjectId optional field if credential subject needs to be bound into the offer
126
- * @param {{[Name: string]: CredentialTypeMetadata}} credentialTypesMap the credential types metadata
127
- * @param {Issuer} issuer the issuer
128
- * @param {Context} context the context
129
- * @returns {Promise<string[]>} Returns signed credentials for each offer in vc-jwt format
130
+ * Gets the new list entry. Since the number of entries per list is 10k then only one will ever be returned
131
+ * @param {AllocationListEntry[]} entries the entries
132
+ * @returns {AllocationListEntry | undefined} returns the new list entry if it exists, otherwise undefined
130
133
  */
131
- const issueVeriiCredentials = async (
132
- offers,
133
- credentialSubjectId,
134
- credentialTypesMap,
135
- issuer,
136
- context
137
- ) => {
138
- const { vcs, revocationListEntries } =
139
- await prepareVeriiVerifiableCredentials(
140
- offers,
141
- credentialSubjectId,
142
- credentialTypesMap,
143
- issuer,
144
- context
145
- );
146
- return anchorVeriiVerifiableCredentials(
147
- vcs,
148
- revocationListEntries,
149
- issuer,
150
- context
151
- );
152
- };
134
+ const getNewListEntry = (entries) => entries?.find((entry) => entry.isNewList);
135
+
153
136
  module.exports = {
154
- anchorVeriiVerifiableCredentials,
137
+ anchorVeriiCredentials,
155
138
  issueVeriiCredentials,
156
- prepareVeriiVerifiableCredentials,
139
+ signVeriiCredentials,
157
140
  };