Skip to content

Commit

Permalink
Merge pull request #195 from alastria/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
rober12 authored May 22, 2024
2 parents 573be7b + 9377bc0 commit 111d871
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 6,191 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '14.x'
node-version: '18.x'
- name: Install dependencies
run: npm install
env:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ build/Release
# Dependency directories
node_modules/
alastriaID-truffle-contracts
alastriaID-hardhat-contracts
jspm_packages/
package-lock.json
src/config.ts

# Typescript v1 declaration files
typings/
Expand Down
5,713 changes: 0 additions & 5,713 deletions package-lock.json

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alastria-identity-lib",
"version": "2.0.0",
"version": "2.2.0",
"description": "A library to interact with alastria-identity smart contracts",
"main": "src/index.js",
"bin": {
Expand All @@ -9,8 +9,8 @@
"types": "dist/index.d.ts",
"scripts": {
"postinstall": "run-s build",
"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",
"clean": "rimraf dist alastriaID-truffle-contracts",
"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",
"clean": "rimraf dist alastriaID-hardhat-contracts",
"build": "run-s clean compile",
"test": "mocha -r ts-node/register test/**/*.ts",
"lint": "eslint 'src/**/*.{js,ts,tsx}'",
Expand Down
1 change: 0 additions & 1 deletion src/config.ts

This file was deleted.

60 changes: 44 additions & 16 deletions src/configFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,58 @@
const fs = require('fs')
const path = require('path')

const contractsABIPath = '../alastriaID-truffle-contracts/build/contracts'
const contractsABIPath = '../alastriaID-hardhat-contracts/artifacts/contracts'
const _contractsAbi = {}
const abi = {}

// Process the abi dir for getting an object with all the abi functions
fs.readdirSync(path.join(__dirname, `${contractsABIPath}`)).forEach((file) => {
const abi = {}
const abiFile = JSON.parse(
fs.readFileSync(path.join(__dirname, `${contractsABIPath}`, file), 'utf8')
)
abiFile.abi.forEach((element) => {
if (element.type === 'constructor') {
abi.constructor = element
} else {
if (element.name) {
abi[element.name] = element
fs.readdirSync(path.join(__dirname, `${contractsABIPath}`)).forEach((folder) => {
fs.readdirSync(path.join(__dirname, `${contractsABIPath}/${folder}`)).forEach((folderSol) => {
fs.readdirSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}`)).forEach((file) => {
if(folderSol === 'upgradeability') {
fs.readdirSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}`)).forEach((folderUpgrade) => {
fs.readdirSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}/${folderUpgrade}`)).forEach((fileUpgrade) => {
if (!fileUpgrade.endsWith('.dbg.json')) {
const abiFile = JSON.parse(
fs.readFileSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}/${folderUpgrade}`, fileUpgrade), 'utf8')
)
abiFile.abi.forEach((element) => {
if (element.type === 'constructor') {
abi.constructor = element
} else {
if (element.name) {
abi[element.name] = element
}
}
})
_contractsAbi[abiFile.contractName] = abi
}
})
})
} else {
if (!file.endsWith('.dbg.json')) {
const abiFile = JSON.parse(
fs.readFileSync(path.join(__dirname, `${contractsABIPath}/${folder}/${folderSol}`, file), 'utf8')
)
abiFile.abi.forEach((element) => {
if (element.type === 'constructor') {
abi.constructor = element
} else {
if (element.name) {
abi[element.name] = element
}
}
})
_contractsAbi[abiFile.contractName] = abi
}
}
}
})
})
_contractsAbi[abiFile.contractName] = abi
})

const contractsAddressesPath = '../alastriaID-truffle-contracts'
const contractsAddressesPath = '../alastriaID-hardhat-contracts'
const contractsInfo = JSON.parse(
fs.readFileSync(path.join(__dirname, `${contractsAddressesPath}`, 'addresses.json'), 'utf8')
fs.readFileSync(path.join(__dirname, `${contractsAddressesPath}`, 'addresses-t.json'), 'utf8')
)

