@verii/verii-issuing 1.1.0-pre.1765351552 → 1.1.0-pre.1765354771

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.1765351552",
3
+ "version": "1.1.0-pre.1765354771",
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.1765351552",
22
- "@verii/common-functions": "1.1.0-pre.1765351552",
23
- "@verii/crypto": "1.1.0-pre.1765351552",
24
- "@verii/did-doc": "1.1.0-pre.1765351552",
25
- "@verii/jwt": "1.1.0-pre.1765351552",
26
- "@verii/metadata-registration": "1.1.0-pre.1765351552",
27
- "@verii/vc-checks": "1.1.0-pre.1765351552",
21
+ "@verii/blockchain-functions": "1.1.0-pre.1765354771",
22
+ "@verii/common-functions": "1.1.0-pre.1765354771",
23
+ "@verii/crypto": "1.1.0-pre.1765354771",
24
+ "@verii/did-doc": "1.1.0-pre.1765354771",
25
+ "@verii/jwt": "1.1.0-pre.1765354771",
26
+ "@verii/metadata-registration": "1.1.0-pre.1765354771",
27
+ "@verii/vc-checks": "1.1.0-pre.1765354771",
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.1765351552",
35
- "@verii/http-client": "1.1.0-pre.1765351552",
36
- "@verii/test-regexes": "1.1.0-pre.1765351552",
37
- "@verii/tests-helpers": "1.1.0-pre.1765351552",
34
+ "@verii/contract-permissions": "1.1.0-pre.1765354771",
35
+ "@verii/http-client": "1.1.0-pre.1765354771",
36
+ "@verii/test-regexes": "1.1.0-pre.1765354771",
37
+ "@verii/tests-helpers": "1.1.0-pre.1765354771",
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": "6a7ce7a831716e1159ac237d5a5566b2833b1d24"
59
+ "gitHead": "95b0dfb9c8d00b85e3c0ca240ea38048505a8681"
60
60
  }
@@ -15,10 +15,7 @@
15
15
  *
16
16
  */
17
17
 
18
- const {
19
- initMetadataRegistry,
20
- ALG_TYPE,
21
- } = require('@verii/metadata-registration');
18
+ const { initMetadataRegistry } = require('@verii/metadata-registration');
22
19
  const { jsonLdToUnsignedVcJwtContent, hexFromJwk } = require('@verii/jwt');
23
20
  const { KeyAlgorithms, initCallWithKmsKey } = require('@verii/crypto');
24
21
  const { buildIssuerVcUrl } = require('./build-issuer-vc-url');
@@ -30,7 +27,7 @@ const { buildIssuerVcUrl } = require('./build-issuer-vc-url');
30
27
  * @param {Context} context the context
31
28
  * @returns {Promise<{
32
29
  * addEntry: function(CredentialMetadata): Promise<void>,
33
- * createList: function(number): Promise<boolean>
30
+ * createList: function(number, string): Promise<boolean>
34
31
  * }>} the contract interface to create metadata
35
32
  */
