Skip to content

Commit

Permalink
feat: simplify sign and encrypt callbacks (#624)
Browse files Browse the repository at this point in the history
* feat: simplify sign and encrypt callbacks

* feat: more radical approach

* feat: select keyRelationship, instead of keyId

* feat: combine signcallback and signextrinsiccallback & cleanup callback file

* feat: reintroduce did as hint for the callbacks

* test: fix unit tests

* test: fix integration tests

* test: fix bundle tests

* test: fix w3n integration tests

* feat: inline signWithoutDid

* feat: consistent naming

* feat: change createPresentation param order

* test: no need to export StoreDidCallback

* feat: pr feedback

* feat: optional keyRelationship param for singPayload

* refactor: rename testutils sign callbacks

* refactor: same for bundle tests
  • Loading branch information
tjwelde authored Sep 20, 2022
1 parent 2b246ee commit a52eb1d
Show file tree
Hide file tree
Showing 23 changed files with 634 additions and 642 deletions.
28 changes: 14 additions & 14 deletions packages/core/src/__integrationtests__/AccountLinking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ describe('When there is an on-chain DID', () => {

const associateSenderTx = api.tx.didLookup.associateSender()
const signedTx = await Did.authorizeExtrinsic(
did,
did.uri,
associateSenderTx,
didKey.sign,
didKey.getSignCallback(did),
paymentAccount.address
)
const balanceBefore = (
Expand Down Expand Up @@ -126,9 +126,9 @@ describe('When there is an on-chain DID', () => {
it('should be possible to associate the tx sender to a new DID', async () => {
const associateSenderTx = api.tx.didLookup.associateSender()
const signedTx = await Did.authorizeExtrinsic(
newDid,
newDid.uri,
associateSenderTx,
newDidKey.sign,
newDidKey.getSignCallback(newDid),
paymentAccount.address
)
const balanceBefore = (
Expand Down Expand Up @@ -241,9 +241,9 @@ describe('When there is an on-chain DID', () => {
sign
)
const signedTx = await Did.authorizeExtrinsic(
did,
did.uri,
api.tx.didLookup.associateAccount(...args),
didKey.sign,
didKey.getSignCallback(did),
paymentAccount.address
)
const balanceBefore = (
Expand Down Expand Up @@ -296,9 +296,9 @@ describe('When there is an on-chain DID', () => {
sign
)
const signedTx = await Did.authorizeExtrinsic(
newDid,
newDid.uri,
api.tx.didLookup.associateAccount(...args),
newDidKey.sign,
newDidKey.getSignCallback(newDid),
paymentAccount.address
)
const balanceBefore = (
Expand Down Expand Up @@ -364,9 +364,9 @@ describe('When there is an on-chain DID', () => {
const removeLinkTx =
api.tx.didLookup.removeAccountAssociation(keypairChain)
const signedTx = await Did.authorizeExtrinsic(
newDid,
newDid.uri,
removeLinkTx,
newDidKey.sign,
newDidKey.getSignCallback(newDid),
paymentAccount.address
)
const balanceBefore = (
Expand Down Expand Up @@ -435,9 +435,9 @@ describe('When there is an on-chain DID', () => {
sign
)
const signedTx = await Did.authorizeExtrinsic(
did,
did.uri,
api.tx.didLookup.associateAccount(...args),
didKey.sign,
didKey.getSignCallback(did),
paymentAccount.address
)
const balanceBefore = (
Expand Down Expand Up @@ -490,9 +490,9 @@ describe('When there is an on-chain DID', () => {
it('should be possible to add a Web3 name for the linked DID and retrieve it starting from the linked account', async () => {
const web3NameClaimTx = api.tx.web3Names.claim('test-name')
const signedTx = await Did.authorizeExtrinsic(
did,
did.uri,
web3NameClaimTx,
didKey.sign,
didKey.getSignCallback(did),
paymentAccount.address
)
await submitExtrinsic(signedTx, paymentAccount)
Expand Down
79 changes: 36 additions & 43 deletions packages/core/src/__integrationtests__/Attestation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ describe('handling attestations that do not exist', () => {
it('Attestation.getRevokeTx', async () => {
const draft = api.tx.attestation.revoke(claimHash, null)
const authorized = await Did.authorizeExtrinsic(
attester,
attester.uri,
draft,
attesterKey.sign,
attesterKey.getSignCallback(attester),
tokenHolder.address
)
await expect(
Expand All @@ -98,9 +98,9 @@ describe('handling attestations that do not exist', () => {
it('Attestation.getRemoveTx', async () => {
const draft = api.tx.attestation.remove(claimHash, null)
const authorized = await Did.authorizeExtrinsic(
attester,
attester.uri,
draft,
attesterKey.sign,
attesterKey.getSignCallback(attester),
tokenHolder.address
)
await expect(
Expand All @@ -117,9 +117,9 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
const ctypeExists = await isCtypeOnChain(driversLicenseCType)
if (ctypeExists) return
const tx = await Did.authorizeExtrinsic(
attester,
attester.uri,
api.tx.ctype.add(CType.toChain(driversLicenseCType)),
attesterKey.sign,
attesterKey.getSignCallback(attester),
tokenHolder.address
)
await submitExtrinsic(tx, tokenHolder)
Expand All @@ -135,8 +135,7 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
const credential = Credential.fromClaim(claim)
const presentation = await Credential.createPresentation({
credential,
signCallback: claimerKey.sign,
claimerDid: claimer,
signCallback: claimerKey.getSignCallback(claimer),
})
expect(() => Credential.verifyDataIntegrity(presentation)).not.toThrow()
await expect(
Expand All @@ -158,8 +157,7 @@ describe('When there is an attester, claimer and ctype drivers license', () => {

const presentation = await Credential.createPresentation({
credential,
signCallback: claimerKey.sign,
claimerDid: claimer,
signCallback: claimerKey.getSignCallback(claimer),
})
await expect(
Credential.verifySignature(presentation)
Expand All @@ -176,9 +174,9 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
null
)
const authorizedStoreTx = await Did.authorizeExtrinsic(
attester,
attester.uri,
storeTx,
attesterKey.sign,
attesterKey.getSignCallback(attester),
tokenHolder.address
)
await submitExtrinsic(authorizedStoreTx, tokenHolder)
Expand Down Expand Up @@ -212,8 +210,7 @@ describe('When there is an attester, claimer and ctype drivers license', () => {

const presentation = await Credential.createPresentation({
credential,
signCallback: claimerKey.sign,
claimerDid: claimer,
signCallback: claimerKey.getSignCallback(claimer),
})
await expect(
Credential.verifySignature(presentation)
Expand All @@ -223,17 +220,17 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
presentation,
attester.uri
)
const { keypair, sign } = makeSigningKeyTool()
const { keypair, getSignCallback } = makeSigningKeyTool()

const storeTx = api.tx.attestation.add(
attestation.claimHash,
attestation.cTypeHash,
null
)
const authorizedStoreTx = await Did.authorizeExtrinsic(
attester,
attester.uri,
storeTx,
sign,
getSignCallback(attester),
keypair.address
)
await expect(
Expand Down Expand Up @@ -280,9 +277,9 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
null
)
const authorizedStoreTx = await Did.authorizeExtrinsic(
attester,
attester.uri,
storeTx,
attesterKey.sign,
attesterKey.getSignCallback(attester),
tokenHolder.address
)

Expand All @@ -305,8 +302,7 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
credential = Credential.fromClaim(claim)
const presentation = await Credential.createPresentation({
credential,
signCallback: claimerKey.sign,
claimerDid: claimer,
signCallback: claimerKey.getSignCallback(claimer),
})
attestation = Attestation.fromCredentialAndDid(credential, attester.uri)
const storeTx = api.tx.attestation.add(
Expand All @@ -315,9 +311,9 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
null
)
const authorizedStoreTx = await Did.authorizeExtrinsic(
attester,
attester.uri,
storeTx,
attesterKey.sign,
attesterKey.getSignCallback(attester),
tokenHolder.address
)
await submitExtrinsic(authorizedStoreTx, tokenHolder)
Expand All @@ -338,9 +334,9 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
null
)
const authorizedStoreTx = await Did.authorizeExtrinsic(
attester,
attester.uri,
storeTx,
attesterKey.sign,
attesterKey.getSignCallback(attester),
tokenHolder.address
)

Expand All @@ -362,8 +358,7 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
const fakeCredential = Credential.fromClaim(claim)
await Credential.createPresentation({
credential,
signCallback: claimerKey.sign,
claimerDid: claimer,
signCallback: claimerKey.getSignCallback(claimer),
})

expect(() =>
Expand All @@ -374,9 +369,9 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
it('should not be possible for the claimer to revoke an attestation', async () => {
const revokeTx = api.tx.attestation.revoke(attestation.claimHash, null)
const authorizedRevokeTx = await Did.authorizeExtrinsic(
claimer,
claimer.uri,
revokeTx,
claimerKey.sign,
claimerKey.getSignCallback(claimer),
tokenHolder.address
)

Expand All @@ -401,9 +396,9 @@ describe('When there is an attester, claimer and ctype drivers license', () => {

const revokeTx = api.tx.attestation.revoke(attestation.claimHash, null)
const authorizedRevokeTx = await Did.authorizeExtrinsic(
attester,
attester.uri,
revokeTx,
attesterKey.sign,
attesterKey.getSignCallback(attester),
tokenHolder.address
)
await submitExtrinsic(authorizedRevokeTx, tokenHolder)
Expand All @@ -419,9 +414,9 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
it('should be possible for the deposit payer to remove an attestation', async () => {
const removeTx = api.tx.attestation.remove(attestation.claimHash, null)
const authorizedRemoveTx = await Did.authorizeExtrinsic(
attester,
attester.uri,
removeTx,
attesterKey.sign,
attesterKey.getSignCallback(attester),
tokenHolder.address
)
await submitExtrinsic(authorizedRemoveTx, tokenHolder)
Expand Down Expand Up @@ -450,9 +445,9 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
CType.toChain(officialLicenseAuthorityCType)
)
const authorizedStoreTx = await Did.authorizeExtrinsic(
attester,
attester.uri,
storeTx,
attesterKey.sign,
attesterKey.getSignCallback(attester),
tokenHolder.address
)
await submitExtrinsic(authorizedStoreTx, tokenHolder)
Expand All @@ -473,8 +468,7 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
const credential1 = Credential.fromClaim(licenseAuthorization)
await Credential.createPresentation({
credential: credential1,
signCallback: claimerKey.sign,
claimerDid: claimer,
signCallback: claimerKey.getSignCallback(claimer),
})
const licenseAuthorizationGranted = Attestation.fromCredentialAndDid(
credential1,
Expand All @@ -486,9 +480,9 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
null
)
const authorizedStoreTx = await Did.authorizeExtrinsic(
anotherAttester,
anotherAttester.uri,
storeTx,
anotherAttesterKey.sign,
anotherAttesterKey.getSignCallback(anotherAttester),
tokenHolder.address
)
await submitExtrinsic(authorizedStoreTx, tokenHolder)
Expand All @@ -504,8 +498,7 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
})
await Credential.createPresentation({
credential: credential2,
signCallback: claimerKey.sign,
claimerDid: claimer,
signCallback: claimerKey.getSignCallback(claimer),
})
const licenseGranted = Attestation.fromCredentialAndDid(
credential2,
Expand All @@ -517,9 +510,9 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
null
)
const authorizedStoreTx2 = await Did.authorizeExtrinsic(
attester,
attester.uri,
storeTx2,
attesterKey.sign,
attesterKey.getSignCallback(attester),
tokenHolder.address
)
await submitExtrinsic(authorizedStoreTx2, tokenHolder)
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/__integrationtests__/Ctypes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ describe('When there is an CtypeCreator and a verifier', () => {

it('should not be possible to create a claim type w/o tokens', async () => {
const ctype = makeCType()
const { keypair, sign } = makeSigningKeyTool()
const { keypair, getSignCallback } = makeSigningKeyTool()
const storeTx = api.tx.ctype.add(CType.toChain(ctype))
const authorizedStoreTx = await Did.authorizeExtrinsic(
ctypeCreator,
ctypeCreator.uri,
storeTx,
sign,
getSignCallback(ctypeCreator),
keypair.address
)
await expect(
Expand All @@ -76,9 +76,9 @@ describe('When there is an CtypeCreator and a verifier', () => {
const ctype = makeCType()
const storeTx = api.tx.ctype.add(CType.toChain(ctype))
const authorizedStoreTx = await Did.authorizeExtrinsic(
ctypeCreator,
ctypeCreator.uri,
storeTx,
key.sign,
key.getSignCallback(ctypeCreator),
paymentAccount.address
)
await submitExtrinsic(authorizedStoreTx, paymentAccount)
Expand All @@ -96,18 +96,18 @@ describe('When there is an CtypeCreator and a verifier', () => {
const ctype = makeCType()
const storeTx = api.tx.ctype.add(CType.toChain(ctype))
const authorizedStoreTx = await Did.authorizeExtrinsic(
ctypeCreator,
ctypeCreator.uri,
storeTx,
key.sign,
key.getSignCallback(ctypeCreator),
paymentAccount.address
)
await submitExtrinsic(authorizedStoreTx, paymentAccount)

const storeTx2 = api.tx.ctype.add(CType.toChain(ctype))
const authorizedStoreTx2 = await Did.authorizeExtrinsic(
ctypeCreator,
ctypeCreator.uri,
storeTx2,
key.sign,
key.getSignCallback(ctypeCreator),
paymentAccount.address
)
await expect(
Expand Down
Loading

0 comments on commit a52eb1d

Please sign in to comment.