Skip to content

Commit

Permalink
Fix up stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ntn-x2 committed Apr 30, 2024
1 parent 62dd07e commit 9b4d99c
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 28 deletions.
2 changes: 2 additions & 0 deletions src/dipProof/extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions src/dipProof/extensions/timeBoundDidSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { toChain } from "@kiltprotocol/did"
import { BN } from "@polkadot/util"
import { BN, u8aToHex } from "@polkadot/util"

import type {
DidUri,
Expand Down Expand Up @@ -127,7 +127,7 @@ export async function generateTimeBoundDipDidSignature({
export function signatureToCodec(signature: TimeBoundDidSignatureRes): Record<string, Codec> {
const encodedSignature = {
signature: {
[signature.type]: signature.signature
[signature.type]: u8aToHex(signature.signature)
},
validUntil: signature.validUntil
} as any as Codec
Expand Down
8 changes: 8 additions & 0 deletions src/dipProof/extensions/types.ts
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 2 additions & 0 deletions src/dipProof/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
9 changes: 9 additions & 0 deletions src/dipProof/types.ts
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 10 additions & 3 deletions src/sibling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -118,7 +117,7 @@ export async function generateDipSiblingBaseProof({
}

export type GenerateDipSubmittableExtrinsicInput = {
additionalProofElements: Record<string, Codec>,
additionalProofElements: Record<any, any>,
api: ApiPromise,
baseDipProof: DipSiblingBaseProofRes,
call: Call
Expand All @@ -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
}
},
Expand Down
2 changes: 2 additions & 0 deletions src/stateProof/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
9 changes: 9 additions & 0 deletions src/stateProof/types.ts
Original file line number Diff line number Diff line change
@@ -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'
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -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'
50 changes: 27 additions & 23 deletions tests/peregrine-dip-consumer-template/develop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -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([
Expand Down Expand Up @@ -94,7 +91,7 @@ describe("V0", () => {
| "keyIds"
| "includeWeb3Name"
| "linkedAccounts"
> & Pick<dipProof.extensions.TimeBoundDidSignatureProviderOpts, 'signer' | 'keyRelationship'> & Pick<dipProof.extensions.TimeBoundDidSignatureConsumerOpts, 'submitterAddress'>
> & Pick<TimeBoundDidSignatureProviderOpts, 'signer' | 'keyRelationship'> & Pick<TimeBoundDidSignatureConsumerOpts, 'submitterAddress'>

beforeAll(async () => {
const { providerApi, consumerApi } = v0Config
Expand Down Expand Up @@ -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(
Expand All @@ -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],
)
Expand All @@ -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(
Expand All @@ -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],
)
Expand Down

0 comments on commit 9b4d99c

Please sign in to comment.