Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes
  • Loading branch information
ntn-x2 committed Dec 19, 2023
commit 01bbd1e345ff7959fe9f6829b96ce68bc748375e
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"bugs": "https://github.com/KILTprotocol/dip-sdk/issues",
"description": "An SDK to help integration of the KILT Decentralized Identity Provider (DIP) protocol using KILT as an Identity Provider.",
"dependencies": {
"@kiltprotocol/did": "0.35.0-rc.1",
"@kiltprotocol/types": "0.35.0-rc.1",
"@kiltprotocol/did": "0.34.1-rc.1",
"@kiltprotocol/types": "0.34.1-rc.1",
"@polkadot/api": "^10.10.1",
"@polkadot/util": "^12.5.1"
},
"devDependencies": {
"@kiltprotocol/sdk-js": "0.35.0-rc.1",
"@kiltprotocol/sdk-js": "0.34.1-rc.1",
"@types/node": "^20.9.4",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
Expand Down
7 changes: 4 additions & 3 deletions src/sibling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
SubmittableExtrinsic,
DidKey,
SignExtrinsicCallback,
BN,
} from "@kiltprotocol/types"
import type { KeyringPair } from "@polkadot/keyring/types"
import type { Call, Hash } from "@polkadot/types/interfaces"
Expand All @@ -40,9 +41,9 @@ export type DipSiblingProofInput = {
submitterAddress: KeyringPair["address"]
keyRelationship: VerificationKeyRelationship
// Optional, retrieved from chain otherwise
blockHeight?: number
blockHeight?: BN
genesisHash?: Hash
providerBlockHeight?: number
providerBlockHeight?: BN
// With defaults
accountIdRuntimeType?: string
blockNumberRuntimeType?: string
Expand Down Expand Up @@ -109,7 +110,7 @@ export async function generateDipAuthorizedTxForSibling({

// Proof of commitment must be generated with the state root at the block before the last one finalized.
const dipRootProofBlockHash = await providerApi.rpc.chain.getBlockHash(
providerStateRootProofProviderBlockHeight - 1,
providerStateRootProofProviderBlockHeight.subn(1),
)

const {
Expand Down
17 changes: 9 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
DidKey,
VerificationKeyRelationship,
VerificationKeyType,
BN,
} from "@kiltprotocol/types"
import type { ApiPromise } from "@polkadot/api"
import type { KeyringPair } from "@polkadot/keyring/types"
Expand All @@ -33,12 +34,12 @@ type ProviderStateRootProofOpts = {
providerApi: ApiPromise
relayApi: ApiPromise
// Optional
providerBlockHeight?: number
providerBlockHeight?: BN
}
type ProviderStateRootProofRes = {
proof: ReadProof
providerBlockHeight: number
relayBlockHeight: number
providerBlockHeight: BN
relayBlockHeight: BN
}
/**
* Generate a state proof that proofs the head of the specified parachain.
Expand Down Expand Up @@ -66,7 +67,7 @@ export async function generateProviderStateRootProof({
await providerApi.rpc.chain.getFinalizedHead()
const providerLastFinalizedBlockHeight = await providerApi.rpc.chain
.getHeader(providerLastFinalizedBlockHash)
.then((h) => h.number.toNumber())
.then((h) => h.number.toBn())
return [providerLastFinalizedBlockHeight, providerLastFinalizedBlockHash]
})()
const providerApiAtBlock = await providerApi.at(providerBlockHash)
Expand Down Expand Up @@ -199,15 +200,15 @@ type DipDidSignatureConsumerOpts = {
identityDetailsRuntimeType: string
submitterAddress: KeyringPair["address"]
// Optional
blockHeight?: number
blockHeight?: BN
genesisHash?: Hash
}
type DipDidSignatureOpts = {
consumer: DipDidSignatureConsumerOpts
provider: DipDidSignatureProviderOpts
}
type DipDidSignatureRes = {
blockNumber: number
blockNumber: BN
signature: Uint8Array
type: VerificationKeyType
}
Expand Down Expand Up @@ -244,8 +245,8 @@ export async function generateDipDidSignature({
genesisHash,
},
}: DipDidSignatureOpts): Promise<DipDidSignatureRes> {
const blockNumber: number =
blockHeight ?? (await api.query.system.number<any>()).toNumber()
const blockNumber: BN =
blockHeight ?? (await api.query.system.number<any>()).toBn()
const genesis = genesisHash ?? (await api.query.system.blockHash(0))
const identityDetails = (
await api.query.dipConsumer.identityEntries<Option<Codec>>(toChain(didUri))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RELAY_IMAGE=parity/polkadot:v1.0.0
RELAY_ALICE_RPC=10001
RELAY_ALICE_RPC=20001
PROVIDER_IMAGE=kiltprotocol/dip-provider-node-template:latest-develop
PROVIDER_ALICE_RPC=10011
PROVIDER_ALICE_RPC=20011
CONSUMER_IMAGE=kiltprotocol/dip-consumer-node-template:latest-develop
CONSUMER_ALICE_RPC=10021
CONSUMER_ALICE_RPC=20021
24 changes: 12 additions & 12 deletions tests/dip-provider-template-dip-consumer-template/develop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ import { setTimeout } from "timers/promises"

import * as Kilt from "@kiltprotocol/sdk-js"
import { ApiPromise, WsProvider } from "@polkadot/api"
import { BN } from "@polkadot/util"
import { blake2AsHex } from "@polkadot/util-crypto"
import { BN } from "bn.js"
import dotenv from "dotenv"
import { beforeAll, describe, it, expect } from "vitest"

import {
createProviderApi,
signAndSubmitTx,
withCrossModuleSystemImport,
} from "../utils.js"

import type { GetStoreTxSignCallback, Web3Name } from "@kiltprotocol/did"
import type { DipSiblingProofInput } from "@kiltprotocol/dip-sdk"
import type {
Expand All @@ -31,6 +25,12 @@ import type { Option } from "@polkadot/types/codec"
import type { Call } from "@polkadot/types/interfaces"
import type { Codec } from "@polkadot/types/types"

import {
createProviderApi,
signAndSubmitTx,
withCrossModuleSystemImport,
} from "../utils.js"

dotenv.config({ path: "tests/dip-provider-template-dip-consumer-template/.env.develop.test" })

const baseConfig: Pick<
Expand All @@ -40,7 +40,7 @@ const baseConfig: Pick<
| "identityDetailsRuntimeType"
> = {
accountIdRuntimeType: "AccountId32",
blockNumberRuntimeType: "u32",
blockNumberRuntimeType: "u64",
identityDetailsRuntimeType: "Option<u128>",
}
const web3NameRuntimeType = "Text"
Expand Down Expand Up @@ -87,7 +87,7 @@ describe("V0", () => {
let did: DidDocument
let web3Name: Web3Name
let didKeypair: Kilt.KeyringPair
let lastTestSetupProviderBlockNumber: number
let lastTestSetupProviderBlockNumber: BN
let testConfig: typeof v0Config &
Pick<
DipSiblingProofInput,
Expand Down Expand Up @@ -170,7 +170,7 @@ describe("V0", () => {
await setTimeout(12_000)
lastTestSetupProviderBlockNumber = (
await providerApi.query.system.number()
).toNumber()
).toBn()
const newFullDid = (await Kilt.Did.resolve(newFullDidUri))
?.document as DidDocument
submitterKeypair = newSubmitterKeypair
Expand Down Expand Up @@ -220,7 +220,7 @@ describe("V0", () => {
// The example PostIt pallet generates the storage key for a post by hashing (block number, submitter's username, content of the post).
const postKey = blake2AsHex(
consumerApi
.createType(`(BlockNumber, ${web3NameRuntimeType}, Bytes)`, [
.createType(`(${config.blockNumberRuntimeType as string}, ${web3NameRuntimeType}, Bytes)`, [
blockNumber,
web3Name,
postText,
Expand Down Expand Up @@ -262,7 +262,7 @@ describe("V0", () => {
// The example PostIt pallet generates the storage key for a post by hashing (block number, submitter's username, content of the post).
const postKey = blake2AsHex(
consumerApi
.createType(`(BlockNumber, ${web3NameRuntimeType}, Bytes)`, [
.createType(`(${config.blockNumberRuntimeType as string}, ${web3NameRuntimeType}, Bytes)`, [
blockNumber,
web3Name,
postText,
Expand Down
28 changes: 11 additions & 17 deletions tests/peregrine-dip-consumer-template/develop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ import { setTimeout } from "timers/promises"

import * as Kilt from "@kiltprotocol/sdk-js"
import { ApiPromise, WsProvider } from "@polkadot/api"
import { BN } from "@polkadot/util"
import { blake2AsHex } from "@polkadot/util-crypto"
import { BN } from "bn.js"
import dotenv from "dotenv"
import { beforeAll, describe, it, expect } from "vitest"

import {
signAndSubmitTx,
withCrossModuleSystemImport,
} from "../utils.js"

import type { GetStoreTxSignCallback, Web3Name } from "@kiltprotocol/did"
import type { DipSiblingProofInput } from "@kiltprotocol/dip-sdk"
import type {
Expand All @@ -30,6 +25,11 @@ import type { Option } from "@polkadot/types/codec"
import type { Call } from "@polkadot/types/interfaces"
import type { Codec } from "@polkadot/types/types"

import {
signAndSubmitTx,
withCrossModuleSystemImport,
} from "../utils.js"

dotenv.config({ path: "tests/peregrine-dip-consumer-template/.env.develop.test" })

const baseConfig: Pick<
Expand All @@ -39,7 +39,7 @@ const baseConfig: Pick<
| "identityDetailsRuntimeType"
> = {
accountIdRuntimeType: "AccountId32",
blockNumberRuntimeType: "u32",
blockNumberRuntimeType: "u64",
identityDetailsRuntimeType: "Option<u128>",
}
const web3NameRuntimeType = "Text"
Expand Down Expand Up @@ -86,7 +86,7 @@ describe("V0", () => {
let did: DidDocument
let web3Name: Web3Name
let didKeypair: Kilt.KeyringPair
let lastTestSetupProviderBlockNumber: number
let lastTestSetupProviderBlockNumber: BN
let testConfig: typeof v0Config &
Pick<
DipSiblingProofInput,
Expand All @@ -113,7 +113,6 @@ describe("V0", () => {
newSubmitterKeypair.address,
`1${consumerUnit}`
)
console.log('Before')
await Promise.all([
Kilt.Blockchain.signAndSubmitTx(
balanceTransferTxOnProviderChain,
Expand All @@ -123,7 +122,6 @@ describe("V0", () => {
providerAndConsumerSudoKeypair,
),
])
console.log('After')
const newDidKeypair = keyring.addFromMnemonic(
Kilt.Utils.Crypto.mnemonicGenerate(),
)
Expand All @@ -142,15 +140,13 @@ describe("V0", () => {
signCallback,
)
const newWeb3Name = Kilt.Utils.UUID.generate().substring(2, 25)
console.log('AAAAA')
const web3NameTx = await Kilt.Did.authorizeTx(
newFullDidUri,
providerApi.tx.web3Names.claim(newWeb3Name),
signCallback,
newSubmitterKeypair.address as KiltAddress,
{ txCounter: new BN(1) },
)
console.log('BBBBB')
const commitIdentityTx = await Kilt.Did.authorizeTx(
newFullDidUri,
providerApi.tx.dipProvider.commitIdentity(
Expand All @@ -161,7 +157,6 @@ describe("V0", () => {
newSubmitterKeypair.address as KiltAddress,
{ txCounter: new BN(2) },
)
console.log('CCCCC')
const batchedTx = providerApi.tx.utility.batchAll([
didCreationTx,
web3NameTx,
Expand All @@ -170,12 +165,11 @@ describe("V0", () => {
await Kilt.Blockchain.signAndSubmitTx(batchedTx, newSubmitterKeypair, {
resolveOn: Kilt.Blockchain.IS_FINALIZED,
})
console.log('DDDDD')
// FIXME: Timeout needed since it seems `.getFinalizedHead()` still returns the previous block number as the latest finalized, even if we wait for finalization above. This results in invalid storage proofs.
await setTimeout(12_000)
lastTestSetupProviderBlockNumber = (
await providerApi.query.system.number()
).toNumber()
).toBn()
const newFullDid = (await Kilt.Did.resolve(newFullDidUri))
?.document as DidDocument
submitterKeypair = newSubmitterKeypair
Expand Down Expand Up @@ -225,7 +219,7 @@ describe("V0", () => {
// The example PostIt pallet generates the storage key for a post by hashing (block number, submitter's username, content of the post).
const postKey = blake2AsHex(
consumerApi
.createType(`(BlockNumber, ${web3NameRuntimeType}, Bytes)`, [
.createType(`(${config.blockNumberRuntimeType as string}, ${web3NameRuntimeType}, Bytes)`, [
blockNumber,
web3Name,
postText,
Expand Down Expand Up @@ -267,7 +261,7 @@ describe("V0", () => {
// The example PostIt pallet generates the storage key for a post by hashing (block number, submitter's username, content of the post).
const postKey = blake2AsHex(
consumerApi
.createType(`(BlockNumber, ${web3NameRuntimeType}, Bytes)`, [
.createType(`(${config.blockNumberRuntimeType as string}, ${web3NameRuntimeType}, Bytes)`, [
blockNumber,
web3Name,
postText,
Expand Down
Loading