Skip to content

Commit

Permalink
Export PAPI test signers from chopstick-utils (#877)
Browse files Browse the repository at this point in the history
* Export PAPI test signers from `chopstick-utils`

* Apply fixes from Checked 171 files in 49ms. No fixes applied.

* Fix `depcheck` issues
  • Loading branch information
rockbmb authored Jan 21, 2025
1 parent 891454e commit 1f8967b
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
"dependencies": {
"@acala-network/chopsticks": "workspace:*",
"@acala-network/chopsticks-core": "workspace:*",
"@polkadot-labs/hdkd": "^0.0.10",
"@polkadot-labs/hdkd-helpers": "^0.0.10",
"@polkadot/api": "^15.0",
"@polkadot/api-base": "^15.0",
"@polkadot/keyring": "^13.2",
"@polkadot/types": "^15.0",
"@polkadot/util": "^13.2"
"@polkadot/util": "^13.2",
"polkadot-api": "^1.8.2"
},
"devDependencies": {
"@swc/cli": "0.5.2",
Expand Down
31 changes: 31 additions & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import {
} from '@acala-network/chopsticks'
import type { NewBlockParams } from '@acala-network/chopsticks-core/rpc/dev/new-block.js'
import type { Config } from '@acala-network/chopsticks/schema/index.js'
import { ed25519CreateDerive, sr25519CreateDerive } from '@polkadot-labs/hdkd'
import { DEV_PHRASE, entropyToMiniSecret, mnemonicToEntropy } from '@polkadot-labs/hdkd-helpers'
import { ApiPromise, WsProvider } from '@polkadot/api'
import type { SubmittableExtrinsic } from '@polkadot/api-base/types'
import { Keyring, createTestKeyring } from '@polkadot/keyring'
import type { Codec } from '@polkadot/types/types'
import type { HexString } from '@polkadot/util/types'
import { getPolkadotSigner } from 'polkadot-api/signer'

const logger = defaultLogger.child({ name: 'utils' })

Expand Down Expand Up @@ -275,3 +278,31 @@ export const testingPairs = (keyringType: 'ed25519' | 'sr25519' = 'ed25519', ss5
keyringEth,
}
}

/**
* Creates a set of test signers for either Ed25519 or Sr25519.
* @param keyringType Type of keyring to use for substrate addresses ('ed25519' or 'sr25519')
* @returns Object containing various test signers, and a `polkadotSignerBuilder` function to create more.
*/
export const testingSigners = (keyringType: 'Ed25519' | 'Sr25519' = 'Ed25519') => {
const entropy = mnemonicToEntropy(DEV_PHRASE)
const miniSecret = entropyToMiniSecret(entropy)
const derive = keyringType === 'Ed25519' ? ed25519CreateDerive(miniSecret) : sr25519CreateDerive(miniSecret)

// Create a PAPI polkadot signer given a derivation path e.g. "//Alice" or "//Bob".
const polkadotSignerBuilder = (path: string, keyringType: 'Ed25519' | 'Sr25519' = 'Ed25519') => {
const hdkdKeyPair = derive(path)
return getPolkadotSigner(hdkdKeyPair.publicKey, keyringType, hdkdKeyPair.sign)
}

return {
alice: polkadotSignerBuilder('//Alice', keyringType),
bob: polkadotSignerBuilder('//Bob', keyringType),
charlie: polkadotSignerBuilder('//Charlie', keyringType),
dave: polkadotSignerBuilder('//Dave', keyringType),
eve: polkadotSignerBuilder('//Eve', keyringType),
ferdie: polkadotSignerBuilder('//Ferdie', keyringType),

polkadotSignerBuilder,
}
}
190 changes: 189 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ __metadata:
dependencies:
"@acala-network/chopsticks": "workspace:*"
"@acala-network/chopsticks-core": "workspace:*"
"@polkadot-labs/hdkd": "npm:^0.0.10"
"@polkadot-labs/hdkd-helpers": "npm:^0.0.10"
"@polkadot/api": "npm:^15.0"
"@polkadot/api-base": "npm:^15.0"
"@polkadot/keyring": "npm:^13.2"
"@polkadot/types": "npm:^15.0"
"@polkadot/util": "npm:^13.2"
"@swc/cli": "npm:0.5.2"
"@swc/core": "npm:^1.10.1"
polkadot-api: "npm:^1.8.2"
typescript: "npm:^5.7.2"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -660,6 +663,15 @@ __metadata:
languageName: node
linkType: hard

"@commander-js/extra-typings@npm:^13.0.0":
version: 13.0.0
resolution: "@commander-js/extra-typings@npm:13.0.0"
peerDependencies:
commander: ~13.0.0
checksum: 10c0/7d1f75624ef5026462600b9ef9f7dbb701cefa3a17204bf57a9946aece44ccff343407d910620645c1daa9416439f5be6597adf75a0b8b4cfd08d59b345d0fcc
languageName: node
linkType: hard

"@cspotcode/source-map-support@npm:^0.8.0":
version: 0.8.1
resolution: "@cspotcode/source-map-support@npm:0.8.1"
Expand Down Expand Up @@ -1633,14 +1645,46 @@ __metadata:
languageName: node
linkType: hard

"@noble/curves@npm:^1.7.0":
version: 1.8.0
resolution: "@noble/curves@npm:1.8.0"
dependencies:
"@noble/hashes": "npm:1.7.0"
checksum: 10c0/3ebb1795f3f7d74c879bc6262a3444061585a2cab90b7b637dc57d931063dd0c95be858a4c2389e932651825dbc461c215dbcf43984a232de3bd6b2d326ba555
languageName: node
linkType: hard

"@noble/curves@npm:~1.7.0":
version: 1.7.0
resolution: "@noble/curves@npm:1.7.0"
dependencies:
"@noble/hashes": "npm:1.6.0"
checksum: 10c0/3317ec9b7699d2476707a89ceb3ddce60e69bac287561a31dd533669408633e093860fea5067eb9c54e5a7ced0705da1cba8859b6b1e0c48d3afff55fe2e77d0
languageName: node
linkType: hard

"@noble/hashes@npm:1.5.0":
version: 1.5.0
resolution: "@noble/hashes@npm:1.5.0"
checksum: 10c0/1b46539695fbfe4477c0822d90c881a04d4fa2921c08c552375b444a48cac9930cb1ee68de0a3c7859e676554d0f3771999716606dc4d8f826e414c11692cdd9
languageName: node
linkType: hard

"@noble/hashes@npm:^1.3.1, @noble/hashes@npm:^1.3.3, @noble/hashes@npm:^1.6.1":
"@noble/hashes@npm:1.6.0":
version: 1.6.0
resolution: "@noble/hashes@npm:1.6.0"
checksum: 10c0/e7e75898257fb36d933935fcdf1cc67ca7c083eb7b2411aa57fde7eb494c2cea0bec03686462032e25d5b0e1e4ab7357d1afb6718f6a68515db1f392141e9f14
languageName: node
linkType: hard

"@noble/hashes@npm:1.7.0":
version: 1.7.0
resolution: "@noble/hashes@npm:1.7.0"
checksum: 10c0/1ef0c985ebdb5a1bd921ea6d959c90ba826af3ae05b40b459a703e2a5e9b259f190c6e92d6220fb3800e2385521e4159e238415ad3f6b79c52f91dd615e491dc
languageName: node
linkType: hard

"@noble/hashes@npm:^1.3.1, @noble/hashes@npm:^1.3.3, @noble/hashes@npm:^1.6.1, @noble/hashes@npm:~1.6.0":
version: 1.6.1
resolution: "@noble/hashes@npm:1.6.1"
checksum: 10c0/27643cd8b551bc933b57cc29aa8c8763d586552fc4c3e06ecf7897f55be3463c0c9dff7f6ebacd88e5ce6d0cdb5415ca4874d0cf4359b5ea4a85be21ada03aab
Expand Down Expand Up @@ -1805,6 +1849,43 @@ __metadata:
languageName: node
linkType: hard

"@polkadot-api/cli@npm:0.10.1":
version: 0.10.1
resolution: "@polkadot-api/cli@npm:0.10.1"
dependencies:
"@commander-js/extra-typings": "npm:^13.0.0"
"@polkadot-api/codegen": "npm:0.12.12"
"@polkadot-api/ink-contracts": "npm:0.2.4"
"@polkadot-api/json-rpc-provider": "npm:0.0.4"
"@polkadot-api/known-chains": "npm:0.6.1"
"@polkadot-api/metadata-compatibility": "npm:0.1.14"
"@polkadot-api/observable-client": "npm:0.7.0"
"@polkadot-api/polkadot-sdk-compat": "npm:2.3.1"
"@polkadot-api/sm-provider": "npm:0.1.7"
"@polkadot-api/smoldot": "npm:0.3.8"
"@polkadot-api/substrate-bindings": "npm:0.11.0"
"@polkadot-api/substrate-client": "npm:0.3.0"
"@polkadot-api/utils": "npm:0.1.2"
"@polkadot-api/wasm-executor": "npm:^0.1.2"
"@polkadot-api/ws-provider": "npm:0.3.6"
"@types/node": "npm:^22.10.5"
commander: "npm:^13.0.0"
execa: "npm:^9.5.2"
fs.promises.exists: "npm:^1.1.4"
ora: "npm:^8.1.1"
read-pkg: "npm:^9.0.1"
rxjs: "npm:^7.8.1"
tsc-prog: "npm:^2.3.0"
tsup: "npm:^8.3.5"
typescript: "npm:^5.7.3"
write-package: "npm:^7.1.0"
bin:
papi: dist/main.js
polkadot-api: dist/main.js
checksum: 10c0/c8cc76976208cdc321ea76d68d00176ff340a3ff4259573d1ca959849b5d2f86b9d19a4f6936035bbd44ff04688d12da0c7314715853f124e38158919cbe8c7a
languageName: node
linkType: hard

"@polkadot-api/codegen@npm:0.12.12":
version: 0.12.12
resolution: "@polkadot-api/codegen@npm:0.12.12"
Expand Down Expand Up @@ -1865,6 +1946,13 @@ __metadata:
languageName: node
linkType: hard

"@polkadot-api/known-chains@npm:0.6.1":
version: 0.6.1
resolution: "@polkadot-api/known-chains@npm:0.6.1"
checksum: 10c0/a7cbe7726778ae2c1503b41d5a2fe6f496a961deb25df17b336633d65827eb046651fc829ea8d490f1c7a11cd65b87b1e23009a8b1e6522fe5e4a57e6239422b
languageName: node
linkType: hard

"@polkadot-api/logs-provider@npm:0.0.6":
version: 0.0.6
resolution: "@polkadot-api/logs-provider@npm:0.0.6"
Expand Down Expand Up @@ -2084,6 +2172,28 @@ __metadata:
languageName: node
linkType: hard

"@polkadot-labs/hdkd-helpers@npm:0.0.10, @polkadot-labs/hdkd-helpers@npm:^0.0.10":
version: 0.0.10
resolution: "@polkadot-labs/hdkd-helpers@npm:0.0.10"
dependencies:
"@noble/curves": "npm:^1.7.0"
"@noble/hashes": "npm:^1.6.1"
"@scure/base": "npm:^1.2.1"
micro-sr25519: "npm:^0.1.0"
scale-ts: "npm:^1.6.1"
checksum: 10c0/0a30aef8dded84ca7d6550fd327ffcbb7c6273d32f2c6b076b871554deee78c70bd1b673c61f4838b8179754a1dc6bb8d82cafa5d006c441f375e840163c7908
languageName: node
linkType: hard

"@polkadot-labs/hdkd@npm:^0.0.10":
version: 0.0.10
resolution: "@polkadot-labs/hdkd@npm:0.0.10"
dependencies:
"@polkadot-labs/hdkd-helpers": "npm:0.0.10"
checksum: 10c0/750c9bb5a1c617167350b9f7a35ce440e1b6ab8ea227144ac7c3fe11d6c453f78e15440330baf5adc17620d099cf3fe797995d2eaa0422c3818ad2080cf324c0
languageName: node
linkType: hard

"@polkadot/api-augment@npm:15.0.2, @polkadot/api-augment@npm:^15.0":
version: 15.0.2
resolution: "@polkadot/api-augment@npm:15.0.2"
Expand Down Expand Up @@ -3297,6 +3407,15 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:^22.10.5":
version: 22.10.7
resolution: "@types/node@npm:22.10.7"
dependencies:
undici-types: "npm:~6.20.0"
checksum: 10c0/c941b4689dfc4044b64a5f601306cbcb0c7210be853ba378a5dd44137898c45accedd796ee002ad9407024cac7ecaf5049304951cb1d80ce3d7cebbbae56f20e
languageName: node
linkType: hard

"@types/node@npm:^22.9.0":
version: 22.10.5
resolution: "@types/node@npm:22.10.5"
Expand Down Expand Up @@ -4725,6 +4844,13 @@ __metadata:
languageName: node
linkType: hard

"commander@npm:^13.0.0":
version: 13.1.0
resolution: "commander@npm:13.1.0"
checksum: 10c0/7b8c5544bba704fbe84b7cab2e043df8586d5c114a4c5b607f83ae5060708940ed0b5bd5838cf8ce27539cde265c1cbd59ce3c8c6b017ed3eec8943e3a415164
languageName: node
linkType: hard

"commander@npm:^4.0.0":
version: 4.1.1
resolution: "commander@npm:4.1.1"
Expand Down Expand Up @@ -6943,6 +7069,16 @@ __metadata:
languageName: node
linkType: hard

"micro-sr25519@npm:^0.1.0":
version: 0.1.0
resolution: "micro-sr25519@npm:0.1.0"
dependencies:
"@noble/curves": "npm:~1.7.0"
"@noble/hashes": "npm:~1.6.0"
checksum: 10c0/3b2b51e51615ffdd60cadf43bf7560213a01843d301dfb52ded13851442f9d23dfdf151b5cd5fe6340713dd8eb8b1c6e21a539b51f6523f13436cba7b03dd946
languageName: node
linkType: hard

"micromark-util-character@npm:^2.0.0":
version: 2.1.0
resolution: "micromark-util-character@npm:2.1.0"
Expand Down Expand Up @@ -7901,6 +8037,38 @@ __metadata:
languageName: node
linkType: hard

"polkadot-api@npm:^1.8.2":
version: 1.8.2
resolution: "polkadot-api@npm:1.8.2"
dependencies:
"@polkadot-api/cli": "npm:0.10.1"
"@polkadot-api/ink-contracts": "npm:0.2.4"
"@polkadot-api/json-rpc-provider": "npm:0.0.4"
"@polkadot-api/known-chains": "npm:0.6.1"
"@polkadot-api/logs-provider": "npm:0.0.6"
"@polkadot-api/metadata-builders": "npm:0.10.0"
"@polkadot-api/metadata-compatibility": "npm:0.1.14"
"@polkadot-api/observable-client": "npm:0.7.0"
"@polkadot-api/pjs-signer": "npm:0.6.3"
"@polkadot-api/polkadot-sdk-compat": "npm:2.3.1"
"@polkadot-api/polkadot-signer": "npm:0.1.6"
"@polkadot-api/signer": "npm:0.1.13"
"@polkadot-api/sm-provider": "npm:0.1.7"
"@polkadot-api/smoldot": "npm:0.3.8"
"@polkadot-api/substrate-bindings": "npm:0.11.0"
"@polkadot-api/substrate-client": "npm:0.3.0"
"@polkadot-api/utils": "npm:0.1.2"
"@polkadot-api/ws-provider": "npm:0.3.6"
"@rx-state/core": "npm:^0.1.4"
peerDependencies:
rxjs: ">=7.8.0"
bin:
papi: bin/cli.mjs
polkadot-api: bin/cli.mjs
checksum: 10c0/9ec708089cfb2696e1ad9a5567c7ce8c6da5829a668f0efc667071b40be1ec5e0aa45b6467635c80147712ded9608afd70dc74c4c498e655e18abcf6edb96bff
languageName: node
linkType: hard

"postcss-load-config@npm:^6.0.1":
version: 6.0.1
resolution: "postcss-load-config@npm:6.0.1"
Expand Down Expand Up @@ -9709,6 +9877,16 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:^5.7.3":
version: 5.7.3
resolution: "typescript@npm:5.7.3"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/b7580d716cf1824736cc6e628ab4cd8b51877408ba2be0869d2866da35ef8366dd6ae9eb9d0851470a39be17cbd61df1126f9e211d8799d764ea7431d5435afa
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A^5.7.2#optional!builtin<compat/typescript>":
version: 5.7.2
resolution: "typescript@patch:typescript@npm%3A5.7.2#optional!builtin<compat/typescript>::version=5.7.2&hash=5786d5"
Expand All @@ -9719,6 +9897,16 @@ __metadata:
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A^5.7.3#optional!builtin<compat/typescript>":
version: 5.7.3
resolution: "typescript@patch:typescript@npm%3A5.7.3#optional!builtin<compat/typescript>::version=5.7.3&hash=5786d5"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/6fd7e0ed3bf23a81246878c613423730c40e8bdbfec4c6e4d7bf1b847cbb39076e56ad5f50aa9d7ebd89877999abaee216002d3f2818885e41c907caaa192cc4
languageName: node
linkType: hard

"uc.micro@npm:^2.0.0, uc.micro@npm:^2.1.0":
version: 2.1.0
resolution: "uc.micro@npm:2.1.0"
Expand Down

0 comments on commit 1f8967b

Please sign in to comment.