diff --git a/src/dipProof/extensions/index.ts b/src/dipProof/extensions/index.ts index 842d719..d6e945f 100644 --- a/src/dipProof/extensions/index.ts +++ b/src/dipProof/extensions/index.ts @@ -5,4 +5,6 @@ * found in the LICENSE file in the root directory of this source tree. */ +export type * from './types.js' + export * from './timeBoundDidSignature.js' diff --git a/src/dipProof/extensions/timeBoundDidSignature.ts b/src/dipProof/extensions/timeBoundDidSignature.ts index 30cdb75..4d82fa2 100644 --- a/src/dipProof/extensions/timeBoundDidSignature.ts +++ b/src/dipProof/extensions/timeBoundDidSignature.ts @@ -6,7 +6,7 @@ */ import { toChain } from "@kiltprotocol/did" -import { BN } from "@polkadot/util" +import { BN, u8aToHex } from "@polkadot/util" import type { DidUri, @@ -127,7 +127,7 @@ export async function generateTimeBoundDipDidSignature({ export function signatureToCodec(signature: TimeBoundDidSignatureRes): Record { const encodedSignature = { signature: { - [signature.type]: signature.signature + [signature.type]: u8aToHex(signature.signature) }, validUntil: signature.validUntil } as any as Codec diff --git a/src/dipProof/extensions/types.ts b/src/dipProof/extensions/types.ts new file mode 100644 index 0000000..b538829 --- /dev/null +++ b/src/dipProof/extensions/types.ts @@ -0,0 +1,8 @@ +/** + * Copyright (c) 2024, BOTLabs GmbH. + * + * This source code is licensed under the BSD 4-Clause "Original" license + * found in the LICENSE file in the root directory of this source tree. + */ + +export type * from './timeBoundDidSignature.js' diff --git a/src/dipProof/index.ts b/src/dipProof/index.ts index 04ceb6a..369309e 100644 --- a/src/dipProof/index.ts +++ b/src/dipProof/index.ts @@ -5,5 +5,7 @@ * found in the LICENSE file in the root directory of this source tree. */ +export type * from './types.js' + export * from './subjectIdentity.js' export * as extensions from './extensions/index.js' diff --git a/src/dipProof/types.ts b/src/dipProof/types.ts new file mode 100644 index 0000000..41b7d9e --- /dev/null +++ b/src/dipProof/types.ts @@ -0,0 +1,9 @@ +/** + * Copyright (c) 2024, BOTLabs GmbH. + * + * This source code is licensed under the BSD 4-Clause "Original" license + * found in the LICENSE file in the root directory of this source tree. + */ + +export type * from './subjectIdentity.js' +export type * from './extensions/types.js' diff --git a/src/index.ts b/src/index.ts index 5ec13bc..0c85294 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,8 @@ * @module @kiltprotocol/dip-sdk */ +export type * from './types.js' + export * as stateProof from './stateProof/index.js' export * as dipProof from './dipProof/index.js' export * from "./sibling.js" diff --git a/src/sibling.ts b/src/sibling.ts index 0933050..ec4f8d6 100644 --- a/src/sibling.ts +++ b/src/sibling.ts @@ -23,7 +23,6 @@ import type { SubmittableExtrinsic, } from "@kiltprotocol/types" import type { Call } from "@polkadot/types/interfaces" -import type { Codec } from "@polkadot/types-codec/types" const defaultValues = { includeWeb3Name: async () => false, @@ -118,7 +117,7 @@ export async function generateDipSiblingBaseProof({ } export type GenerateDipSubmittableExtrinsicInput = { - additionalProofElements: Record, + additionalProofElements: Record, api: ApiPromise, baseDipProof: DipSiblingBaseProofRes, call: Call @@ -132,7 +131,15 @@ export function generateDipSubmittableExtrinsic({ additionalProofElements, api, toChain(didUri), { [`V${proofVersion}`]: { - ...dipProof, + providerHeadProof: { + relayBlockNumber: dipProof.providerHeadProof.relayBlockHeight, + proof: dipProof.providerHeadProof.proof.proof + }, + dipCommitmentProof: dipProof.dipCommitmentProof.proof.proof, + dipProof: { + blinded: dipProof.dipProof.proof.blinded, + revealed: dipProof.dipProof.proof.revealed + }, ...additionalProofElements } }, diff --git a/src/stateProof/index.ts b/src/stateProof/index.ts index 4a5a580..2426607 100644 --- a/src/stateProof/index.ts +++ b/src/stateProof/index.ts @@ -5,5 +5,7 @@ * found in the LICENSE file in the root directory of this source tree. */ +export type * from './types.js' + export * from './providerStateRoot.js' export * from './subjectDipCommitment.js' diff --git a/src/stateProof/types.ts b/src/stateProof/types.ts new file mode 100644 index 0000000..b0b6623 --- /dev/null +++ b/src/stateProof/types.ts @@ -0,0 +1,9 @@ +/** + * Copyright (c) 2024, BOTLabs GmbH. + * + * This source code is licensed under the BSD 4-Clause "Original" license + * found in the LICENSE file in the root directory of this source tree. + */ + +export type * from './providerStateRoot.js' +export type * from './subjectDipCommitment.js' diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..7db1331 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,10 @@ +/** + * Copyright (c) 2024, BOTLabs GmbH. + * + * This source code is licensed under the BSD 4-Clause "Original" license + * found in the LICENSE file in the root directory of this source tree. + */ + +export type * from './stateProof/index.js' +export type * from './dipProof/index.js' +export type * from './sibling.js' diff --git a/tests/peregrine-dip-consumer-template/develop.test.ts b/tests/peregrine-dip-consumer-template/develop.test.ts index 154c138..65075b6 100644 --- a/tests/peregrine-dip-consumer-template/develop.test.ts +++ b/tests/peregrine-dip-consumer-template/develop.test.ts @@ -13,10 +13,9 @@ import { BN } from "@polkadot/util" import { blake2AsHex } from "@polkadot/util-crypto" import dotenv from "dotenv" import { beforeAll, describe, it, expect } from "vitest" -import { dipProof, generateDipSiblingBaseProof } from '@kiltprotocol/dip-sdk' import type { GetStoreTxSignCallback, Web3Name } from "@kiltprotocol/did" -import type { DipSiblingBaseProofInput } from "@kiltprotocol/dip-sdk" +import type { DipSiblingBaseProofInput, TimeBoundDidSignatureConsumerOpts, TimeBoundDidSignatureOpts, TimeBoundDidSignatureProviderOpts } from "@kiltprotocol/dip-sdk" import type { DidDocument, KiltAddress, @@ -29,14 +28,12 @@ import type { Codec } from "@polkadot/types/types" import { signAndSubmitTx, withCrossModuleSystemImport } from "../utils.js" dotenv.config({ - path: "tests/peregrine-dip-consumer-template/.env.develop.test", + path: "tests/peregrine-dip-consumer-template/.env.develop.test" }) const baseConfig: Pick< - DipSiblingBaseProofInput, - | "accountIdRuntimeType" - | "blockNumberRuntimeType" - | "identityDetailsRuntimeType" + TimeBoundDidSignatureConsumerOpts, + "accountIdRuntimeType" | "blockNumberRuntimeType" | "identityDetailsRuntimeType" > = { accountIdRuntimeType: "AccountId32", blockNumberRuntimeType: "u64", @@ -61,7 +58,7 @@ describe("V0", () => { Pick< DipSiblingBaseProofInput, "proofVersion" | "providerApi" | "relayApi" - > & { "consumerApi": dipProof.extensions.TimeBoundDidSignatureConsumerOpts['api'] } + > & { "consumerApi": TimeBoundDidSignatureConsumerOpts['api'] } beforeAll(async () => { const [relayApi, providerApi, consumerApi] = await Promise.all([ @@ -94,7 +91,7 @@ describe("V0", () => { | "keyIds" | "includeWeb3Name" | "linkedAccounts" - > & Pick & Pick + > & Pick & Pick beforeAll(async () => { const { providerApi, consumerApi } = v0Config @@ -286,18 +283,20 @@ describe("V0", () => { it("Successful posts on the consumer's PostIt pallet using by default the latest provider finalized block", async () => { const { consumerApi } = testConfig const postText = "Hello, world!" - const baseDipProof = generateDipSiblingBaseProof(testConfig) - const crossChainDidSignature = dipProof.extensions.generateTimeBoundDipDidSignature(testConfig) - const config: DipSiblingProofInput = { + const call = consumerApi.tx.postIt.post(postText).method as Call + const config: DipSiblingBaseProofInput & TimeBoundDidSignatureOpts = { ...testConfig, - call: consumerApi.tx.postIt.post(postText).method as Call, + provider: testConfig, + consumer: { ...testConfig, api: consumerApi, call } } + const baseDipProof = await DipSdk.generateDipSiblingBaseProof(config) + const crossChainDidSignature = await DipSdk.dipProof.extensions.generateTimeBoundDipDidSignature(config) + + const dipSubmittable = DipSdk.generateDipSubmittableExtrinsic({ additionalProofElements: crossChainDidSignature, api: consumerApi, baseDipProof, call, didUri: did.uri }) - const crossChainTx = - await DipSdk.generateDipAuthorizedTxForSibling(config) const { status } = await signAndSubmitTx( consumerApi, - crossChainTx, + dipSubmittable, submitterKeypair, ) expect( @@ -311,7 +310,7 @@ describe("V0", () => { const postKey = blake2AsHex( consumerApi .createType( - `(${config.blockNumberRuntimeType as string + `(${config.consumer.blockNumberRuntimeType as string }, ${web3NameRuntimeType}, Bytes)`, [blockNumber, web3Name, postText], ) @@ -328,18 +327,23 @@ describe("V0", () => { it("Successful posts on the consumer's PostIt pallet using the same block as before", async () => { const { consumerApi } = testConfig const postText = "Hello, world!" - const config: DipSiblingProofInput = { + const call = consumerApi.tx.postIt.post(postText).method as Call + const config: DipSiblingBaseProofInput & TimeBoundDidSignatureOpts = { ...testConfig, - call: consumerApi.tx.postIt.post(postText).method as Call, // Set explicit block number for the DIP proof providerBlockHeight: lastTestSetupProviderBlockNumber, + provider: testConfig, + consumer: { ...testConfig, api: consumerApi, call, } } - const crossChainTx = - await DipSdk.generateDipAuthorizedTxForSibling(config) + const baseDipProof = await DipSdk.generateDipSiblingBaseProof(config) + const crossChainDidSignature = await DipSdk.dipProof.extensions.generateTimeBoundDipDidSignature(config) + + const dipSubmittable = DipSdk.generateDipSubmittableExtrinsic({ additionalProofElements: crossChainDidSignature, api: consumerApi, baseDipProof, call, didUri: did.uri }) + const { status } = await signAndSubmitTx( consumerApi, - crossChainTx, + dipSubmittable, submitterKeypair, ) expect( @@ -353,7 +357,7 @@ describe("V0", () => { const postKey = blake2AsHex( consumerApi .createType( - `(${config.blockNumberRuntimeType as string + `(${config.consumer.blockNumberRuntimeType as string }, ${web3NameRuntimeType}, Bytes)`, [blockNumber, web3Name, postText], )