Skip to content

Commit

Permalink
fix: bigint handling and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
fermentfan committed Nov 9, 2023
1 parent 5ecab76 commit d6039cf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spherity/ethr-revocation-registry-controller",
"version": "1.3.1",
"version": "1.3.2",
"description": "The controller module for interacting with Ethereum revocation lists & resolving revocation entries for EIP-5539.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
32 changes: 16 additions & 16 deletions src/EthereumRevocationRegistryController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type TimestampedEvent<T extends TypedContractEvent> = T & {
export type Signaturish = {
signer: string
signature: string
nonce: bigint
nonce: number
}

export type ChangeStatusSignedOperation = Signaturish & {
Expand Down Expand Up @@ -128,7 +128,7 @@ export class EthereumRevocationRegistryController {
return {
name: EIP712DomainName,
version: version,
chainId: chainId,
chainId: Number(chainId),
verifyingContract: await this.registry.getAddress()
} as TypedDataDomain
}
Expand Down Expand Up @@ -201,9 +201,9 @@ export class EthereumRevocationRegistryController {
}
}

private async checkNonceForAddress(address: string, expectedNonce: bigint) {
private async checkNonceForAddress(address: string, expectedNonce: number) {
const currentNonce = await this.registry.nonces(address)
if(currentNonce !== expectedNonce) {
if(Number(currentNonce) !== expectedNonce) {
throw new Error(`Nonce in the payload is out of date or invalid (Expected: '${expectedNonce}' ; Current: '${currentNonce}').`)
}
}
Expand Down Expand Up @@ -326,7 +326,7 @@ export class EthereumRevocationRegistryController {
revocationList: revocationKeyPath.list,
revocationKey: revocationKeyPath.revocationKey,
signer: signer,
nonce: nonce
nonce: Number(nonce)
}

let signature: string
Expand All @@ -341,7 +341,7 @@ export class EthereumRevocationRegistryController {
revocationKeyPath: revocationKeyPath,
signer: signer,
signature: signature,
nonce: nonce
nonce: Number(nonce)
} as ChangeStatusSignedOperation
}

Expand Down Expand Up @@ -468,7 +468,7 @@ export class EthereumRevocationRegistryController {
revocationList: revocationListPath.list,
revocationKeys: keysAndStatuses.revocationKeys,
signer: signer,
nonce: nonce
nonce: Number(nonce)
}

let signature: string
Expand All @@ -483,7 +483,7 @@ export class EthereumRevocationRegistryController {
revocationKeyInstructions: revocationKeyInstructions,
signer: signer,
signature: signature,
nonce: nonce
nonce: Number(nonce)
} as ChangeStatusesInListSignedOperation
}

Expand Down Expand Up @@ -526,7 +526,7 @@ export class EthereumRevocationRegistryController {
newOwner: newOwner,
revocationList: revocationListPath.list,
signer: signer,
nonce: nonce
nonce: Number(nonce)
}

const signature = await this.registry.runner.signTypedData(this.typedDataDomain, EIP712ChangeListOwnerType, values)
Expand All @@ -536,7 +536,7 @@ export class EthereumRevocationRegistryController {
newOwner: newOwner,
signer: signer,
signature: signature,
nonce: nonce
nonce: Number(nonce)
} as ChangeListOwnerSignedOperation
}

Expand Down Expand Up @@ -588,7 +588,7 @@ export class EthereumRevocationRegistryController {
revocationList: revocationListPath.list,
validity: expiryDateEpochSeconds,
signer: signer,
nonce: nonce
nonce: Number(nonce)
}

const signature = await this.registry.runner.signTypedData(this.typedDataDomain, EIP712AddListDelegateType, values)
Expand All @@ -599,7 +599,7 @@ export class EthereumRevocationRegistryController {
expiryDate: expiryDate,
signer: signer,
signature: signature,
nonce: nonce
nonce: Number(nonce)
} as AddListDelegateSignedOperation
}

Expand Down Expand Up @@ -636,7 +636,7 @@ export class EthereumRevocationRegistryController {
delegate: delegate,
revocationList: revocationListPath.list,
signer: signer,
nonce: nonce
nonce: Number(nonce)
}

const signature = await this.registry.runner.signTypedData(this.typedDataDomain, EIP712RemoveListDelegateType, values)
Expand All @@ -646,7 +646,7 @@ export class EthereumRevocationRegistryController {
delegate: delegate,
signer: signer,
signature: signature,
nonce: nonce
nonce: Number(nonce)
} as RemoveListDelegateSignedOperation
}

Expand Down Expand Up @@ -687,7 +687,7 @@ export class EthereumRevocationRegistryController {
namespace: revocationListPath.namespace,
revocationList: revocationListPath.list,
signer: signer,
nonce: nonce
nonce: Number(nonce)
}

const signature = await this.registry.runner.signTypedData(this.typedDataDomain, EIP712ChangeListStatusType, values)
Expand All @@ -697,7 +697,7 @@ export class EthereumRevocationRegistryController {
revocationListPath: revocationListPath,
signer: signer,
signature: signature,
nonce: nonce
nonce: Number(nonce)
} as ChangeListStatusSignedOperation
}

