Skip to content

Commit

Permalink
fix(deps): bump dependencies and adapt code (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceanis committed Nov 8, 2023
1 parent bdc5c28 commit 0a8da00
Show file tree
Hide file tree
Showing 6 changed files with 3,462 additions and 2,104 deletions.
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,28 @@
]
},
"devDependencies": {
"@babel/core": "7.20.2",
"@babel/preset-env": "7.20.2",
"@babel/preset-typescript": "7.18.6",
"@ethers-ext/provider-ganache": "^6.0.0-beta.2",
"@semantic-release/changelog": "6.0.1",
"@babel/core": "7.23.2",
"@babel/preset-env": "7.23.2",
"@babel/preset-typescript": "7.23.2",
"@ethers-ext/provider-ganache": "6.0.0-beta.2",
"@semantic-release/changelog": "6.0.3",
"@semantic-release/git": "10.0.1",
"@types/jest": "29.2.2",
"@typescript-eslint/eslint-plugin": "5.42.0",
"@typescript-eslint/parser": "5.42.0",
"babel-jest": "29.2.2",
"eslint": "8.27.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-jest": "27.1.4",
"eslint-plugin-prettier": "4.2.1",
"jest": "29.2.2",
"@types/jest": "29.5.8",
"@typescript-eslint/eslint-plugin": "6.10.0",
"@typescript-eslint/parser": "6.10.0",
"babel-jest": "29.7.0",
"eslint": "8.53.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-jest": "27.6.0",
"eslint-plugin-prettier": "5.0.1",
"jest": "29.7.0",
"microbundle": "0.15.1",
"prettier": "2.7.1",
"semantic-release": "19.0.5",
"typescript": "4.8.4"
"prettier": "3.0.3",
"semantic-release": "22.0.7",
"typescript": "5.2.2"
},
"dependencies": {
"did-resolver": "^4.1.0",
"ethers": "6.8.1"
"ethers": "^6.8.1"
}
}
34 changes: 15 additions & 19 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { VerificationMethod } from 'did-resolver'
import { keccak256, getAddress, computeAddress, Contract, SigningKey, concat, toBeHex, zeroPadValue } from 'ethers'
import { computeAddress, getAddress } from 'ethers'

export const identifierMatcher = /^(.*)?(0x[0-9a-fA-F]{40}|0x[0-9a-fA-F]{66})$/
export const nullAddress = '0x0000000000000000000000000000000000000000'
Expand Down Expand Up @@ -57,6 +57,7 @@ export interface LegacyVerificationMethod extends VerificationMethod {
publicKeyBase64?: string
/**@deprecated */
publicKeyPem?: string

// eslint-disable-next-line @typescript-eslint/no-explicit-any
[x: string]: any
}
Expand Down Expand Up @@ -121,25 +122,11 @@ export function interpretIdentifier(identifier: string): { address: string; publ
}
}

export async function signMetaTxData(
identity: string,
signerAddress: string,
privateKeyBytes: Uint8Array,
dataBytes: Uint8Array,
didReg: Contract
) {
const nonce = await didReg.nonce(signerAddress)
const paddedNonce = zeroPadValue(toBeHex(nonce), 32)
const dataToSign = concat(['0x1900', await didReg.getAddress(), paddedNonce, identity, dataBytes])
const hash = keccak256(dataToSign)
return new SigningKey(privateKeyBytes).sign(hash)
}

export enum Errors {
/**
* The resolver has failed to construct the DID document.
* This can be caused by a network issue, a wrong registry address or malformed logs while parsing the registry history.
* Please inspect the `DIDResolutionMetadata.message` to debug further.
* This can be caused by a network issue, a wrong registry address or malformed logs while parsing the registry
* history. Please inspect the `DIDResolutionMetadata.message` to debug further.
*/
notFound = 'notFound',

Expand All @@ -149,12 +136,21 @@ export enum Errors {
invalidDid = 'invalidDid',

/**
* The resolver is misconfigured or is being asked to resolve a DID anchored on an unknown network
* The resolver is misconfigured or is being asked to resolve a `DID` anchored on an unknown network
*/
unknownNetwork = 'unknownNetwork',

/**
* The resolver does not supported 'accept' format for {@link did-resolver#DIDResolutionOptions}
* The resolver does not support the 'accept' format requested with `DIDResolutionOptions`
*/
unsupportedFormat = 'unsupportedFormat',
}

/**
* Returns true when the argument is defined and not null.
* Usable as array.filter(isDefined)
* @param arg
*/
export function isDefined<T>(arg: T): arg is Exclude<T, null | undefined> {
return arg !== null && typeof arg !== 'undefined'
}
22 changes: 9 additions & 13 deletions src/logParser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Log, LogDescription, Contract } from 'ethers'
import { bytes32toString, ERC1056Event } from './helpers'
import { Contract, Log, LogDescription } from 'ethers'
import { bytes32toString, ERC1056Event, isDefined } from './helpers'

