Skip to content

Commit

Permalink
chore: remove all uses of SignCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
rflechtner committed Oct 23, 2023
1 parent be7811c commit c92a0f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 40 deletions.
6 changes: 0 additions & 6 deletions packages/core/src/credentialsV1/KiltAttestationProofV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import type {
ICType,
IDelegationNode,
KiltAddress,
SignExtrinsicCallback,
SignerInterface,
} from '@kiltprotocol/types'
import * as CType from '../ctype/index.js'
Expand Down Expand Up @@ -661,11 +660,6 @@ export type AttestationHandler = (
timestamp?: number
}>

export interface DidSigner {
did: DidUri
signer: SignExtrinsicCallback
}

export type TxHandler = {
account: KiltAddress
signAndSubmit?: AttestationHandler
Expand Down
53 changes: 19 additions & 34 deletions packages/did/src/Did.signature.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import type {
KiltKeyringPair,
KeyringPair,
DidDocument,
SignCallback,
DidUrl,
DidSignature,
DereferenceResult,
SignerInterface,
} from '@kiltprotocol/types'

import { Crypto, SDKErrors } from '@kiltprotocol/utils'
import { Crypto, SDKErrors, Signers } from '@kiltprotocol/utils'
import { randomAsHex, randomAsU8a } from '@polkadot/util-crypto'

import type { NewLightDidVerificationKey } from './DidDetails'
Expand Down Expand Up @@ -308,8 +307,8 @@ describe('light DID', () => {
describe('full DID', () => {
let keypair: KiltKeyringPair
let did: DidDocument
let sign: SignCallback
beforeAll(() => {
let signer: SignerInterface & { id: DidUrl }
beforeAll(async () => {
keypair = Crypto.makeKeypairFromSeed()
did = {
id: `did:kilt:${keypair.address}`,
Expand All @@ -323,15 +322,11 @@ describe('full DID', () => {
},
],
}
sign = async ({ data, did: signingDid }) => ({
signature: keypair.sign(data),
verificationMethod: {
id: '#0x12345',
controller: signingDid,
type: 'Multikey',
publicKeyMultibase: keypairToMultibaseKey(keypair),
},
})
signer = (await Signers.signerFromKeypair({
keypair,
keyUri: `${did.id}#0x12345`,
algorithm: 'Ed25519',
})) as SignerInterface & { id: DidUrl }
})

beforeEach(() => {
Expand All @@ -358,33 +353,29 @@ describe('full DID', () => {

it('verifies did signature over string', async () => {
const SIGNED_STRING = 'signed string'
const { signature, verificationMethod } = await sign({
const signature = await signer.sign({
data: Crypto.coToUInt8(SIGNED_STRING),
did: did.id,
verificationRelationship: 'authentication',
})
await expect(
verifyDidSignature({
message: SIGNED_STRING,
signature,
signerUrl: `${did.id}${verificationMethod.id}`,
signerUrl: signer.id,
expectedVerificationRelationship: 'authentication',
})
).resolves.not.toThrow()
})

it('verifies did signature over bytes', async () => {
const SIGNED_BYTES = Uint8Array.from([1, 2, 3, 4, 5])
const { signature, verificationMethod } = await sign({
const signature = await signer.sign({
data: SIGNED_BYTES,
did: did.id,
verificationRelationship: 'authentication',
})
await expect(
verifyDidSignature({
message: SIGNED_BYTES,
signature,
signerUrl: `${did.id}${verificationMethod.id}`,
signerUrl: signer.id,
expectedVerificationRelationship: 'authentication',
})
).resolves.not.toThrow()
Expand All @@ -397,16 +388,14 @@ describe('full DID', () => {
contentStream: { id: did.id },
})
const SIGNED_STRING = 'signed string'
const { signature, verificationMethod } = await sign({
const signature = await signer.sign({
data: Crypto.coToUInt8(SIGNED_STRING),
did: did.id,
verificationRelationship: 'authentication',
})
await expect(
verifyDidSignature({
message: SIGNED_STRING,
signature,
signerUrl: `${did.id}${verificationMethod.id}`,
signerUrl: signer.id,
expectedVerificationRelationship: 'authentication',
})
).rejects.toThrow()
Expand All @@ -418,27 +407,23 @@ describe('full DID', () => {
dereferencingMetadata: { error: 'notFound' },
})
const SIGNED_STRING = 'signed string'
const { signature, verificationMethod } = await sign({
const signature = await signer.sign({
data: Crypto.coToUInt8(SIGNED_STRING),
did: did.id,
verificationRelationship: 'authentication',
})
await expect(
verifyDidSignature({
message: SIGNED_STRING,
signature,
signerUrl: `${did.id}${verificationMethod.id}`,
signerUrl: signer.id,
expectedVerificationRelationship: 'authentication',
})
).rejects.toThrow()
})

it('accepts signature of full did for light did if enabled', async () => {
const SIGNED_STRING = 'signed string'
const { signature, verificationMethod } = await sign({
const signature = await signer.sign({
data: Crypto.coToUInt8(SIGNED_STRING),
did: did.id,
verificationRelationship: 'authentication',
})

const authKey = did.verificationMethod?.find(
Expand All @@ -460,7 +445,7 @@ describe('full DID', () => {
verifyDidSignature({
message: SIGNED_STRING,
signature,
signerUrl: `${did.id}${verificationMethod.id}`,
signerUrl: signer.id,
expectedSigner,
expectedVerificationRelationship: 'authentication',
})
Expand All @@ -470,7 +455,7 @@ describe('full DID', () => {
verifyDidSignature({
message: SIGNED_STRING,
signature,
signerUrl: `${did.id}${verificationMethod.id}`,
signerUrl: signer.id,
expectedSigner,
allowUpgraded: true,
expectedVerificationRelationship: 'authentication',
Expand Down

0 comments on commit c92a0f9

Please sign in to comment.