Skip to content

Commit

Permalink
test: add test for expressing a Bls key (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceanis authored Dec 18, 2023
1 parent 3ac8765 commit 2d1eaa9
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/__tests__/resolve.attribute.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract, ethers } from 'ethers'
import { Contract, ethers, hexlify, toUtf8Bytes } from 'ethers'
import { Resolvable } from 'did-resolver'

import { GanacheProvider } from '@ethers-ext/provider-ganache'
Expand Down Expand Up @@ -51,6 +51,38 @@ describe('attributes', () => {
})
})

it('add Bls12381G2Key2020 assertion key', async () => {
expect.assertions(1)
const { address: identity, shortDID: did, signer } = await randomAccount(provider)
const pubKey = hexlify(toUtf8Bytes("public key material here")) // encodes to 0x7075626c6963206b6579206d6174657269616c2068657265 in base16
await new EthrDidController(identity, registryContract, signer).setAttribute(
'did/pub/Bls12381G2Key2020', // attrName must fit into 32 bytes. Anything extra will be truncated.
pubKey, // There's no limit on the size of the public key material
86401
)
const { didDocument } = await didResolver.resolve(did)
expect(didDocument).toEqual({
'@context': expect.anything(),
id: did,
verificationMethod: [
{
id: `${did}#controller`,
type: 'EcdsaSecp256k1RecoveryMethod2020',
controller: did,
blockchainAccountId: `eip155:1337:${identity}`,
},
{
id: `${did}#delegate-1`,
type: 'Bls12381G2Key2020',
controller: did,
publicKeyHex: "7075626c6963206b6579206d6174657269616c2068657265",
},
],
authentication: [`${did}#controller`],
assertionMethod: [`${did}#controller`, `${did}#delegate-1`],
})
})

it('add Ed25519VerificationKey2018 authentication key', async () => {
expect.assertions(1)
const { address: identity, shortDID: did, signer } = await randomAccount(provider)
Expand Down

0 comments on commit 2d1eaa9

Please sign in to comment.