Skip to content

Commit

Permalink
Merge branch 'main' into separate-code-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenbf committed Sep 11, 2023
2 parents 5c563b7 + c8e5030 commit d810305
Show file tree
Hide file tree
Showing 66 changed files with 4,660 additions and 483 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
tsconfigRootDir: __dirname,
project: [
'./packages/**/tsconfig.json',
'./packages/**/tsconfig.eslint.json',
'./tsconfig.eslint.json',
'./examples/tsconfig.eslint.json',
],
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
./packages/nodejs/lib
./packages/common/grpc
./packages/nodejs/grpc
./packages/ccd-js-gen/lib
typecheck-examples:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -158,6 +159,7 @@ jobs:

lint:
runs-on: ubuntu-22.04
needs: build
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v3
Expand All @@ -167,6 +169,11 @@ jobs:
node-version: ${{ env.NODE_VERSION }}
cache: yarn

- name: Get build-debug
uses: ./.github/actions/download-artifact
with:
name: build-debug

- name: Install dependencies
run: yarn install --immutable

Expand Down
2 changes: 1 addition & 1 deletion deps/concordium-base
Submodule concordium-base updated 95 files
+0 −2 README.md
+4 −1 concordium-base.cabal
+1 −1 concordium-contracts-common
+1 −1 concordium-grpc-api
+0 −7 haskell-bins/genesis/README.md
+87 −0 haskell-src/Concordium/GRPC2.hs
+2 −4 haskell-src/Concordium/Genesis/Data/P6.hs
+9 −0 haskell-src/Concordium/Types/Accounts.hs
+65 −1 haskell-src/Concordium/Types/Queries.hs
+135 −0 haskell-src/Concordium/Types/Queries/KonsensusV1.hs
+86 −0 haskell-src/Concordium/Utils/InterpolationSearch.hs
+181 −0 haskell-tests/ConcordiumTests/Utils/InterpolationSearch.hs
+5 −5 identity-provider-service/Cargo.lock
+5 −5 idiss/Cargo.lock
+1 −1 idiss/Cargo.toml
+6 −6 mobile_wallet/Cargo.lock
+2 −2 mobile_wallet/Cargo.toml
+16 −10 mobile_wallet/src/lib.rs
+4 −0 rust-bins/CHANGELOG.md
+7 −7 rust-bins/Cargo.lock
+1 −1 rust-bins/Cargo.toml
+0 −115 rust-bins/data-generation-notes.md
+5 −5 rust-bins/docs/identity-provider-cli.md
+3 −3 rust-bins/docs/user-cli.md
+3 −3 rust-bins/src/bin/client.rs
+5 −5 rust-bins/src/bin/generate_testdata.rs
+0 −438 rust-bins/src/bin/genesis_tool.rs
+3 −7 rust-bins/src/bin/user_cli.rs
+306 −269 rust-src/Cargo.lock
+26 −0 rust-src/concordium_base/CHANGELOG.md
+3 −3 rust-src/concordium_base/Cargo.toml
+5 −5 rust-src/concordium_base/benches/aggr_dlog_commit_message.rs
+13 −3 rust-src/concordium_base/benches/bulletproofs.rs
+2 −2 rust-src/concordium_base/benches/compute_message.rs
+16 −2 rust-src/concordium_base/benches/set_proof_bench.rs
+2 −2 rust-src/concordium_base/benches/verify_cdi.rs
+1 −1 rust-src/concordium_base/src/aggregate_sig/ffi.rs
+2 −2 rust-src/concordium_base/src/aggregate_sig/mod.rs
+2 −38 rust-src/concordium_base/src/base.rs
+256 −11 rust-src/concordium_base/src/bulletproofs/range_proof.rs
+250 −35 rust-src/concordium_base/src/bulletproofs/set_membership_proof.rs
+246 −36 rust-src/concordium_base/src/bulletproofs/set_non_membership_proof.rs
+20 −18 rust-src/concordium_base/src/cis4_types.rs
+27 −1 rust-src/concordium_base/src/common/impls.rs
+47 −0 rust-src/concordium_base/src/common/serialize.rs
+18 −5 rust-src/concordium_base/src/common/types.rs
+2 −7 rust-src/concordium_base/src/constants.rs
+2 −74 rust-src/concordium_base/src/curve_arithmetic/bls12_381_instance.rs
+2 −11 rust-src/concordium_base/src/curve_arithmetic/mod.rs
+14 −7 rust-src/concordium_base/src/eddsa_ed25519/dlog_ed25519.rs
+9 −5 rust-src/concordium_base/src/encrypted_transfers/proofs/generate_proofs.rs
+0 −7 rust-src/concordium_base/src/encrypted_transfers/proofs/mod.rs
+3 −4 rust-src/concordium_base/src/encrypted_transfers/types.rs
+25 −28 rust-src/concordium_base/src/id/account_holder.rs
+27 −28 rust-src/concordium_base/src/id/chain.rs
+2 −2 rust-src/concordium_base/src/id/ffi.rs
+9 −2 rust-src/concordium_base/src/id/id_proof_types.rs
+65 −42 rust-src/concordium_base/src/id/id_prover.rs
+217 −44 rust-src/concordium_base/src/id/id_verifier.rs
+47 −41 rust-src/concordium_base/src/id/identity_provider.rs
+0 −1 rust-src/concordium_base/src/id/mod.rs
+3 −3 rust-src/concordium_base/src/id/test.rs
+153 −119 rust-src/concordium_base/src/id/types.rs
+5 −2 rust-src/concordium_base/src/id/utils.rs
+1 −0 rust-src/concordium_base/src/lib.rs
+31 −30 rust-src/concordium_base/src/sigma_protocols/aggregate_dlog.rs
+26 −24 rust-src/concordium_base/src/sigma_protocols/com_enc_eq.rs
+25 −23 rust-src/concordium_base/src/sigma_protocols/com_eq.rs
+25 −25 rust-src/concordium_base/src/sigma_protocols/com_eq_different_groups.rs
+45 −45 rust-src/concordium_base/src/sigma_protocols/com_eq_sig.rs
+189 −0 rust-src/concordium_base/src/sigma_protocols/com_ineq.rs
+18 −15 rust-src/concordium_base/src/sigma_protocols/com_lin.rs
+22 −21 rust-src/concordium_base/src/sigma_protocols/com_mult.rs
+85 −75 rust-src/concordium_base/src/sigma_protocols/common.rs
+29 −28 rust-src/concordium_base/src/sigma_protocols/dlog.rs
+29 −29 rust-src/concordium_base/src/sigma_protocols/dlogaggequal.rs
+12 −12 rust-src/concordium_base/src/sigma_protocols/dlogeq.rs
+64 −63 rust-src/concordium_base/src/sigma_protocols/enc_trans.rs
+7 −0 rust-src/concordium_base/src/sigma_protocols/mod.rs
+1 −1 rust-src/concordium_base/src/sigma_protocols/sigma_test.rs
+20 −19 rust-src/concordium_base/src/sigma_protocols/vcom_eq.rs
+77 −8 rust-src/concordium_base/src/transactions.rs
+35 −1 rust-src/concordium_base/src/web3id/did.rs
+749 −336 rust-src/concordium_base/src/web3id/mod.rs
+1 −1 rust-src/concordium_base_derive/Cargo.toml
+9 −5 rust-src/concordium_base_derive/src/lib.rs
+1 −1 rust-src/key_derivation/Cargo.toml
+82 −41 rust-src/key_derivation/src/lib.rs
+2 −1 smart-contracts/wasm-chain-integration/CHANGELOG.md
+122 −108 smart-contracts/wasm-chain-integration/Cargo.lock
+5 −5 smart-contracts/wasm-chain-integration/Cargo.toml
+3 −2 smart-contracts/wasm-chain-integration/src/constants.rs
+43 −31 smart-contracts/wasm-test/Cargo.lock
+2 −0 smart-contracts/wasm-transform/CHANGELOG.md
+3 −3 smart-contracts/wasm-transform/Cargo.toml
77 changes: 77 additions & 0 deletions examples/ccd-js-gen/wCCD/client-tokenMetadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { credentials } from '@grpc/grpc-js';
import * as SDK from '@concordium/node-sdk';
import meow from 'meow';
import { parseEndpoint } from '../../shared/util';