Expand Down
28 changes: 14 additions & 14 deletions test/EthereumRevocationRegistryController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ describe('EthrRevocationRegistryController', () => {
revocationKeyPath: revocationKeyPath,
signer: validAddress,
signature: web3.utils.keccak256("mockedSignature"),
nonce: 0n
nonce: 0
} as ChangeStatusSignedOperation

when(registryContractMock.nonces).calledWith(changeStatusSignedOperation.signer).mockResolvedValue(0n)
Expand Down Expand Up @@ -541,7 +541,7 @@ describe('EthrRevocationRegistryController', () => {
revocationKeyPath: revocationKeyPath,
signer: validAddress,
signature: "",
nonce: 0n
nonce: 0
} as ChangeStatusSignedOperation

when(registryContractMock.nonces).calledWith(changeStatusSignedOperation.signer).mockResolvedValue(0n)
Expand All @@ -559,7 +559,7 @@ describe('EthrRevocationRegistryController', () => {
revocationKeyPath: revocationKeyPath,
signer: validAddress,
signature: "asd",
nonce: 0n
nonce: 0
} as ChangeStatusSignedOperation

when(registryContractMock.nonces).calledWith(changeStatusSignedOperation.signer).mockResolvedValue(0n)
Expand All @@ -580,7 +580,7 @@ describe('EthrRevocationRegistryController', () => {
revocationKeyPath: revocationKeyPath,
signer: validAddress,
signature: "",
nonce: 0n
nonce: 0
} as ChangeStatusSignedOperation

when(registryContractMock.nonces).calledWith(changeStatusSignedOperation.signer).mockResolvedValue(0n)
Expand All @@ -598,7 +598,7 @@ describe('EthrRevocationRegistryController', () => {
revocationKeyPath: revocationKeyPath,
signer: web3.utils.keccak256("invalidAddress"),
signature: web3.utils.keccak256("mockedSignature"),
nonce: 0n
nonce: 0
} as ChangeStatusSignedOperation

when(registryContractMock.nonces).calledWith(changeStatusSignedOperation.signer).mockResolvedValue(0n)
Expand Down Expand Up @@ -637,7 +637,7 @@ describe('EthrRevocationRegistryController', () => {
revocationKeyPath: revocationKeyPath,
signer: validAddress,
signature: "",
nonce: 0n
nonce: 0
} as ChangeStatusSignedOperation

when(registryContractMock.nonces).calledWith(changeStatusSignedOperation.signer).mockResolvedValue(1n)
Expand All @@ -658,7 +658,7 @@ describe('EthrRevocationRegistryController', () => {
revocationKeyPath: revocationKeyPath,
signer: validAddress,
signature: web3.utils.keccak256("mockedSignature"),
nonce: 0n
nonce: 0
} as ChangeStatusSignedOperation

when(registryContractMock.nonces).calledWith(changeStatusSignedOperation.signer).mockResolvedValue(0n)
Expand All @@ -676,7 +676,7 @@ describe('EthrRevocationRegistryController', () => {
revocationKeyPath: revocationKeyPath,
signer: validAddress,
signature: web3.utils.keccak256("mockedSignature"),
nonce: 0n
nonce: 0
} as ChangeStatusSignedOperation

when(registryContractMock.nonces).calledWith(changeStatusSignedOperation.signer).mockResolvedValue(0n)
Expand All @@ -697,7 +697,7 @@ describe('EthrRevocationRegistryController', () => {
revocationKeyPath: revocationKeyPath,
signer: validAddress,
signature: web3.utils.keccak256("mockedSignature"),
nonce: 0n
nonce: 0
} as ChangeStatusSignedOperation

when(registryContractMock.nonces).calledWith(changeStatusSignedOperation.signer).mockResolvedValue(0n)
Expand All @@ -715,7 +715,7 @@ describe('EthrRevocationRegistryController', () => {
revocationKeyPath: revocationKeyPath,
signer: validAddress,
signature: web3.utils.keccak256("mockedSignature"),
nonce: 0n
nonce: 0
} as ChangeStatusSignedOperation

when(registryContractMock.nonces).calledWith(changeStatusSignedOperation.signer).mockResolvedValue(0n)
Expand All @@ -736,7 +736,7 @@ describe('EthrRevocationRegistryController', () => {
revocationKeyPath: revocationKeyPath,
signer: validAddress,
signature: web3.utils.keccak256("mockedSignature"),
nonce: 0n
nonce: 0
} as ChangeStatusSignedOperation

when(registryContractMock.nonces).calledWith(changeStatusSignedOperation.signer).mockResolvedValue(0n)
Expand All @@ -754,7 +754,7 @@ describe('EthrRevocationRegistryController', () => {
revocationKeyPath: revocationKeyPath,
signer: validAddress,
signature: web3.utils.keccak256("mockedSignature"),
nonce: 0n
nonce: 0
} as ChangeStatusSignedOperation

when(registryContractMock.nonces).calledWith(changeStatusSignedOperation.signer).mockResolvedValue(0n)
Expand All @@ -767,7 +767,7 @@ describe('EthrRevocationRegistryController', () => {
describe('generateChangeStatusSignedPayload input verification', () => {
it('should return a ChangeStatusSignedOperation', async () => {
const revocationStatus = true
const nonce = 0n
const nonce = 0
const signature = "mockedSignatureasd"
const revocationKeyPath: RevocationKeyPath = {
namespace: validAddress,
Expand All @@ -782,7 +782,7 @@ describe('EthrRevocationRegistryController', () => {
chainId: networkMock.chainId,
verifyingContract: addressMock
}, expect.anything(), expect.anything()).mockResolvedValue(signature)
when(registryContractMock.nonces).calledWith(validAddress).mockResolvedValue(nonce)
when(registryContractMock.nonces).calledWith(validAddress).mockResolvedValue(BigInt(nonce))
expect(registry.generateChangeStatusSignedPayload(revocationStatus, revocationKeyPath)).resolves.toEqual({
revoked: revocationStatus,
revocationKeyPath: revocationKeyPath,
Expand Down

0 comments on commit d6039cf

Please sign in to comment.