Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Commit

Permalink
version 0.3.0 merged
Browse files Browse the repository at this point in the history
  • Loading branch information
wischli committed Jun 16, 2020
2 parents c81ecaa + 680e9d1 commit 36b2cb5
Show file tree
Hide file tree
Showing 15 changed files with 632 additions and 855 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
ls
mv wasm build/wasm
yarn install --frozen-lockfile
docker run -d --rm -p 9944:9944 kiltprotocol/portablegabi-node --dev --ws-port 9944 --ws-external
docker run -d --rm -p 9944:9944 kiltprotocol/portablegabi-node
sleep 5s
yarn test:integration
docker stop $(docker ps -f ancestor=kiltprotocol/portablegabi-node -q)
Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:
yarn install --frozen-lockfile
yarn ts-node docs/examples/exampleSingle.ts
yarn ts-node docs/examples/exampleCombined.ts
docker run -d --rm -p 9944:9944 kiltprotocol/portablegabi-node --dev --ws-port 9944 --ws-external
docker run -d --rm -p 9944:9944 kiltprotocol/portablegabi-node
sleep 5s
yarn ts-node docs/examples/exampleSingle.chain.ts
yarn ts-node docs/examples/exampleCombined.chain.ts
Expand Down Expand Up @@ -168,7 +168,7 @@ jobs:
mv wasm build/wasm
yarn install --frozen-lockfile
yarn ts-node docs/examples/tutorial/tutorial.ts
docker run -d --rm -p 9944:9944 kiltprotocol/portablegabi-node --dev --ws-port 9944 --ws-external
docker run -d --rm -p 9944:9944 kiltprotocol/portablegabi-node
sleep 5s
yarn ts-node docs/examples/tutorial/sections/4_chain.ts
env:
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/exampleCombined.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async function completeProcessCombined({
async function completeProcessCombinedExamples(): Promise<void> {
// connect to chain
const blockchain = await connect({
pgabiModName: 'portablegabi',
pgabiModName: 'portablegabiPallet',
})
console.log('Connected to chain')
// we accept every accumulator when requiring past in reqUpdatedAfter
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/exampleSingle.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function completeProcessSingle({
async function completeProcessSingleExamples(): Promise<void> {
// connect to chain
const blockchain = await connect({
pgabiModName: 'portablegabi',
pgabiModName: 'portablegabiPallet',
})
console.log('Connected to chain')
// we accept every accumulator when requiring past in reqUpdatedAfter
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/onchain/1_actorProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function actorProcessChain({
new AttesterPublicKey(attesterPubKey),
new AttesterPrivateKey(attesterPrivKey),
attesterURI,
'ed25519'
'sr25519'
)

// get accumulator from chain
Expand All @@ -52,9 +52,9 @@ export async function actorProcessChain({
accumulator = await attester.createAccumulator()

// check for missing balance before updating accumulator
const balance = await blockchain.api.query.balances.freeBalance(
attester.address
)
const {
data: { free: balance },
} = await blockchain.api.query.system.account(attester.address)
if (balance.isEmpty) {
throw new Error(
`Missing balance for address "${attester.address}" with URI/mnemonic ${attesterURI}`
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/tutorial/sections/4_chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function exec(): Promise<void> {
/** (1) Chain phase */
// (1.1) Connect to the chain.
const chain = await portablegabi.connect({
pgabiModName: 'portablegabi',
pgabiModName: 'portablegabiPallet',
})
console.log('Successfully connected to the chain')

Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kiltprotocol/portablegabi",
"version": "0.2.3",
"version": "0.3.0",
"description": "Typescript API and WASM wrapper of Go library Gabi enabling anonymous credentials",
"main": "./build/index.js",
"typings": "./build/index.d.ts",
Expand Down Expand Up @@ -32,15 +32,15 @@
},
"homepage": "https://github.com/KILTprotocol/portablegabi#readme",
"devDependencies": {
"@types/jest": "^25.2.3",
"@types/node": "^14.0.5",
"@typescript-eslint/eslint-plugin": "^3.0.1",
"@typescript-eslint/parser": "^3.0.1",
"@types/jest": "^26.0.0",
"@types/node": "^14.0.13",
"@typescript-eslint/eslint-plugin": "^3.2.0",
"@typescript-eslint/parser": "^3.2.0",
"eslint": "^7.1.0",
"eslint-config-airbnb-base": "14.1.0",
"eslint-config-airbnb-base": "14.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jsdoc": "^25.4.2",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-jsdoc": "^27.0.6",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-tsc": "^1.2.0",
"jest": "^26.0.1",
Expand All @@ -51,18 +51,18 @@
"ts-jest": "^26.0.0",
"ts-node": "^8.10.1",
"typedoc": "^0.17.7",
"typescript": "^3.8.3"
"typescript": "^3.9.5"
},
"repository": {
"type": "git",
"url": "git+https://github.com/KILTprotocol/portablegabi.git"
},
"dependencies": {
"@polkadot/api": "^0.96.1",
"@polkadot/keyring": "^1.7.0",
"@polkadot/rpc-provider": "^1.7.0",
"@polkadot/types": "^0.96.1",
"@polkadot/util": "^1.7.0",
"@polkadot/util-crypto": "^1.7.0"
"@polkadot/api": "^1.18.1",
"@polkadot/keyring": "^2.13.1",
"@polkadot/rpc-provider": "^1.18.1",
"@polkadot/types": "^1.18.1",
"@polkadot/util": "^2.13.1",
"@polkadot/util-crypto": "^2.13.1"
}
}
12 changes: 6 additions & 6 deletions src/attestation/Attester.chain.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mnemonicToSeed, mnemonicToMiniSecret } from '@polkadot/util-crypto'
import { mnemonicToMiniSecret } from '@polkadot/util-crypto'
import { Keyring } from '@polkadot/api'
import AttesterChain from './Attester.chain'
import { actorSetupChain } from '../testSetup/testSetup.chain'
Expand Down Expand Up @@ -32,7 +32,7 @@ describe('Test Attester on chain', () => {
it('Should generate correct keypair for signature type sr25519', async () => {
const mnemonic = AttesterChain.generateMnemonic()
const miniSecretSeed = mnemonicToMiniSecret(mnemonic)
const seed = mnemonicToSeed(mnemonic)
const seed = mnemonicToMiniSecret(mnemonic)
const { address: attesterAddress } = await AttesterChain.buildFromMnemonic(
new AttesterPublicKey('pb'),
new AttesterPrivateKey('pk'),
Expand All @@ -57,14 +57,14 @@ describe('Test Attester on chain', () => {
}).addFromMnemonic(mnemonic)
expect(attesterAddress).toBe(fromMiniSecret)
expect(attesterAddress).toBe(fromMnemonic)
expect(attesterAddress).not.toBe(fromSeed)
expect(attesterAddress).toBe(fromSeed)
expect(attesterAddress).toBe(attesterAddressFromURI)
}, 10000)
// NOTE: if this test fails after updating @polkadot packages, we should adjust Attester.chain.ts
// see issue https://github.com/polkadot-js/common/blob/d889c71056158df72b34b994506d062c2e731cc0/packages/keyring/src/keyring.ts#L174
it('Should generate correct keypair for signature type ed25519', async () => {
const mnemonic = AttesterChain.generateMnemonic()
const seed = mnemonicToSeed(mnemonic)
const seed = mnemonicToMiniSecret(mnemonic)
const { address: attesterAddress } = await AttesterChain.buildFromMnemonic(
new AttesterPublicKey('pb'),
new AttesterPrivateKey('pk'),
Expand All @@ -87,8 +87,8 @@ describe('Test Attester on chain', () => {
type: 'ed25519',
}).addFromMnemonic(mnemonic)
expect(attesterAddress).toBe(fromSeed)
expect(attesterAddress).not.toBe(fromMnemonic)
expect(attesterAddress).not.toBe(attesterAddressFromURI)
expect(attesterAddress).toBe(fromMnemonic)
expect(attesterAddress).toBe(attesterAddressFromURI)
expect(attesterAddressFromURI).toBe(fromMnemonic)
}, 10000)
it('Should generate new mnemonic with every call', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/attestation/Attester.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { KeyringPair } from '@polkadot/keyring/types'
import { Keyring } from '@polkadot/api'
import {
mnemonicGenerate,
mnemonicToSeed,
mnemonicToMiniSecret,
cryptoWaitReady,
} from '@polkadot/util-crypto'
import { KeypairType } from '@polkadot/util-crypto/types'
import { u8aToHex } from '@polkadot/util'
import { SubmittableExtrinsic } from '@polkadot/api/types'
import { u8aToHex } from '@polkadot/util'
import Attester, { KeyGenOptions } from './Attester'
import {
Witness,
Expand Down Expand Up @@ -89,7 +89,7 @@ export default class AttesterChain extends Attester implements IAttesterChain {
return this.buildFromURI(publicKey, privateKey, mnemonic, type)
}
const keyringPair = new Keyring({ type }).addFromUri(
u8aToHex(mnemonicToSeed(mnemonic))
u8aToHex(mnemonicToMiniSecret(mnemonic))
)
return new AttesterChain(publicKey, privateKey, keyringPair)
}
Expand Down
10 changes: 5 additions & 5 deletions src/blockchain/Blockchain.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ let alice: Attester
let bob: Attester

beforeAll(async () => {
alice = await Attester.buildFromURI(pubKey, privKey, '//Alice', 'ed25519')
bob = await Attester.buildFromURI(pubKey2, privKey2, '//Bob', 'ed25519')
alice = await Attester.buildFromURI(pubKey, privKey, '//Alice', 'sr25519')
bob = await Attester.buildFromURI(pubKey2, privKey2, '//Bob', 'sr25519')
})

describe('When I have a fresh chain with a Portablegabi pallet...', () => {
it('it connects', async () => {
chain = await getCached({ pgabiModName: 'portablegabi' })
chain = await getCached({ pgabiModName: 'portablegabiPallet' })
expect(chain.api.isReady).toBeTruthy()
})

Expand All @@ -40,7 +40,7 @@ describe('When I have a fresh chain with a Portablegabi pallet...', () => {
])
expect(count).toEqual<number>(baseline + 1)
expect(accChain).toEqual<Accumulator>(accumulator)
}, 15_000)
}, 20_000)

it('is possible for someone else to store an accumulator at the same time', async () => {
const baseline = await chain.getAccumulatorCount(bob.address)
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('When I have a fresh chain with a Portablegabi pallet...', () => {
})

it('it disconnects', async () => {
chain = await getCached({ pgabiModName: 'portablegabi' })
chain = await getCached({ pgabiModName: 'portablegabiPallet' })
await chain.api.disconnect()
expect(chain.api.isReady).resolves.toStrictEqual({})
})
Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/Blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Accumulator from '../attestation/Accumulator'
* import portablegabi from '@kiltprotocol/portablegabi'
* // depending on the blockchain, the module where the accumulator is store might be called differently.
* // The name can be configured using the 'pgabiModName' option.
* const bc = await portablegabi.connect({ pgabiModName: 'portablegabi' })
* const bc = await portablegabi.connect({ pgabiModName: 'portablegabiPallet' })
* const acc = await bc.getAccumulatorCount(addr)
* ```
*/
Expand Down
5 changes: 4 additions & 1 deletion src/blockchainApiConnection/BlockchainApiConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export interface IPortableGabiApiOptions extends ApiOptions {

const DEFAULT_WS_ADDRESS = 'ws://127.0.0.1:9944'
const DEFAULT_MOD_NAME: PgabiModName = 'portablegabi'
const DEFAULT_TYPES: RegistryTypes = {}
const DEFAULT_TYPES: RegistryTypes = {
Address: 'AccountId',
LookupSource: 'AccountId',
}
const DEFAULT_PARAMS: IPortableGabiApiOptions = {
host: DEFAULT_WS_ADDRESS,
types: DEFAULT_TYPES,
Expand Down
4 changes: 2 additions & 2 deletions src/claim/Claimer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('Test claimer creation', () => {
)
expect(claimerWithoutPass).toHaveProperty(
'secret',
'{"MasterSecret":"9o2iTwz6wx0FtPJ7BqQCVrF/vvVxX0GFr5kPBQ6R9XM="}'
'{"MasterSecret":"q6Ei+TL3Tdd6YSGQol8J2fqWMnhPiBr81OhuUdRC3bU="}'
)
expect(claimerWithoutPass).not.toStrictEqual(claimer)
const claimerWithPass = await Claimer.buildFromMnemonic(
Expand All @@ -81,7 +81,7 @@ describe('Test claimer creation', () => {
)
expect(claimerWithPass).toHaveProperty(
'secret',
'{"MasterSecret":"2VhYuA7pIoHpPFzzerBUULPDRjT2vqthdNIhlByFcgg="}'
'{"MasterSecret":"kAQp95GiILur3Nne1KGengwhhioS9ycwRiW5xDThano="}'
)
expect(claimerWithPass).not.toStrictEqual(claimer)
expect(claimerWithPass).not.toStrictEqual(claimerWithoutPass)
Expand Down
4 changes: 2 additions & 2 deletions src/claim/Claimer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import toSeed from '@polkadot/util-crypto/mnemonic/toSeed'
import { u8aToHex } from '@polkadot/util'
import validate from '@polkadot/util-crypto/mnemonic/validate'
import { mnemonicToMiniSecret } from '@polkadot/util-crypto'
import IClaimer, {
AttestationRequest,
ClaimerAttestationSession,
Expand Down Expand Up @@ -70,7 +70,7 @@ export default class Claimer implements IClaimer {
if (!validate(mnemonic)) {
throw new Error('Invalid mnemonic')
}
const seed = toSeed(mnemonic, password)
const seed = mnemonicToMiniSecret(mnemonic, password)
return this.buildFromSeed(seed, keyLength)
}

Expand Down
15 changes: 2 additions & 13 deletions src/types/Chain.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Codec, AnyFunction } from '@polkadot/types/types'
import {
SubmittableExtrinsic,
MethodResult,
StorageEntryBase,
ApiTypes,
} from '@polkadot/api/types'
import { Codec } from '@polkadot/types/types'
import { SubmittableExtrinsic, AugmentedQuery } from '@polkadot/api/types'
import { ApiPromise } from '@polkadot/api'
import { KeyringPair } from '@polkadot/keyring/types'
import Accumulator from '../attestation/Accumulator'
Expand All @@ -19,12 +14,6 @@ export type PgabiModName = 'portablegabi' | 'portablegabiPallet' | string
*/
export const DEFAULT_KEY_TYPE = 'sr25519'

/** @internal */
export type AugmentedQuery<
ApiType extends ApiTypes,
F extends AnyFunction
> = MethodResult<ApiType, F> & StorageEntryBase<ApiType, F>

/** @internal */
export interface IPortablegabiApi<T extends PgabiModName> {
query: {
Expand Down
Loading

0 comments on commit 36b2cb5

Please sign in to comment.