From 5c4a7a725807e4f5d2f79423e298ee232818c2be Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 30 Jan 2024 10:13:30 +0100 Subject: [PATCH] Add Autogenerated API docs (#5) * Add Yarn and GitHub workflow config for building docs to GitHub Pages * Add type comments * Address TSDoc warnings * Lint fixes * Revert yarn lock changes --------- Co-authored-by: Antonio Antonino --- .github/workflows/docpublish.yml | 24 +++++++ .gitignore | 4 ++ .yarn/versions/9db34678.yml | 2 + docs/.nojekyll | 0 package.json | 5 +- src/sibling.ts | 42 ++++++------ src/utils.ts | 113 ++++++++++++++++++++----------- tsconfig.docs.json | 22 ++++++ yarn.lock | 88 +++++++++++++++++++++++- 9 files changed, 238 insertions(+), 62 deletions(-) create mode 100644 .github/workflows/docpublish.yml create mode 100644 .yarn/versions/9db34678.yml create mode 100644 docs/.nojekyll create mode 100644 tsconfig.docs.json diff --git a/.github/workflows/docpublish.yml b/.github/workflows/docpublish.yml new file mode 100644 index 0000000..6d075f6 --- /dev/null +++ b/.github/workflows/docpublish.yml @@ -0,0 +1,24 @@ +name: Build and Deploy API docs + +on: + release: + types: [published] + workflow_dispatch: + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install and Build + run: | + yarn install + yarn build:docs + + - name: Deploy + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages # The branch the action should deploy to. + folder: docs/api # The folder the action should deploy to. diff --git a/.gitignore b/.gitignore index c0bba76..bcb4fe5 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,7 @@ cjs # VSCode .vscode + +# doc +**/docs/api +/docs/api \ No newline at end of file diff --git a/.yarn/versions/9db34678.yml b/.yarn/versions/9db34678.yml new file mode 100644 index 0000000..80749ae --- /dev/null +++ b/.yarn/versions/9db34678.yml @@ -0,0 +1,2 @@ +declined: + - "@kiltprotocol/dip-sdk" diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json index 9bc5492..b30f7d3 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "eslint-plugin-license-header": "^0.6.0", "prettier": "^3.0.0", "rimraf": "^5.0.1", - "typescript": "^5.3.2", + "typedoc": "^0.25.7", + "typescript": "^5.1", "vitest": "^0.33.0" }, "engines": { @@ -45,9 +46,11 @@ "scripts": { "build": "yarn build:cjs && yarn build:esm", "build:cjs": "run -T tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json", + "build:docs": "typedoc --theme default --out docs/api --tsconfig tsconfig.docs.json && touch docs/.nojekyll", "build:esm": "run -T tsc -p tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./dist/esm/package.json", "check": "tsc -p tsconfig.json", "clean": "yarn rimraf -g */{cjs,esm}", + "clean:docs": "rimraf docs/api", "lint": "eslint --ext .ts . && prettier -c .", "lint:fix": "prettier -w . && eslint --fix --ext .ts .", "prepublish": "yarn exec cp -f ../../LICENSE .", diff --git a/src/sibling.ts b/src/sibling.ts index 48ce99a..6f4072e 100644 --- a/src/sibling.ts +++ b/src/sibling.ts @@ -29,52 +29,52 @@ import type { import type { KeyringPair } from "@polkadot/keyring/types" import type { Call, Hash } from "@polkadot/types/interfaces" +/** The DIP proof params. */ export type DipSiblingProofInput = { + /** The `Call` on the consumer chain that requires a DIP origin. */ call: Call + /** The `ApiPromise` instance for the consumer chain. */ consumerApi: ApiPromise + /** The DID URI of the DIP subject that is performing the cross-chain operation. */ didUri: DidUri + /** The verification method IDs of the DID to be revealed in the cross-chain operation. */ keyIds: Array + /** The version of the DIP proof to generate. */ proofVersion: number + /** The `ApiPromise` instance for the provider chain. */ providerApi: ApiPromise + /** The `ApiPromise` instance for the parent relay chain. */ relayApi: ApiPromise + /** The signing callback to sign the cross-chain transaction. */ signer: SignExtrinsicCallback + /** The address of the tx submitter on the consumer chain. */ submitterAddress: KeyringPair["address"] + /** The `VerificationKeyRelationship` required for the DIP operation to be authorized on the relay chain. */ keyRelationship: VerificationKeyRelationship - // Optional, retrieved from chain otherwise + /** The block number on the consumer chain to use for the DID signature. If not provided, the latest best block number is used. */ blockHeight?: BN + /** The genesis hash of the consumer chain to use for the DID signature. If not provided, it is retrieved at runtime from the consumer chain. */ genesisHash?: Hash + /** The block number of the provider to use for the generation of the DIP proof. If not provided, the latest finalized block number is used. */ providerBlockHeight?: BN - // With defaults + /** The runtime type definition for an `AccountId` on the consumer chain. If not provided, the `AccountId` type is used. */ accountIdRuntimeType?: string + /** The runtime type definition for a `BlockNumber` on the consumer chain. If not provided, the `u64` type is used. */ blockNumberRuntimeType?: string + /** The runtime type definition for the `IdentityDetails` on the consumer chain. If not provided, the `Option` type, representing a simple nonce, is used. */ identityDetailsRuntimeType?: string + /** Flag indicating whether the generated DIP proof should include the web3name of the DID subject. If not provided, the web3name is not revealed. */ includeWeb3Name?: boolean + /** The list of linked accounts to reveal in the generated DIP proof. If not provided, no account is revealed. */ linkedAccounts?: readonly PalletDidLookupLinkableAccountLinkableAccountId[] } /** * Generate a submittable extrinsic for the provided call which includes a complete DIP proof according to the parameters provided, to be used on a consumer chain of which the provider chain is a sibling. + * * @param params The DIP proof params. - * @param params.call The [[Call]] on the consumer chain that requires a DIP origin. - * @param params.consumerApi The [[ApiPromise]] instance for the consumer chain. - * @param params.didUri The DID URI of the DIP subject that is performing the cross-chain operation. - * @param params.keyIds The verification method IDs of the DID to be revealed in the cross-chain operation. - * @param params.proofVersion The version of the DIP proof to generate. - * @param params.providerApi The [[ApiPromise]] instance for the provider chain. - * @param params.relayApi The [[ApiPromise]] instance for the parent relay chain. - * @param params.signer The signing callback to sign the cross-chain transaction. - * @param params.submitterAddress The address of the tx submitter on the consumer chain. - * @param params.keyRelationship The [[VerificationKeyRelationship]] required for the DIP operation to be authorized on the relay chain. - * @param params.blockHeight [OPTIONAL] The block number on the consumer chain to use for the DID signature. If not provided, the latest best block number is used. - * @param params.genesisHash [OPTIONAL] The genesis hash of the consumer chain to use for the DID signature. If not provided, it is retrieved at runtime from the consumer chain. - * @param params.providerBlockHeight [OPTIONAL] The block number of the provider to use for the generation of the DIP proof. If not provided, the latest finalized block number is used. - * @param params.accountIdRuntimeType [OPTIONAL] The runtime type definition for an `AccountId` on the consumer chain. If not provided, the `AccountId` type is used. - * @param params.blockNumberRuntimeType [OPTIONAL] The runtime type definition for a `BlockNumber` on the consumer chain. If not provided, the `u64` type is used. - * @param params.identityDetailsRuntimeType [OPTIONAL] The runtime type definition for the `IdentityDetails` on the consumer chain. If not provided, the `Option` type, representing a simple nonce, is used. - * @param params.includeWeb3Name [OPTIONAL] Flag indicating whether the generated DIP proof should include the web3name of the DID subject. If not provided, the web3name is not revealed. - * @param params.linkedAccounts [OPTIONAL] The list of linked accounts to reveal in the generated DIP proof. If not provided, no account is revealed. * - * @returns The [[SubmittableExtrinsic]] containing the signed cross-chain operation, that must be submitted by the account specified as the `submitterAddress` parameter. + * @returns The `SubmittableExtrinsic` containing the signed cross-chain operation, that must be submitted by the account specified as the `submitterAddress` parameter. */ export async function generateDipAuthorizedTxForSibling({ call, diff --git a/src/utils.ts b/src/utils.ts index e7b2c7f..af2b270 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -30,24 +30,32 @@ export const defaultValues = { linkedAccounts: [], } -type ProviderStateRootProofOpts = { +/** + * The options object provided when generating a Provider state proof. + */ +export type ProviderStateRootProofOpts = { + /** The `ApiPromise` instance for the provider chain. */ providerApi: ApiPromise + /** The `ApiPromise` instance for the relay chain. */ relayApi: ApiPromise - // Optional + /** The block number on the provider chain to use for the state proof. If not provided, the latest finalized block number is used. */ providerBlockHeight?: BN } -type ProviderStateRootProofRes = { +/** + * The response object containing the provider state root proof. + */ +export type ProviderStateRootProofRes = { + /** The state proof for the provider header. */ proof: ReadProof + /** The block number of the provider which the proof is anchored to. */ providerBlockHeight: BN + /** The block number of the relaychain which the proof is anchored to. */ relayBlockHeight: BN } /** * Generate a state proof that proofs the head of the specified parachain. * * @param params The state proof params. - * @param params.providerApi The [[ApiPromise]] instance for the provider chain. - * @param params.relayApi The [[ApiPromise]] instance for the relay chain. - * @param params.providerBlockHeight [OPTIONAL] The block number on the provider chain to use for the state proof. If not provided, the latest finalized block number is used. * * @returns The generated state proof. */ @@ -92,23 +100,30 @@ export async function generateProviderStateRootProof({ } } -type DipCommitmentProofOpts = { +/** + * The options object provided when generating a DIP commitment proof. + */ +export type DipCommitmentProofOpts = { + /** The `DidUri` of the subject. */ didUri: DidUri + /** The `ApiPromise` instance for the provider chain. */ providerApi: ApiPromise + /** The block hash on the provider chain to use for the state proof. */ providerBlockHash: Hash + /** The version of the identity commitment to generate the state proof for. */ version: number } -type DipCommitmentProofRes = { +/** + * The response object for a DIP commitment proof. + */ +export type DipCommitmentProofRes = { + /** The storage proof for the DIP commitment value. */ proof: ReadProof } /** * Generate a state proof that proofs the value of an identity commitment on the specified provider chain. * * @param params The state proof params. - * @param params.did The [[Did]] of the subject. - * @param params.providerApi The [[ApiPromise]] instance for the provider chain. - * @param params.providerBlockHash The block hash on the provider chain to use for the state proof. - * @param params.version The version of the identity commitment to generate the state proof for. * * @returns The generated state proof. */ @@ -131,31 +146,41 @@ export async function generateDipCommitmentProof({ return { proof } } -type DipIdentityProofOpts = { +/** + * The options object provided when generating a DIP identity proof. + */ +export type DipIdentityProofOpts = { + /** The `Did` of the subject. */ didUri: DidUri + /** The list of DID verification methods to include in the DIP proof and to reveal to the consumer chain. */ keyIds: Array + /** A flag indicating whether the web3name should be included in the DIP proof. */ includeWeb3Name: boolean + /** The list of accounts linked to the DID ot include in the DIP proof and to reveal to the consumer chain. */ linkedAccounts: readonly PalletDidLookupLinkableAccountLinkableAccountId[] + /** The `ApiPromise` instance for the provider chain. */ providerApi: ApiPromise + /** The version of the DIP proof to generate. */ version: number } -type DipIdentityProofRes = { +/** + * The response object for a generated DIP proof. + */ +export type DipIdentityProofRes = { + /** The generated storage proof. */ proof: { + /** The Merkle proof blinded (not revealed) leaves. */ blinded: Codec + /** The Merkle proof revealed leaves. */ revealed: Codec } + /** The Merkle root hash which the proof is anchored to. */ root: Hash } /** * Generate a DIP proof that reveals the specified information about the DID subject. * * @param params The DIP proof params. - * @param params.did The [[Did]] of the subject. - * @param params.keyIds The list of DID verification methods to include in the DIP proof and to reveal to the consumer chain. - * @param params.includeWeb3Name A flag indicating whether the web3name should be included in the DIP proof. - * @param params.linkedAccounts The list of accounts linked to the DID ot include in the DIP proof and to reveal to the consumer chain. - * @param params.providerApi The [[ApiPromise]] instance for the provider chain. - * @param params.version The version of the DIP proof to generate. * * @returns The generated DIP proof. */ @@ -187,27 +212,49 @@ export async function generateDipIdentityProof({ return okProof } -type DipDidSignatureProviderOpts = { +/** + * The Provider options object provided when generating a DIP DID signature. + */ +export type DipDidSignatureProviderOpts = { + /** The `DidUri` of the DIP subject that is performing the cross-chain operation. */ didUri: DidUri + /** The list of `Signers` to use to sign the cross-chain payload. */ signer: SignExtrinsicCallback + /** The `SignatureVerificationRelationship` to use from the provided DID Document to sign the cross-chain payload. */ keyRelationship: VerificationKeyRelationship } -type DipDidSignatureConsumerOpts = { +/** + * The Consumer options object provided when generating a DIP DID signature. + */ +export type DipDidSignatureConsumerOpts = { + /** The runtime definition of an `AccountId`. */ accountIdRuntimeType: string + /** The `ApiPromise` instance. */ api: ApiPromise + /** The runtime definition of a `BlockNumber`. */ blockNumberRuntimeType: string + /** The `Call` to DID-authorize. */ call: Call + /** The runtime definition of the `IdentityDetails`. */ identityDetailsRuntimeType: string + /** The address of the submitter account on the consumer chain. */ submitterAddress: KeyringPair["address"] - // Optional + /** The block number to use for the DID signature. If not provided, the latest best block number is used. */ blockHeight?: BN + /** The genesis hash to use for the DID signature. If not provided, it is retrieved at runtime. */ genesisHash?: Hash } -type DipDidSignatureOpts = { +/** + * The options object provided when generating a DIP DID signature. + */ +export type DipDidSignatureOpts = { consumer: DipDidSignatureConsumerOpts provider: DipDidSignatureProviderOpts } -type DipDidSignatureRes = { +/** + * The response object for DIP DID signature. + */ +export type DipDidSignatureRes = { blockNumber: BN signature: Uint8Array type: VerificationKeyType @@ -215,20 +262,8 @@ type DipDidSignatureRes = { /** * Generate a DID signature to be used in conjunction with a DIP proof to DID-authorize a cross-chain operation. * - * @param params The DID signature parameters. - * @param params.provider The provider-specific parameters. - * @param params.provider.didDocument The [[DidDocument] of the DIP subject that is performing the cross-chain operation. - * @param params.provider.signers The list of [[Signers]] to use to sign the cross-chain payload. - * @param params.provider.verificationRelationship The [[SignatureVerificationRelationship]] to use from the provided DID Document to sign the cross-chain payload. - * @param params.consumer The consumer-specific parameters. - * @param params.consumer.accountIdRuntimeType The runtime definition of an `AccountId`. - * @param params.consumer.api The [[ApiPromise]] instance. - * @param params.consumer.blockNumberRuntimeType The runtime definition of a `BlockNumber`. - * @param params.consumer.call The [[Call]] to DID-authorize. - * @param params.consumer.identityDetailsRuntimeType The runtime definition of the `IdentityDetails`. - * @param params.consumer.submitterAddress The address of the submitter account on the consumer chain. - * @param params.consumer.blockHeight [OPTIONAL] The block number to use for the DID signature. If not provided, the latest best block number is used. - * @param params.consumer.genesisHash [OPTIONAL] The genesis hash to use for the DID signature. If not provided, it is retrieved at runtime. + * @param params The signature generation parameters. + * @returns The generated DIP proof. */ export async function generateDipDidSignature({ diff --git a/tsconfig.docs.json b/tsconfig.docs.json new file mode 100644 index 0000000..a2fbafb --- /dev/null +++ b/tsconfig.docs.json @@ -0,0 +1,22 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*"], + "typedocOptions": { + "entryPointStrategy": "resolve", + "entryPoints": ["src/runtime.ts", "src/sibling.ts", "src/utils.ts"], + "out": "docs/api", + "theme": "default", + "exclude": [ + "**/*spec.ts", + "**/__mocks__/**", + "**/tests/**", + "**/*.js", + "**/node_modules/**" + ], + "excludeExternals": true, + "excludePrivate": true, + "hideGenerator": true, + "name": "API Documentation", + "readme": "README.md" + } +} diff --git a/yarn.lock b/yarn.lock index da92200..d454069 100644 --- a/yarn.lock +++ b/yarn.lock @@ -399,7 +399,8 @@ __metadata: eslint-plugin-license-header: ^0.6.0 prettier: ^3.0.0 rimraf: ^5.0.1 - typescript: ^5.3.2 + typedoc: ^0.25.7 + typescript: ^5.1 vitest: ^0.33.0 languageName: unknown linkType: soft @@ -1516,6 +1517,13 @@ __metadata: languageName: node linkType: hard +"ansi-sequence-parser@npm:^1.1.0": + version: 1.1.1 + resolution: "ansi-sequence-parser@npm:1.1.1" + checksum: ead5b15c596e8e85ca02951a844366c6776769dcc9fd1bd3a0db11bb21364554822c6a439877fb599e7e1ffa0b5f039f1e5501423950457f3dcb2f480c30b188 + languageName: node + linkType: hard + "ansi-styles@npm:^4.0.0, ansi-styles@npm:^4.1.0": version: 4.3.0 resolution: "ansi-styles@npm:4.3.0" @@ -3621,6 +3629,13 @@ __metadata: languageName: node linkType: hard +"lunr@npm:^2.3.9": + version: 2.3.9 + resolution: "lunr@npm:2.3.9" + checksum: 176719e24fcce7d3cf1baccce9dd5633cd8bdc1f41ebe6a180112e5ee99d80373fe2454f5d4624d437e5a8319698ca6837b9950566e15d2cae5f2a543a3db4b8 + languageName: node + linkType: hard + "magic-string@npm:^0.30.1": version: 0.30.5 resolution: "magic-string@npm:0.30.5" @@ -3656,6 +3671,15 @@ __metadata: languageName: node linkType: hard +"marked@npm:^4.3.0": + version: 4.3.0 + resolution: "marked@npm:4.3.0" + bin: + marked: bin/marked.js + checksum: 0db6817893952c3ec710eb9ceafb8468bf5ae38cb0f92b7b083baa13d70b19774674be04db5b817681fa7c5c6a088f61300815e4dd75a59696f4716ad69f6260 + languageName: node + linkType: hard + "merge-stream@npm:^2.0.0": version: 2.0.0 resolution: "merge-stream@npm:2.0.0" @@ -4738,6 +4762,18 @@ __metadata: languageName: node linkType: hard +"shiki@npm:^0.14.7": + version: 0.14.7 + resolution: "shiki@npm:0.14.7" + dependencies: + ansi-sequence-parser: ^1.1.0 + jsonc-parser: ^3.2.0 + vscode-oniguruma: ^1.7.0 + vscode-textmate: ^8.0.0 + checksum: 2aec3b3519df977c4391df9e1825cb496e9a4d7e11395f05a0da77e4fa2f7c3d9d6e6ee94029ac699533017f2b25637ee68f6d39f05f311535c2704d0329b520 + languageName: node + linkType: hard + "side-channel@npm:^1.0.4": version: 1.0.4 resolution: "side-channel@npm:1.0.4" @@ -5286,6 +5322,22 @@ __metadata: languageName: node linkType: hard +"typedoc@npm:^0.25.7": + version: 0.25.7 + resolution: "typedoc@npm:0.25.7" + dependencies: + lunr: ^2.3.9 + marked: ^4.3.0 + minimatch: ^9.0.3 + shiki: ^0.14.7 + peerDependencies: + typescript: 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x + bin: + typedoc: bin/typedoc + checksum: 49c3bf923a3c9401b549e5843f8efaaac8fa28f8ec6bd8617187b5d9ba9932a3fa63dc3863b82389507ffc7d92908af0dce33780fffb4970cd0833274f6fa0cf + languageName: node + linkType: hard + "typescript-logging@npm:^1.0.0": version: 1.0.1 resolution: "typescript-logging@npm:1.0.1" @@ -5295,6 +5347,16 @@ __metadata: languageName: node linkType: hard +"typescript@npm:^5.1": + version: 5.3.3 + resolution: "typescript@npm:5.3.3" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 2007ccb6e51bbbf6fde0a78099efe04dc1c3dfbdff04ca3b6a8bc717991862b39fd6126c0c3ebf2d2d98ac5e960bcaa873826bb2bb241f14277034148f41f6a2 + languageName: node + linkType: hard + "typescript@npm:^5.3.2": version: 5.3.2 resolution: "typescript@npm:5.3.2" @@ -5305,6 +5367,16 @@ __metadata: languageName: node linkType: hard +"typescript@patch:typescript@^5.1#~builtin": + version: 5.3.3 + resolution: "typescript@patch:typescript@npm%3A5.3.3#~builtin::version=5.3.3&hash=14eedb" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: f61375590b3162599f0f0d5b8737877ac0a7bc52761dbb585d67e7b8753a3a4c42d9a554c4cc929f591ffcf3a2b0602f65ae3ce74714fd5652623a816862b610 + languageName: node + linkType: hard + "typescript@patch:typescript@^5.3.2#~builtin": version: 5.3.2 resolution: "typescript@patch:typescript@npm%3A5.3.2#~builtin::version=5.3.2&hash=14eedb" @@ -5540,6 +5612,20 @@ __metadata: languageName: node linkType: hard +"vscode-oniguruma@npm:^1.7.0": + version: 1.7.0 + resolution: "vscode-oniguruma@npm:1.7.0" + checksum: 53519d91d90593e6fb080260892e87d447e9b200c4964d766772b5053f5699066539d92100f77f1302c91e8fc5d9c772fbe40fe4c90f3d411a96d5a9b1e63f42 + languageName: node + linkType: hard + +"vscode-textmate@npm:^8.0.0": + version: 8.0.0 + resolution: "vscode-textmate@npm:8.0.0" + checksum: 127780dfea89559d70b8326df6ec344cfd701312dd7f3f591a718693812b7852c30b6715e3cfc8b3200a4e2515b4c96f0843c0eacc0a3020969b5de262c2a4bb + languageName: node + linkType: hard + "w3c-xmlserializer@npm:^5.0.0": version: 5.0.0 resolution: "w3c-xmlserializer@npm:5.0.0"