Skip to content

Commit 111d871

Browse files
authored
Merge pull request #195 from alastria/develop
Develop
2 parents 573be7b + 9377bc0 commit 111d871

14 files changed

+302
-6191
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- name: Setup Node
1111
uses: actions/setup-node@v1
1212
with:
13-
node-version: '14.x'
13+
node-version: '18.x'
1414
- name: Install dependencies
1515
run: npm install
1616
env:

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ build/Release
3636
# Dependency directories
3737
node_modules/
3838
alastriaID-truffle-contracts
39+
alastriaID-hardhat-contracts
3940
jspm_packages/
4041
package-lock.json
42+
src/config.ts
4143

4244
# Typescript v1 declaration files
4345
typings/

package-lock.json

-5,713
This file was deleted.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "alastria-identity-lib",
3-
"version": "2.0.0",
3+
"version": "2.2.0",
44
"description": "A library to interact with alastria-identity smart contracts",
55
"main": "src/index.js",
66
"bin": {
@@ -9,8 +9,8 @@
99
"types": "dist/index.d.ts",
1010
"scripts": {
1111
"postinstall": "run-s build",
12-
"compile": "git clone --branch v2.0.0 https://github.com/alastria/alastriaID-truffle-contracts.git && npm install --prefix alastriaID-truffle-contracts && npm run compile --prefix alastriaID-truffle-contracts && node src/configFile.js && tsc",
13-
"clean": "rimraf dist alastriaID-truffle-contracts",
12+
"compile": "git clone --branch develop https://github.com/alastria/alastriaID-hardhat-contracts.git && npm install --prefix alastriaID-hardhat-contracts && npm run compile --prefix alastriaID-hardhat-contracts && node src/configFile.js && tsc",
13+
"clean": "rimraf dist alastriaID-hardhat-contracts",
1414
"build": "run-s clean compile",
1515
"test": "mocha -r ts-node/register test/**/*.ts",
1616
"lint": "eslint 'src/**/*.{js,ts,tsx}'",

src/config.ts

-1
This file was deleted.

src/configFile.js

+44-16
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,58 @@
22
const fs = require('fs')
33
const path = require('path')
44

5-
const contractsABIPath = '../alastriaID-truffle-contracts/build/contracts'
5+
const contractsABIPath = '../alastriaID-hardhat-contracts/artifacts/contracts'
66
const _contractsAbi = {}
7+
const abi = {}
78

89
// Process the abi dir for getting an object with all the abi functions
9-
fs.readdirSync(path.join(__dirname, `${contractsABIPath}`)).forEach((file) => {
10-
const abi = {}
11-
const abiFile = JSON.parse(
12-
fs.readFileSync(path.join(__dirname, `${contractsABIPath}`, file), 'utf8')
13-
)
14-
abiFile.abi.forEach((element) => {
15-
if (element.type === 'constructor') {
16-
abi.constructor = element
17-
} else {
18-
if (element.name) {
19-
abi[element.name] = element
10+
fs.readdirSync(path.join(__dirname, `${contractsABIPath}`)).forEach((folder) => {
11+
fs.readdirSync(path.join(__dirname, `${contractsABIPath}/${folder}`)).forEach((folderSol) => {
12+
fs.readdirSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}`)).forEach((file) => {
13+
if(folderSol === 'upgradeability') {
14+
fs.readdirSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}`)).forEach((folderUpgrade) => {
15+
fs.readdirSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}/${folderUpgrade}`)).forEach((fileUpgrade) => {
16+
if (!fileUpgrade.endsWith('.dbg.json')) {
17+
const abiFile = JSON.parse(
18+
fs.readFileSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}/${folderUpgrade}`, fileUpgrade), 'utf8')
19+
)
20+
abiFile.abi.forEach((element) => {
21+
if (element.type === 'constructor') {
22+
abi.constructor = element
23+
} else {
24+
if (element.name) {
25+
abi[element.name] = element
26+
}
27+
}
28+
})
29+
_contractsAbi[abiFile.contractName] = abi
30+
}
31+
})
32+
})
33+
} else {
34+
if (!file.endsWith('.dbg.json')) {
35+
const abiFile = JSON.parse(
36+
fs.readFileSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}`, file), 'utf8')
37+
)
38+
abiFile.abi.forEach((element) => {
39+
if (element.type === 'constructor') {
40+
abi.constructor = element
41+
} else {
42+
if (element.name) {
43+
abi[element.name] = element
44+
}
45+
}
46+
})
47+
_contractsAbi[abiFile.contractName] = abi
48+
}
2049
}
21-
}
50+
})
2251
})
23-
_contractsAbi[abiFile.contractName] = abi
2452
})
2553

26-
const contractsAddressesPath = '../alastriaID-truffle-contracts'
54+
const contractsAddressesPath = '../alastriaID-hardhat-contracts'
2755
const contractsInfo = JSON.parse(
28-
fs.readFileSync(path.join(__dirname, `${contractsAddressesPath}`, 'addresses.json'), 'utf8')
56+
fs.readFileSync(path.join(__dirname, `${contractsAddressesPath}`, 'addresses-t.json'), 'utf8')
2957
)
3058

3159
const config = {

src/tokenFactory/tokensFactory.ts

+32-10
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ function createAlastriaSession(
6666
context: string[],
6767
iss: string,
6868
kid: string,
69-
type: string[],
7069
alastriaToken: string,
7170
exp: number,
71+
type: string[],
7272
pku?: string,
7373
nbf?: number,
7474
jti?: string
@@ -103,27 +103,35 @@ function createAlastriaSession(
103103
}
104104

105105
/** Creates the AlastriaToken
106+
* @param context aditional urls to "https://alastria.github.io/identity/artifacts/v1"
106107
* @param iss DID representing the AlastriaID of the entity that issued the Alastria Token
107108
* @param gwu Provider gateway url
108-
* @param cbu Callbacku url from the user
109-
* @param ani Alastria Network ID
109+
* @param cbu Callback url from the user
110110
* @param exp expiration time
111111
* @param kid indicates which key was used to secure (digitally sign) the JWT
112+
* @param type aditional types to "AlastriaToken"
113+
* @param mfau callback from a mfau
112114
* @param jwk Users public key
113115
* @param nbf not before
114116
* @param jti Unique token identifier
115117
*/
116118
function createAlastriaToken(
119+
context: string[],
117120
iss: string,
118121
gwu: string,
119122
cbu: string,
120-
ani: string,
121123
exp: number,
122124
kid: string,
125+
type: string[],
126+
mfau?: string,
123127
jwk?: string,
124128
nbf?: number,
125129
jti?: string
126130
) {
131+
const requiredContext: string[] = [
132+
'https://alastria.github.io/identity/artifacts/v1'
133+
]
134+
const requiredTypes: string[] = ['AlastriaToken']
127135
if(jwk){
128136
jwk = AddressUtils.getAddressWithHexPrefix(jwk)
129137
}
@@ -136,11 +144,13 @@ function createAlastriaToken(
136144
jwk
137145
},
138146
payload: {
147+
'@context': requiredContext.concat(context),
139148
iss,
140149
gwu,
141150
cbu,
142151
iat: Math.round(Date.now() / 1000),
143-
ani,
152+
type: requiredTypes.concat(type),
153+
mfau,
144154
nbf,
145155
exp,
146156
jti
@@ -164,13 +174,14 @@ export function createCredential(
164174
iss: string,
165175
context: string[],
166176
credentialSubject: object,
177+
type: string[],
167178
kid?: string,
168179
sub?: string,
169180
exp?: number,
170181
nbf?: number,
171182
jti?: string,
172183
jwk?: string,
173-
type?: string[]
184+
174185
) {
175186
const requiredContext: string[] = [
176187
'https://www.w3.org/2018/credentials/v1',
@@ -224,6 +235,7 @@ export function createCredential(
224235
* @param exp identifies the expiration time on or after which the JWT (presentation) MUST NOT be accepted for processing
225236
* @param nbf identifies the time before which the JWT (presentation) MUST NOT be accepted for processing
226237
* @param jti This is the identification of this specific presentation instance (it is NOT the identifier of the holder or of any other actor)
238+
* @param jtipr this is a field that links this presentation to the originally sent presentation request
227239
*/
228240
function createPresentation(
229241
iss: string,
@@ -237,7 +249,8 @@ function createPresentation(
237249
jwk?: string,
238250
exp?: number,
239251
nbf?: number,
240-
jti?: string
252+
jti?: string,
253+
jtipr?: string,
241254
) {
242255
const requiredContext: string[] = [
243256
'https://www.w3.org/2018/credentials/v1',
@@ -260,6 +273,7 @@ function createPresentation(
260273
},
261274
payload: {
262275
jti,
276+
jtipr,
263277
iss,
264278
aud,
265279
iat: Math.round(Date.now() / 1000),
@@ -290,6 +304,9 @@ function createPresentation(
290304
* @param exp identifies the expiration time on or after which the JWT (Presentation Request) MUST NOT be accepted for processing
291305
* @param nbf identifies the time before which the JWT (presentation) MUST NOT be accepted for processing
292306
* @param jti This is the identification of this specific Presentation Request (it is NOT the identifier of the holder or of any other actor)
307+
* @param p_exp it contains the suggested expiration date (exp field) to be used by the corresponding presentation in response to this Presentation Request.
308+
* @param p_exp_delta identifies the time before which the JWT (presentation) MUST NOT be accepted for processing
309+
* @param procDesc This is a value in seconds, so that the wallet can later obtain this value and calculate based on the current date what will be the date of issuance of the presentation.
293310
*/
294311
function createPresentationRequest(
295312
iss: string,
@@ -303,7 +320,10 @@ function createPresentationRequest(
303320
jwk?: string,
304321
exp?: number,
305322
nbf?: number,
306-
jti?: string
323+
p_exp?: number,
324+
p_exp_delta?: number,
325+
jti?: string,
326+
procDesc?: string
307327
) {
308328
const requiredContext: string[] = [
309329
'https://www.w3.org/2018/credentials/v1',
@@ -331,11 +351,14 @@ function createPresentationRequest(
331351
exp,
332352
nbf,
333353
cbu,
354+
p_exp,
355+
p_exp_delta,
334356
pr: {
335357
'@context': requiredContext.concat(context),
336358
type: requiredTypes.concat(type),
337359
procHash,
338360
procUrl,
361+
procDesc,
339362
data
340363
}
341364
}
@@ -370,7 +393,6 @@ function createAIC(
370393
kid?: string,
371394
jwk?: string,
372395
jti?: string,
373-
iat?: number,
374396
exp?: number,
375397
nbf?: number
376398
) {
@@ -396,7 +418,7 @@ function createAIC(
396418
alastriaToken,
397419
publicKey,
398420
jti: jti,
399-
iat: iat,
421+
iat: Math.round(Date.now() / 1000),
400422
exp: exp,
401423
nbf: nbf
402424
}

src/txFactory/credentialRegistryTransactionFactory.ts

-18
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,6 @@ export function getSubjectCredentialStatus(
7878
return transaction
7979
}
8080

81-
/**
82-
* function getSubjectCredentialList(web3, subject)
83-
* Dev: get invoke getSubjectCredentialList transaction object
84-
* @param web3 ethereum connection
85-
* @param didSubject subject to recover credential list
86-
*/
87-
export function getSubjectCredentialList(web3, didSubject) {
88-
const subjectAddr = AIdUtils.getProxyAddress(didSubject)
89-
const transaction = Object.assign({}, config.basicTransaction)
90-
transaction.data = web3.eth.abi.encodeFunctionCall(
91-
config.contractsAbi.AlastriaCredentialRegistry.getSubjectCredentialList,
92-
[subjectAddr]
93-
)
94-
transaction.to = config.alastriaCredentialRegistry
95-
transaction.gasLimit = 600000
96-
return transaction
97-
}
98-
9981
/**
10082
* function updateCredentialStatus(web3, issuerCredentialHash, status)
10183
* @param web3

src/txFactory/identityManagerTransactionFactory.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function prepareAlastriaID(web3, signAddress) {
3838
}
3939

4040
/**
41-
* function createAlastriaIdentity(bytes publicKeyData) public validAddress(msg.sender) isOnTimeToLiveAndIsFromCaller(msg.sender)
41+
* THIS METHOD WILL BE DEPREATED
4242
* @param web3
4343
* @param publicKey publicKey is a String
4444
*/
@@ -57,6 +57,26 @@ export function createAlastriaIdentity(web3, publicKey) {
5757
return transaction
5858
}
5959

60+
/**
61+
62+
* @param web3
63+
* @param publicKeyHash
64+
*/
65+
export function createAlastriaIdentityHash(web3, publicKeyHash) {
66+
const transaction = Object.assign({}, config.basicTransaction)
67+
transaction.gasLimit = 600000
68+
const publicKeyCallData = web3.eth.abi.encodeFunctionCall(
69+
config.contractsAbi.AlastriaPublicKeyRegistry.addPublicKey,
70+
[publicKeyHash]
71+
)
72+
transaction.data = web3.eth.abi.encodeFunctionCall(
73+
config.contractsAbi.AlastriaIdentityManager.createAlastriaIdentity,
74+
[publicKeyCallData]
75+
)
76+
transaction.to = config.alastriaIdentityManager
77+
return transaction
78+
}
79+
6080
/**
6181
* AlastriaIdentityIssuer.sol
6282
* function addIdentityIssuer(address _identityIssuer, Eidas.EidasLevel _level) public alLeastLow(_level) notIdentityIssuer(_identityIssuer)

src/txFactory/presentationRegistryTransactionFactory.ts

-17
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,6 @@ export function getSubjectPresentationStatus(
6060
return transaction
6161
}
6262

63-
/**
64-
* function getSubjectPresentationList(address subject) public view returns(uint, bytes32[])
65-
* @param web3
66-
* @param didSubject
67-
*/
68-
export function getSubjectPresentationList(web3, didSubject) {
69-
const subjectAddr = AIdUtils.getProxyAddress(didSubject)
70-
const transaction = Object.assign({}, config.basicTransaction)
71-
transaction.data = web3.eth.abi.encodeFunctionCall(
72-
config.contractsAbi.AlastriaPresentationRegistry.getSubjectPresentationList,
73-
[subjectAddr]
74-
)
75-
transaction.to = config.alastriaPresentationRegistry
76-
transaction.gasLimit = 600000
77-
return transaction
78-
}
79-
8063
/**
8164
* Receiver functions
8265
* function updateReceiverPresentation(bytes32 receiverPresentationHash, Status status) public validStatus(status)

0 commit comments

Comments
 (0)