36
33
  const initCredentialMetadataContract = async (issuer, context) => {
@@ -60,14 +57,15 @@ const initCredentialMetadataContract = async (issuer, context) => {
60
57
  metadata,
61
58
  metadata.contentHash,
62
59
  caoDid,
63
- ALG_TYPE.COSEKEY_AES_256
60
+ metadata.algType
64
61
  ),
65
62
  /**
66
63
  * List to create on the dlt
67
64
  * @param {number} listId list id to create
65
+ * @param {string} algType the alg type
68
66
  * @returns {Promise<boolean>} true if a list was created, false if it already existed
69
67
  */
70
- createList: async (listId) => {
68
+ createList: async (listId, algType) => {
71
69
  const accountId = issuer.dltPrimaryAddress;
72
70
  const { payload, header } = jsonLdToUnsignedVcJwtContent(
73
71
  {
@@ -92,7 +90,7 @@ const initCredentialMetadataContract = async (issuer, context) => {
92
90
  listId,
93
91
  issuerVC,
94
92
  caoDid,
95
- ALG_TYPE.COSEKEY_AES_256
93
+ algType
96
94
  );
97
95
  },
98
96
  };
@@ -15,10 +15,13 @@
15
15
  *
16
16
  */
17
17
 
18
- /** @import { Context, Issuer, AllocationListEntry, AllocationListQueries } from "../../types/types" */
18
+ /** @import { Context, CredentialOffer, CredentialTypeMetadata, Issuer, AllocationListEntry, AllocationListQueries } from "../../types/types" */
19
19
 
20
+ const { extractCredentialType } = require('@verii/vc-checks');
21
+ const { ALG_TYPE } = require('@verii/metadata-registration');
20
22
  const { allocateArray } = require('./utils/allocate-array');
21
23
  const { generateListIndex } = require('./utils/generate-list-index');
24
+ const { calcAlgTypeName } = require('./utils/calc-alg-type-name');
22
25
  /**
23
26
  * Allocates list entries
24
27
  * @param {number} total the number of entries required (typically the number of offers)
@@ -28,7 +31,7 @@ const { generateListIndex } = require('./utils/generate-list-index');
28
31
  * @param {Context} context the context
29
32
  * @returns {Promise<AllocationListEntry[]>} the allocated entries
30
33
  */
31
- const allocateListEntries = async (
34
+ const allocateGenericListEntries = async (
32
35
  total,
33
36
  issuer,
34
37
  entityName,
@@ -45,6 +48,41 @@ const allocateListEntries = async (
45
48
  return entries;
46
49
  };
47
50
 
51
+ /**
52
+ * Generates metadata list entries. Different lists for each different algorithm used.
53
+ * @param {CredentialOffer[]} offers array of offers
54
+ * @param {{[Name: string]: CredentialTypeMetadata}} credentialTypesMap the credential types
55
+ * @param {Issuer} issuer the issuer
56
+ * @param {number} listSize the list size
57
+ * @param {Context} context the context
58
+ * @returns {Promise<AllocationListEntry[]>} the allocated entries
59
+ */
60
+ const allocateMetadataListEntries = async (
61
+ offers,
62
+ credentialTypesMap,
63
+ issuer,
64
+ listSize,
65
+ context
66
+ ) => {
67
+ const entries = [];
68
+ for (let i = 0; i < offers.length; i += 1) {
69
+ const algTypeName = calcAlgTypeName(
70
+ credentialTypesMap?.[extractCredentialType(offers[i])]
71
+ );
72
+ entries.push({
73
+ algType: ALG_TYPE[algTypeName],
74
+ // eslint-disable-next-line no-await-in-loop
75
+ ...(await allocateListEntry(
76
+ issuer,
77
+ `${algTypeName}_MetadataListAllocations`,
78
+ listSize,
79
+ context
80
+ )),
81
+ });
82
+ }
83
+ return entries;
84
+ };
85
+
48
86
  /**
49
87
  * Gets the next list entry
50
88
  * @param {Issuer} issuer the issuer
@@ -71,6 +109,7 @@ const allocateListEntry = async (issuer, entityName, listSize, context) => {
71
109
  };
72
110
 
73
111
  module.exports = {
74
- allocateListEntries,
112
+ allocateGenericListEntries,
113
+ allocateMetadataListEntries,
75
114
  allocateListEntry,
76
115
  };
@@ -15,7 +15,10 @@
15
15
  */
16
16
 
17
17
  const { map } = require('lodash/fp');
18
- const { allocateListEntries } = require('./allocate-list-entries');
18
+ const {
19
+ allocateGenericListEntries,
20
+ allocateMetadataListEntries,
21
+ } = require('./allocate-list-entries');
19
22
  const {
20
23
  initCredentialMetadataContract,
21
24
  } = require('./adapters/init-credential-metadata-contract');
@@ -73,31 +76,37 @@ const signVeriiCredentials = async (
73
76
  issuer,
74
77
  context
75
78
  ) => {
76
- const metadataEntries = await allocateListEntries(
77
- offers.length,
79
+ const metadataEntries = await allocateMetadataListEntries(
80
+ offers,
81
+ credentialTypesMap,
78
82
  issuer,
79
- 'metadataListAllocations',
80
83
  METADATA_LIST_SIZE,
81
84
  context
82
85
  );
83
- const newMetadataListEntry = getNewListEntry(metadataEntries);
84
- if (newMetadataListEntry != null) {
86
+ const newMetadataListEntries = getNewListEntries(metadataEntries);
87
+ if (newMetadataListEntries.length > 0) {
85
88
  const { createList } = await initCredentialMetadataContract(
86
89
  issuer,
87
90
  context
88
91
  );
89
- await createList(newMetadataListEntry.listId);
92
+ for (const newMetadataListEntry of newMetadataListEntries) {
93
+ // eslint-disable-next-line no-await-in-loop
94
+ await createList(
95
+ newMetadataListEntry.listId,
96
+ newMetadataListEntry.algType
97
+ );
98
+ }
90
99
  }
91
100
 
92
101
  // pre-allocate list entries using internal tables/collections
93
- const revocationListEntries = await allocateListEntries(
102
+ const revocationListEntries = await allocateGenericListEntries(
94
103
  offers.length,
95
104
  issuer,
96
105
  'revocationListAllocations',
97
106
  REVOCATION_LIST_SIZE,
98
107
  context
99
108
  );
100
- const newRevocationListEntry = getNewListEntry(revocationListEntries);
109
+ const [newRevocationListEntry] = getNewListEntries(revocationListEntries);
101
110
  if (newRevocationListEntry != null) {
102
111
  await createRevocationList(newRevocationListEntry.listId, issuer, context);
103
112
  }
@@ -127,11 +136,12 @@ const anchorVeriiCredentials = async (credentialMetadatas, issuer, context) => {
127
136
  };
128
137
 
129
138
  /**
130
- * Gets the new list entry. Since the number of entries per list is 10k then only one will ever be returned
139
+ * Gets the new list entries. Multiple new list entries can be returned, especially when different algorithm types are used.
131
140
  * @param {AllocationListEntry[]} entries the entries
132
- * @returns {AllocationListEntry | undefined} returns the new list entry if it exists, otherwise undefined
141
+ * @returns {AllocationListEntry[]} returns the new list entries if they exist, otherwise an empty array
133
142
  */
134
- const getNewListEntry = (entries) => entries?.find((entry) => entry.isNewList);
143
+ const getNewListEntries = (entries) =>
144
+ entries.filter((entry) => entry.isNewList);
135
145
 
136
146
  module.exports = {
137
147
  anchorVeriiCredentials,
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright 2025 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+ /** @import { CredentialTypeMetadata } from "../../types/types" */
18
+
19
+ /**
20
+ * Calculates the algTypeName based on credentialTypeMetadata
21
+ * Currently RS signatures use COSEKEY, otherwise HEX encoding
22
+ * @param {CredentialTypeMetadata} credentialTypeMetadata the credential type metadata
23
+ * @returns {string} the alg type name
24
+ */
25
+ const calcAlgTypeName = (credentialTypeMetadata) =>
26
+ credentialTypeMetadata?.defaultSignatureAlgorithm?.startsWith('RS')
27
+ ? 'COSEKEY_AES_256'
28
+ : 'HEX_AES_256';
29
+
30
+ module.exports = { calcAlgTypeName };
package/types/types.d.ts CHANGED
@@ -131,6 +131,7 @@ export interface AllocationListEntry {
131
131
  isNewList: boolean;
132
132
  listId: number;
133
133
  index: number;
134
+ algType?: string;
134
135
  }
135
136
 
136
137
  export interface CredentialOffer extends BaseCredential {