const config = {
Expand Down
42 changes: 32 additions & 10 deletions src/tokenFactory/tokensFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ function createAlastriaSession(
context: string[],
iss: string,
kid: string,
type: string[],
alastriaToken: string,
exp: number,
type: string[],
pku?: string,
nbf?: number,
jti?: string
Expand Down Expand Up @@ -103,27 +103,35 @@ function createAlastriaSession(
}

/** Creates the AlastriaToken
* @param context aditional urls to "https://alastria.github.io/identity/artifacts/v1"
* @param iss DID representing the AlastriaID of the entity that issued the Alastria Token
* @param gwu Provider gateway url
* @param cbu Callbacku url from the user
* @param ani Alastria Network ID
* @param cbu Callback url from the user
* @param exp expiration time
* @param kid indicates which key was used to secure (digitally sign) the JWT
* @param type aditional types to "AlastriaToken"
* @param mfau callback from a mfau
* @param jwk Users public key
* @param nbf not before
* @param jti Unique token identifier
*/
function createAlastriaToken(
context: string[],
iss: string,
gwu: string,
cbu: string,
ani: string,
exp: number,
kid: string,
type: string[],
mfau?: string,
jwk?: string,
nbf?: number,
jti?: string
) {
const requiredContext: string[] = [
'https://alastria.github.io/identity/artifacts/v1'
]
const requiredTypes: string[] = ['AlastriaToken']
if(jwk){
jwk = AddressUtils.getAddressWithHexPrefix(jwk)
}
Expand All @@ -136,11 +144,13 @@ function createAlastriaToken(
jwk
},
payload: {
'@context': requiredContext.concat(context),
iss,
gwu,
cbu,
iat: Math.round(Date.now() / 1000),
ani,
type: requiredTypes.concat(type),
mfau,
nbf,
exp,
jti
Expand All @@ -164,13 +174,14 @@ export function createCredential(
iss: string,
context: string[],
credentialSubject: object,
type: string[],
kid?: string,
sub?: string,
exp?: number,
nbf?: number,
jti?: string,
jwk?: string,
type?: string[]

) {
const requiredContext: string[] = [
'https://www.w3.org/2018/credentials/v1',
Expand Down Expand Up @@ -224,6 +235,7 @@ export function createCredential(
* @param exp identifies the expiration time on or after which the JWT (presentation) MUST NOT be accepted for processing
* @param nbf identifies the time before which the JWT (presentation) MUST NOT be accepted for processing
* @param jti This is the identification of this specific presentation instance (it is NOT the identifier of the holder or of any other actor)
* @param jtipr this is a field that links this presentation to the originally sent presentation request
*/
function createPresentation(
iss: string,
Expand All @@ -237,7 +249,8 @@ function createPresentation(
jwk?: string,
exp?: number,
nbf?: number,
jti?: string
jti?: string,
jtipr?: string,
) {
const requiredContext: string[] = [
'https://www.w3.org/2018/credentials/v1',
Expand All @@ -260,6 +273,7 @@ function createPresentation(
},
payload: {
jti,
jtipr,
iss,
aud,
iat: Math.round(Date.now() / 1000),
Expand Down Expand Up @@ -290,6 +304,9 @@ function createPresentation(
* @param exp identifies the expiration time on or after which the JWT (Presentation Request) MUST NOT be accepted for processing
* @param nbf identifies the time before which the JWT (presentation) MUST NOT be accepted for processing
* @param jti This is the identification of this specific Presentation Request (it is NOT the identifier of the holder or of any other actor)
* @param p_exp it contains the suggested expiration date (exp field) to be used by the corresponding presentation in response to this Presentation Request.
* @param p_exp_delta identifies the time before which the JWT (presentation) MUST NOT be accepted for processing
* @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.
*/
function createPresentationRequest(
iss: string,
Expand All @@ -303,7 +320,10 @@ function createPresentationRequest(
jwk?: string,
exp?: number,
nbf?: number,
jti?: string
p_exp?: number,
p_exp_delta?: number,
jti?: string,
procDesc?: string
) {
const requiredContext: string[] = [
'https://www.w3.org/2018/credentials/v1',
Expand Down Expand Up @@ -331,11 +351,14 @@ function createPresentationRequest(
exp,
nbf,
cbu,
p_exp,
p_exp_delta,
pr: {
'@context': requiredContext.concat(context),
type: requiredTypes.concat(type),
procHash,
procUrl,
procDesc,
data
}
}
Expand Down Expand Up @@ -370,7 +393,6 @@ function createAIC(
kid?: string,
jwk?: string,
jti?: string,
iat?: number,
exp?: number,
nbf?: number
) {
Expand All @@ -396,7 +418,7 @@ function createAIC(
alastriaToken,
publicKey,
jti: jti,
iat: iat,
iat: Math.round(Date.now() / 1000),
exp: exp,
nbf: nbf
}
Expand Down
18 changes: 0 additions & 18 deletions src/txFactory/credentialRegistryTransactionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,6 @@ export function getSubjectCredentialStatus(
return transaction
}

/**
* function getSubjectCredentialList(web3, subject)
* Dev: get invoke getSubjectCredentialList transaction object
* @param web3 ethereum connection
* @param didSubject subject to recover credential list
*/
export function getSubjectCredentialList(web3, didSubject) {
const subjectAddr = AIdUtils.getProxyAddress(didSubject)
const transaction = Object.assign({}, config.basicTransaction)
transaction.data = web3.eth.abi.encodeFunctionCall(
config.contractsAbi.AlastriaCredentialRegistry.getSubjectCredentialList,
[subjectAddr]
)
transaction.to = config.alastriaCredentialRegistry
transaction.gasLimit = 600000
return transaction
}

/**
* function updateCredentialStatus(web3, issuerCredentialHash, status)
* @param web3
Expand Down
22 changes: 21 additions & 1 deletion src/txFactory/identityManagerTransactionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function prepareAlastriaID(web3, signAddress) {
}

/**
* function createAlastriaIdentity(bytes publicKeyData) public validAddress(msg.sender) isOnTimeToLiveAndIsFromCaller(msg.sender)
* THIS METHOD WILL BE DEPREATED
* @param web3
* @param publicKey publicKey is a String
*/
Expand All @@ -57,6 +57,26 @@ export function createAlastriaIdentity(web3, publicKey) {
return transaction
}

/**
* @param web3
* @param publicKeyHash
*/
export function createAlastriaIdentityHash(web3, publicKeyHash) {
const transaction = Object.assign({}, config.basicTransaction)
transaction.gasLimit = 600000
const publicKeyCallData = web3.eth.abi.encodeFunctionCall(
config.contractsAbi.AlastriaPublicKeyRegistry.addPublicKey,
[publicKeyHash]
)
transaction.data = web3.eth.abi.encodeFunctionCall(
config.contractsAbi.AlastriaIdentityManager.createAlastriaIdentity,
[publicKeyCallData]
)
transaction.to = config.alastriaIdentityManager
return transaction
}

/**
* AlastriaIdentityIssuer.sol
* function addIdentityIssuer(address _identityIssuer, Eidas.EidasLevel _level) public alLeastLow(_level) notIdentityIssuer(_identityIssuer)
Expand Down
17 changes: 0 additions & 17 deletions src/txFactory/presentationRegistryTransactionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,6 @@ export function getSubjectPresentationStatus(
return transaction
}

/**
* function getSubjectPresentationList(address subject) public view returns(uint, bytes32[])
* @param web3
* @param didSubject
*/
export function getSubjectPresentationList(web3, didSubject) {
const subjectAddr = AIdUtils.getProxyAddress(didSubject)
const transaction = Object.assign({}, config.basicTransaction)
transaction.data = web3.eth.abi.encodeFunctionCall(
config.contractsAbi.AlastriaPresentationRegistry.getSubjectPresentationList,
[subjectAddr]
)
transaction.to = config.alastriaPresentationRegistry
transaction.gasLimit = 600000
return transaction
}

/**
* Receiver functions
* function updateReceiverPresentation(bytes32 receiverPresentationHash, Status status) public validStatus(status)
Expand Down
Loading

0 comments on commit 111d871

Please sign in to comment.