66 */
77
88/* eslint-disable @typescript-eslint/ban-ts-comment */
9- import {
10- CType ,
11- Claim ,
12- DidDocument ,
13- ICType ,
14- IClaim ,
15- Credential ,
16- Quote ,
17- IConfirmPaymentContent ,
18- IAttestation ,
19- connect ,
20- KiltKeyringPair ,
21- DecryptCallback ,
22- EncryptCallback ,
23- ConfigService ,
24- ChainHelpers ,
25- Blockchain ,
26- } from '@kiltprotocol/sdk-js'
9+ import { Blockchain } from '@kiltprotocol/chain-helpers'
10+ import { CType } from '@kiltprotocol/credentials'
11+ import { Claim , Credential } from '@kiltprotocol/legacy-credentials'
12+ import { ConfigService , connect } from '@kiltprotocol/sdk-js'
13+ import type { DidDocument , IAttestation , ICType , IClaim , KiltKeyringPair } from '@kiltprotocol/types'
14+ import Keyring from '@polkadot/keyring'
2715import { BN } from '@polkadot/util'
2816import { mnemonicGenerate } from '@polkadot/util-crypto'
29- import Keyring from '@polkadot/keyring'
30-
3117import {
32- KeyToolSignCallback ,
18+ confirmPayment ,
19+ receiveAttestation ,
20+ requestAttestation ,
21+ requestPayment ,
22+ submitAttestation ,
23+ submitTerms ,
24+ validateConfirmedPayment ,
25+ } from '.'
26+ import { createAttesterSignedQuote , verifyAttesterSignedQuote , verifyQuoteAgreement } from '../../../quote'
27+ import {
28+ KeyToolSigners ,
3329 createAttestation ,
3430 createCtype ,
3531 fundAccount ,
3632 generateDid ,
3733 keypairs ,
3834 makeDecryptCallback ,
35+ makeDidSigners ,
3936 makeEncryptCallback ,
40- makeSignCallback ,
4137 startContainer ,
4238} from '../../../tests'
43- import { receiveSessionRequest , requestSession , verifySession } from '../session'
44- import { IRequestAttestation , IRequestPayment , ISession , ISessionRequest , ISubmitTerms , ITerms } from '../../../types'
4539import {
46- confirmPayment ,
47- receiveAttestation ,
48- requestAttestation ,
49- requestPayment ,
50- submitAttestation ,
51- submitTerms ,
52- validateConfirmedPayment ,
53- } from '.'
40+ DecryptCallback ,
41+ EncryptCallback ,
42+ IConfirmPaymentContent ,
43+ IRequestAttestation ,
44+ IRequestPayment ,
45+ ISession ,
46+ ISessionRequest ,
47+ ISubmitTerms ,
48+ ITerms ,
49+ } from '../../../types'
5450import {
5551 isIConfirmPayment ,
5652 isIRequestPayment ,
@@ -59,22 +55,22 @@ import {
5955 isSubmitTerms ,
6056} from '../../../utils'
6157import { decrypt } from '../../MessageEnvelope'
62- import { verifyAttesterSignedQuote , verifyQuoteAgreement } from '../../../quote '
58+ import { receiveSessionRequest , requestSession , verifySession } from '../session '
6359
6460describe ( 'Attestation' , ( ) => {
6561 //Alice
6662 let aliceAccount : KiltKeyringPair
6763 let aliceFullDid : DidDocument
68- let aliceSign : KeyToolSignCallback
69- let aliceSignAssertion : KeyToolSignCallback
64+ let aliceSign : KeyToolSigners
65+ let aliceSignAssertion : KeyToolSigners
7066 let aliceDecryptCallback : DecryptCallback
7167 let aliceEncryptCallback : EncryptCallback
7268 let aliceMnemonic : string
7369
7470 //Bob
7571 let bobAccount : KiltKeyringPair
7672 let bobFullDid : DidDocument
77- let bobSign : KeyToolSignCallback
73+ let bobSign : KeyToolSigners
7874 let bobDecryptCallback : DecryptCallback
7975 let bobEncryptCallback : EncryptCallback
8076
@@ -107,8 +103,8 @@ describe('Attestation', () => {
107103 const keyPairsAlice = await keypairs ( aliceMnemonic )
108104 aliceEncryptCallback = makeEncryptCallback ( keyPairsAlice . keyAgreement ) ( aliceFullDid )
109105 aliceDecryptCallback = makeDecryptCallback ( keyPairsAlice . keyAgreement )
110- aliceSign = makeSignCallback ( keyPairsAlice . authentication )
111- aliceSignAssertion = makeSignCallback ( keyPairsAlice . assertionMethod )
106+ aliceSign = makeDidSigners ( keyPairsAlice . authentication )
107+ aliceSignAssertion = makeDidSigners ( keyPairsAlice . assertionMethod )
112108
113109 //setup bob
114110 const bobMnemonic = mnemonicGenerate ( )
@@ -119,7 +115,7 @@ describe('Attestation', () => {
119115 const keyPairsBob = await keypairs ( bobMnemonic )
120116 bobEncryptCallback = makeEncryptCallback ( keyPairsBob . keyAgreement ) ( bobFullDid )
121117 bobDecryptCallback = makeDecryptCallback ( keyPairsBob . keyAgreement )
122- bobSign = makeSignCallback ( keyPairsBob . authentication )
118+ bobSign = makeDidSigners ( keyPairsBob . authentication )
123119
124120 //sessions
125121 sessionRequest = requestSession ( aliceFullDid , 'MyApp' )
@@ -128,7 +124,7 @@ describe('Attestation', () => {
128124 sessionRequest ,
129125 bobEncryptCallback ,
130126 bobDecryptCallback ,
131- bobSign ( bobFullDid )
127+ await bobSign ( bobFullDid )
132128 )
133129 bobSession = session
134130
@@ -137,7 +133,7 @@ describe('Attestation', () => {
137133 sessionResponse ,
138134 aliceDecryptCallback ,
139135 aliceEncryptCallback ,
140- aliceSign ( aliceFullDid )
136+ await aliceSign ( aliceFullDid )
141137 )
142138
143139 testCType = CType . fromProperties ( 'testCtype' , {
@@ -148,10 +144,10 @@ describe('Attestation', () => {
148144 name : 'Bob' ,
149145 }
150146
151- claim = Claim . fromCTypeAndClaimContents ( testCType , claimContents , bobFullDid . uri )
147+ claim = Claim . fromCTypeAndClaimContents ( testCType , claimContents , bobFullDid . id )
152148
153149 const quoteData = {
154- attesterDid : aliceFullDid . uri ,
150+ attesterDid : aliceFullDid . id ,
155151 cTypeHash : claim . cTypeHash ,
156152 cost : {
157153 tax : { vat : 3.3 } ,
@@ -163,7 +159,7 @@ describe('Attestation', () => {
163159 timeframe : new Date ( 2023 , 8 , 23 ) . toISOString ( ) ,
164160 }
165161 // Quote signed by attester
166- const quoteAttesterSigned = await Quote . createAttesterSignedQuote ( quoteData , aliceSign ( aliceFullDid ) )
162+ const quoteAttesterSigned = await createAttesterSignedQuote ( quoteData , aliceSession [ 'authenticationSigner' ] )
167163
168164 submitTermsContent = {
169165 claim,
@@ -302,7 +298,7 @@ describe('Attestation', () => {
302298
303299 const txTransfer = api . tx . balances . transfer ( aliceAccount . address , COST )
304300
305- const finalizedTx = await ChainHelpers . Blockchain . signAndSubmitTx ( txTransfer , bobAccount , {
301+ const finalizedTx = await Blockchain . signAndSubmitTx ( txTransfer , bobAccount , {
306302 resolveOn : Blockchain . IS_FINALIZED ,
307303 } )
308304
@@ -334,7 +330,7 @@ describe('Attestation', () => {
334330 delegationId : null ,
335331 claimHash : credential . rootHash ,
336332 cTypeHash : claim . cTypeHash ,
337- owner : bobFullDid . uri ,
333+ owner : bobFullDid . id ,
338334 revoked : false ,
339335 }
340336
@@ -363,7 +359,7 @@ describe('Attestation', () => {
363359 delegationId : null ,
364360 claimHash : credential . rootHash ,
365361 cTypeHash : claim . cTypeHash ,
366- owner : bobFullDid . uri ,
362+ owner : bobFullDid . id ,
367363 revoked : false ,
368364 }
369365
@@ -372,11 +368,11 @@ describe('Attestation', () => {
372368 const requestAttestationMessages = await requestAttestation ( requestTerms . encryptedMessage , credential , bobSession )
373369
374370 // Anchor attestation to the blockchain
375- await createCtype ( aliceFullDid . uri , aliceAccount , aliceMnemonic , testCType )
371+ await createCtype ( aliceFullDid . id , aliceAccount , aliceMnemonic , testCType )
376372 await createAttestation (
377373 aliceAccount ,
378- aliceFullDid . uri ,
379- aliceSignAssertion ( aliceFullDid ) ,
374+ aliceFullDid . id ,
375+ await aliceSignAssertion ( aliceFullDid ) ,
380376 credential . rootHash ,
381377 claim . cTypeHash
382378 )
0 commit comments