// The generated module could be imported directly like below,
// but for this example it is imported dynamicly to improve
// the error message when not generated.
// import * as wCCDModule from './lib/wCCD';

const cli = meow(
`
This example uses a generated smart contract client for the wCCD smart contract.
Usage
$ yarn run-example <path-to-this-file> [options]
Required
--index, -i The index of the smart contract. Defaults to 2059, which is wCCD on testnet.
Options
--help, -h Displays this message
--endpoint, -e Specify endpoint of a grpc2 interface of a Concordium node in the format "<scheme>://<address>:<port>". Defaults to 'http://localhost:20000'
--subindex, The subindex of the smart contract. Defaults to 0
`,
{
importMeta: import.meta,
flags: {
endpoint: {
type: 'string',
alias: 'e',
default: 'http://localhost:20000',
},
index: {
type: 'number',
alias: 'i',
default: 2059,
},
subindex: {
type: 'number',
default: 0,
},
},
}
);

const [address, port, scheme] = parseEndpoint(cli.flags.endpoint);
const grpcClient = SDK.createConcordiumClient(
address,
Number(port),
scheme === 'https' ? credentials.createSsl() : credentials.createInsecure()
);

const contractAddress: SDK.ContractAddress = {
index: BigInt(cli.flags.index),
subindex: BigInt(cli.flags.subindex),
};