function populateEventMetaClass(logResult: LogDescription, blockNumber: number): ERC1056Event {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -23,15 +23,11 @@ function populateEventMetaClass(logResult: LogDescription, blockNumber: number):
}

export function logDecoder(contract: Contract, logs: Log[]): ERC1056Event[] {
const results: (ERC1056Event | undefined)[] = logs.map((log: Log) => {
const res = contract.interface.parseLog({ topics: [...log.topics], data: log.data })
if (!res) return
const event = populateEventMetaClass(res, log.blockNumber)
return event
})
const cleanResults: (ERC1056Event | undefined)[] = results.filter((result) => result !== undefined)
// THIS IS THE GIGA HACK JUST TO REMOVE THE POSSIBLE UNDEFINED FROM THE ARRAY
// THAT IS INTRODUCED BY THE .MAP ABOVE
type cleanResult = Exclude<typeof results[0], undefined>
return cleanResults as Array<cleanResult>
return logs
.map((log: Log) => {
const res = contract.interface.parseLog({ topics: [...log.topics], data: log.data })
if (!res) return null
return populateEventMetaClass(res, log.blockNumber)
})
.filter(isDefined)
}
43 changes: 15 additions & 28 deletions src/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BlockTag, encodeBase58 } from 'ethers'
import { ConfigurationOptions, ConfiguredNetworks, configureResolverWithNetworks } from './configuration'
import { EthrDidController } from './controller'
import {
DIDDocument,
DIDResolutionOptions,
Expand All @@ -12,20 +11,20 @@ import {
VerificationMethod,
} from 'did-resolver'
import {
interpretIdentifier,
DIDAttributeChanged,
DIDDelegateChanged,
DIDOwnerChanged,
ERC1056Event,
Errors,
eventNames,
identifierMatcher,
interpretIdentifier,
legacyAlgoMap,
legacyAttrTypes,
LegacyVerificationMethod,
verificationMethodTypes,
identifierMatcher,
nullAddress,
DIDOwnerChanged,
Errors,
strip0x,
verificationMethodTypes,
} from './helpers'
import { logDecoder } from './logParser'

Expand All @@ -41,26 +40,14 @@ export class EthrDidResolver {
}

/**
* returns the current owner of a DID (represented by an address or public key)
*
* @param address
*
* @deprecated
*/
async getOwner(address: string, networkId: string, blockTag?: BlockTag): Promise<string> {
//TODO: check if address or public key
return new EthrDidController(address, this.contracts[networkId]).getOwner(address, blockTag)
}

/**
* returns the previous change
* Returns the block number with the previous change to a particular address (DID)
*
* @param address
* @param address - the address (DID) to check for changes
* @param networkId - the EVM network to check
* @param blockTag - the block tag to use for the query (default: 'latest')
*/
async previousChange(address: string, networkId: string, blockTag?: BlockTag): Promise<bigint> {
const result = await this.contracts[networkId].changed(address, { blockTag })
// console.log(`last change result: '${BigNumber.from(result['0'])}'`)
return result
return await this.contracts[networkId].changed(address, { blockTag })
}

async getBlockMetadata(blockHeight: number, networkId: string): Promise<{ height: string; isoDate: string }> {
Expand Down Expand Up @@ -148,10 +135,10 @@ export class EthrDidResolver {
const keyAgreementRefs: Record<string, string> = {}
const pks: Record<string, VerificationMethod> = {}
const services: Record<string, Service> = {}
// if (typeof blockHeight === 'string') {
// // latest
// blockHeight = -1
// }
if (typeof blockHeight === 'string') {
// latest
blockHeight = -1
}
for (const event of history) {
if (blockHeight !== -1 && event.blockNumber > blockHeight) {
if (nextVersionId > event.blockNumber) {
Expand All @@ -175,7 +162,7 @@ export class EthrDidResolver {
switch (delegateType) {
case 'sigAuth':
auth[eventIndex] = `${did}#delegate-${delegateCount}`
// eslint-disable-line no-fallthrough
// eslint-disable-next-line no-fallthrough
case 'veriKey':
pks[eventIndex] = {
id: `${did}#delegate-${delegateCount}`,
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"sourceMap": true,
"outDir": "lib",
"strict": true,
"skipLibCheck": true,
"noImplicitThis": false,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
Expand Down

0 comments on commit 0a8da00

Please sign in to comment.