(async () => {
// Importing the generated smart contract module client.
/* eslint-disable import/no-unresolved */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const wCCDModule = await import('./lib/wCCD').catch((e) => {
/* eslint-enable import/no-unresolved */
console.error(
'\nFailed to load the generated wCCD module, did you run the `generate` script?\n'
);
throw e;
});

const parameter = '010000'; // First 2 bytes for number of tokens to query, 1 byte for the token ID.
const contract = new wCCDModule.Cis2WCCD(grpcClient, contractAddress);

const responseHex = await contract.dryRun.tokenMetadata(parameter);
console.log({ responseHex });
})();
72 changes: 72 additions & 0 deletions examples/ccd-js-gen/wCCD/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { credentials } from '@grpc/grpc-js';
import * as SDK from '@concordium/node-sdk';
import * as Gen from '@concordium/ccd-js-gen';
import * as Path from 'node:path';
import * as Url from 'node:url';
import meow from 'meow';
import { parseEndpoint } from '../../shared/util';

const cli = meow(
`
This example fetches the wCCD smart contract module source from the chain and generates a typescript client for interacting with such a smart contract.
Usage
$ yarn run-example <path-to-this-file> [options]
Required
--index, -i The index of the smart contract. Defaults to 2059, which is wCCD on Testnet.
Options
--help, -h Displays this message
--endpoint, -e Specify endpoint of a grpc2 interface of a Concordium node in the format "address:port". Defaults to 'localhost:20000'
--subindex, The subindex of the smart contract. Defaults to 0
`,
{
importMeta: import.meta,
flags: {
endpoint: {
type: 'string',
alias: 'e',
default: 'localhost:20000',
},
index: {
type: 'number',
alias: 'i',
isRequired: true,
default: 2059,
},
subindex: {
type: 'number',
default: 0,
},
},
}
);

const [address, port] = parseEndpoint(cli.flags.endpoint);
const grpcClient = SDK.createConcordiumClient(
address,
Number(port),
credentials.createInsecure()
);

const contractAddress: SDK.ContractAddress = {
index: BigInt(cli.flags.index),
subindex: BigInt(cli.flags.subindex),
};

(async () => {
console.info(`Fetching instance information for ${contractAddress.index}.`);
const info = await grpcClient.getInstanceInfo(contractAddress);
console.info(
`Fetching smart contract module source with reference '${info.sourceModule.moduleRef}'.`
);
const moduleSource = await grpcClient.getModuleSource(info.sourceModule);
const filePath = Url.fileURLToPath(import.meta.url);
const outDir = Path.join(Path.dirname(filePath), 'lib');
console.info(`Generating smart contract module client at '${outDir}'.`);
await Gen.generateContractClients(moduleSource, 'wCCD', outDir, {
output: 'TypeScript',
});
console.info('Code generation was successful.');
})();
49 changes: 49 additions & 0 deletions examples/client/healthCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { parseEndpoint } from '../shared/util';
import { createConcordiumClient } from '@concordium/node-sdk';
import { credentials } from '@grpc/grpc-js';

import meow from 'meow';

const cli = meow(
`
Usage
$ yarn run-example <path-to-this-file> [options]
Options
--help, Displays this message
--endpoint, -e Specify endpoint of the form "address:port", defaults to localhost:20000
`,
{
importMeta: import.meta,
flags: {
endpoint: {
type: 'string',
alias: 'e',
default: 'localhost:20000',
},
},
}
);

const [address, port] = parseEndpoint(cli.flags.endpoint);

const client = createConcordiumClient(
address,
Number(port),
credentials.createInsecure()
);

/**
* Queries the node for its health
*/
(async () => {
// #region documentation-snippet
const check = await client.healthCheck();
if (check.isHealthy) {
console.log('The node is healthy!');
} else {
console.log('The node is not healthy');
console.log('Message: ' + check.message);
}
// #endregion documentation-snippet
})();
2 changes: 2 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"name": "@concordium/examples",
"type": "module",
"dependencies": {
"@concordium/ccd-js-gen": "workspace:^",
"@concordium/common-sdk": "workspace:^",
"@concordium/node-sdk": "workspace:^",
"@grpc/grpc-js": "^1.3.4",
"@noble/ed25519": "^1.7.1",
Expand Down
26 changes: 21 additions & 5 deletions examples/shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,27 @@ export const parseAddress = (input: string): Base58String | ContractAddress => {
return { index: BigInt(i), subindex: BigInt(si) };
};

export const parseEndpoint = (endpoint: string): [string, number] => {
// Regular expression for matching the scheme prefix of a URL.
const schemeRegex = /^(\w+):\/\//;

/**
* Parse endpoint information from a string, such as 'http://my-concordium-node:20000'
* @param endpoint String with information of an endpoint.
* @returns Triple with ['<address>', <port>, '<scheme>'].
*/
export const parseEndpoint = (
endpoint: string
): [string, number, string | undefined] => {
const result = schemeRegex.exec(endpoint);
const matched = result?.[0];
const scheme = result?.[1];

const noSchemeEndpoint = endpoint.substring(matched?.length ?? 0);

// Split endpoint on last colon
const lastColonIndex = endpoint.lastIndexOf(':');
const address = endpoint.substring(0, lastColonIndex);
const port = Number(endpoint.substring(lastColonIndex + 1));
const lastColonIndex = noSchemeEndpoint.lastIndexOf(':');
const address = noSchemeEndpoint.substring(0, lastColonIndex);
const port = Number(noSchemeEndpoint.substring(lastColonIndex + 1));

return [address, port];
return [address, port, scheme];
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"./packages/common",
"./packages/nodejs",
"./packages/web",
"./packages/ccd-js-gen",
"./examples"
]
},
Expand Down
4 changes: 4 additions & 0 deletions packages/ccd-js-gen/bin/ccd-js-gen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node
// eslint-disable-next-line @typescript-eslint/no-var-requires
const cli = require('../lib/src/cli.js');
cli.main();
52 changes: 52 additions & 0 deletions packages/ccd-js-gen/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@concordium/ccd-js-gen",
"version": "1.0.0",
"description": "Generate JS clients for the Concordium Blockchain",
"bin": "bin/ccd-js-gen.js",
"main": "lib/src/lib.js",
"typings": "lib/src/lib.d.ts",
"scripts": {
"build": "tsc",
"build-dev": "yarn build",
"clean": "rm -r lib",
"lint": "eslint src/** bin/** --cache --ext .ts,.js --max-warnings 0",
"lint-fix": "yarn --silent lint --fix; exit 0",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"concordium",
"smart-contracts"
],
"repository": {
"type": "git",
"url": "https://github.com/Concordium/concordium-node-sdk-js",
"directory": "packages/ccd-js-gen"
},
"author": {
"name": "Concordium Software",
"email": "[email protected]",
"url": "https://concordium.com"
},
"license": "Apache-2.0",
"dependencies": {
"@concordium/common-sdk": "9.4.0",
"buffer": "^6.0.3",
"commander": "^11.0.0",
"ts-morph": "^19.0.0"
},
"devDependencies": {
"@types/node": "^20.5.0",
"@typescript-eslint/eslint-plugin": "^4.28.1",
"@typescript-eslint/parser": "^4.28.1",
"eslint": "^7.29.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^2.3.2",
"typescript": "^4.3.5"
},
"prettier": {
"singleQuote": true,
"tabWidth": 4
}
}
34 changes: 34 additions & 0 deletions packages/ccd-js-gen/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
This file contains code for building the command line inferface to the ccd-js-gen library.
*/
import { Command } from 'commander';
import packageJson from '../package.json';
import * as lib from './lib';

/** Type representing the CLI options/arguments and needs to match the options set with commander.js */
type Options = {
/** Smart contract module to generate clients from */
module: string;
/** The output directory for the generated code */
outDir: string;
};

// Main function, which is called be the executable script in `bin`.
export async function main(): Promise<void> {
const program = new Command();
program
.name(packageJson.name)
.description(packageJson.description)
.version(packageJson.version)
.requiredOption(
'-m, --module <module-file>',
'Smart contract module to generate clients from'
)
.requiredOption(
'-o, --out-dir <directory>',
'The output directory for the generated code'
)
.parse(process.argv);
const options = program.opts<Options>();
await lib.generateContractClientsFromFile(options.module, options.outDir);
}
Loading

0 comments on commit d810305

Please sign in to comment.