Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference docs generation and plan. #319

Merged
merged 55 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
3d81a3b
add typedoc back in, update setup
mixmix Apr 18, 2024
8649c2c
delete docs/
mixmix Apr 18, 2024
7a39578
generate html docs
mixmix Apr 18, 2024
7636472
add docs plugin - preserves default export class name
mixmix Apr 18, 2024
e291209
tweak ts config + tsup config
mixmix Apr 18, 2024
1700d08
update README.md
mixmix Apr 18, 2024
9498ef0
files for testing import + require is working
mixmix Apr 18, 2024
76dd5eb
WIP documentation coverage
mixmix Apr 23, 2024
1729517
more
mixmix Apr 23, 2024
e129117
WIP: catch + clarify the "ready" error
mixmix Apr 23, 2024
c003a01
prettier + stuff
mixmix Apr 24, 2024
8a603f2
delete docs
mixmix Apr 24, 2024
9b5baf6
gitignore docs
mixmix Apr 24, 2024
b0cd4ae
add lint-staged in pre-commit hook (husky)
mixmix Apr 24, 2024
bf62e87
bits
mixmix Apr 29, 2024
97880ac
Merge branch 'main' of github.com:entropyxyz/sdk into mixmix/DOCS
mixmix Apr 29, 2024
8e933df
Merge branch 'main' of github.com:entropyxyz/sdk into code-style
mixmix Apr 29, 2024
265835e
add remove:db script back
mixmix Apr 29, 2024
27bcedb
undo entropy-metadata.json / yaml files
mixmix Apr 29, 2024
1cf3051
install code-style deps
mixmix Apr 30, 2024
e295273
lint + prettier
mixmix Apr 30, 2024
66843f8
upgrade eslint (minor), rm dead config
mixmix Apr 30, 2024
2a660b5
Merge branch 'code-style' into mixmix/DOCS
mixmix Apr 30, 2024
8372a2a
fix lockfile
mixmix Apr 30, 2024
1ead074
Merge branch 'code-style' into mixmix/DOCS
mixmix Apr 30, 2024
2835357
tidy
mixmix Apr 30, 2024
2a3fb2b
stop eslint + prettier fighting over spaces
mixmix Apr 30, 2024
4d59dd7
merge in some eslint / prettier changes
mixmix Apr 30, 2024
ee43790
Merge branch 'code-style' into mixmix/DOCS
mixmix Apr 30, 2024
4028c4e
fix yarn.lock
mixmix Apr 30, 2024
97e77b4
update prettier
mixmix Apr 30, 2024
673a256
update prettier
mixmix Apr 30, 2024
4a3a2ea
Merge branch 'code-style' into mixmix/DOCS
mixmix Apr 30, 2024
a2a61c7
remark tweaks, tidying
mixmix Apr 30, 2024
17f782d
tutu
mixmix Apr 30, 2024
cd24ff6
Merge branch 'main' of github.com:entropyxyz/sdk into mixmix/DOCS
mixmix May 1, 2024
867d447
misc bits
mixmix May 1, 2024
bdfc4d2
wip: working on examples with mix
frankiebee May 2, 2024
190e5b9
add publish check list
frankiebee May 2, 2024
e84bc97
chunk
mixmix May 2, 2024
f1a87eb
progress test
mixmix May 2, 2024
46eaac2
Merge branch 'main' of github.com:entropyxyz/sdk into mixmix/DOCS
mixmix Jun 5, 2024
de6e748
tidy
mixmix Jun 5, 2024
428ea26
enable all entryPoints
mixmix Jun 6, 2024
1384092
revert typescrupt config changes
mixmix Jun 6, 2024
c4161d9
Merge branch 'main' into mixmix/DOCS
mixmix Jun 6, 2024
5f29e13
Merge branch 'main' of github.com:entropyxyz/sdk into mixmix/DOCS
mixmix Jun 11, 2024
881812b
Merge branch 'main' of github.com:entropyxyz/sdk into mixmix/DOCS
mixmix Jun 18, 2024
08ed720
update config to reflect entryPoints
mixmix Jun 18, 2024
820b0b0
add plugin which merges docs entryPoints, add some @examples
mixmix Jun 18, 2024
1c67fa2
add plugin which merges docs entryPoints, add some @examples
mixmix Jun 18, 2024
8963395
moar docs
mixmix Jun 18, 2024
879159f
Merge branch 'main' of github.com:entropyxyz/sdk into mixmix/DOCS
mixmix Jun 23, 2024
9f66f90
Merge branch 'main' into mixmix/DOCS
rh0delta Jun 25, 2024
18f05b3
fixing sign test
rh0delta Jun 25, 2024
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
47 changes: 46 additions & 1 deletion dev/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Hello sdk dev!

This is your home base for how to develop on the project locally and process around that

## Branches

- `dev`
in development
- `main`
"stable" what is on npm

- `<name>/<issue_number>-<short_title>` (personal branches)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is issue number required for the branch name? Will this now be the new standard? More often than not, our branches don't include the issue number in the name, but rather required in the PR description prefixed by "closes" or "fixes" or something along those lines

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I copied this from notes from a call with frankie. I'm not sure I care about issue number.
Let's discuss

for example `frankie/i123-docs`

all PRS go into `dev`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make a comment about hotfix prs going straight to main?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. Those would be patch releases aye?

i feel like we could make a patch branch. Basically anything we write ha gotta get smoke testing befor going into main + published...

depends how many patches we expect. What I'm being cautious of is "special shorcuts". They can cause problems


## Versions

The SDK version must match a compatible [`entropy-core`](https://github.com/entropyxyz/entropy-core) version.

<!-- TODO: -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this here for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An invisible comment!

i think I'd like to see a thing there where we list the details of the compatible versions of things.

this was just from using other sdks where it became a nightmare to know how to run a compatible network of tools cos the versions of things which work together was not well documented.
i may have trauma


| module | tag |
| ----------------- | ----------------- |
| `@entropyxyz/sdk` | `main` TODO |
| `entropy-core` | `release/v0.0.12` |


## Tests

For the tests to run you **must** edit your `/etc/hosts` file, adding:
Expand Down Expand Up @@ -93,13 +119,32 @@ git commit --no-verify

## Publishing

**Unfinished section**

Always publish from `stable` branch

- [ ] craft version pr for `dev` into `main`
- [ ] `yarn burn`
- [ ] `yarn build`
- [ ] `yarn test`

- change logs should be hand written as apart of the version pr
- `yarn version patch #or major.minor.patch`

<!-- TO-DO: figure out with him an automated system -->

- [ ] minimum day ideally two day before ping @johnnymatthews on version bump pr set 48 hour timer
- [ ] after timer merge into main
- [ ] `git push origin main --tags`
- [ ] make sure we have a version tag
- [ ] check out version tag
- [ ] create a tag push to main? this might be handled by yarn needs to be checked
- [ ] `npm publish`

```bash
git checkout stable
yarn burn
yarn
yarn build
yarn version --patch # patch|minor|major
npm publish
git push origin stable --tags
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.2.1",
"license": "AGPL-3.0-only",
"description": "JS SDK for entropy blockchain ",
"type": "module",
mixmix marked this conversation as resolved.
Show resolved Hide resolved
"files": [
"index.cjs",
"index.mjs",
Expand All @@ -12,7 +13,6 @@
"dev/**/*",
"README.md"
],
"type": "module",
"exports": {
".": {
"import": "./index.mjs",
Expand Down Expand Up @@ -54,6 +54,7 @@
"build:link": "yarn build && yarn unlink && yarn link",
"find-deadcode": "ts-prune",
"generate:types": "dev/bin/generate-types.sh",
"generate:docs": "typedoc --options typedoc.config.cjs --tsconfig tsconfig.json",
"prepare": "husky",
"postinstall": "patch-package",
"prepack": "pinst --disable",
Expand All @@ -73,6 +74,7 @@
},
"homepage": "https://github.com/entropyxyz/sdk#readme",
"devDependencies": {
"@mxssfd/typedoc-theme": "^1.1.3",
"@polkadot/typegen": "^10.11.1",
"@types/tape": "^5",
"@typescript-eslint/eslint-plugin": "^5.43.0",
Expand All @@ -91,7 +93,9 @@
"tsup": "^6.5.0",
"tsx": "^4.9.3",
"typedoc": "^0.25.3",
"typedoc-plugin-markdown": "^3.17.0",
"typedoc-plugin-merge-modules": "^5.1.0",
"typedoc-plugin-missing-exports": "^2.3.0",
"typedoc-plugin-rename-defaults": "^0.7.0",
"typescript": "^4.9.5",
"ws": "^8.17.1"
},
Expand Down
48 changes: 41 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,59 @@ export async function wasmGlobalsReady () {
await keysCryptoWaitReady
}
export interface EntropyOpts {
/** Keyring class instance object. */
/** Keyring used to manage all the keys Entropy uses */
keyring: Keyring
/** Local or devnet endpoint for establishing a connection to validators */
/** A websocket endpoint for establishing a connection to validators */
endpoint?: string
/** A collection of signing adapters. */
/** A collection of adapters used for signing messages of particular types.
* These help with formatting, configuring hash functions to use, etc.
* */
adapters?: { [key: string | number]: Adapter }
}

/**
* The main class to handle all interactions with the Entropy SDK.
* The main class to handle all interactions within the Entropy SDK.
*/
export default class Entropy {
/** A promise that resolves once the cryptographic library has been loaded. */
/** A promise that resolves once all internal setup has been successfully completed. */
ready: Promise<boolean>

/* Accessor for ... TODO: */
registrationManager: RegistrationManager

/* Accessor for ... TODO: */
programs: ProgramManager

/* Accessor for the SignatureRequestManager.
* Generally you will use entropy.sign or entropy.signWithAdapter
*
*/
signingManager: SignatureRequestManager

/** Accessor for the keyring passed at instantiation */
keyring: Keyring

/** (Advanced) Accessor for the raw subtate API. */
substrate: ApiPromise

/**
* Initializes an instance of the Entropy class.
* @param {EntropyOpts} opts
*
* @param {EntropyOpts} opts - The configuration options for the Entropy instance.
* @example
* ```ts
* import { Entropy, wasmGlobalsReady } from '@entropyxyz/sdk'
* import { Keyring } from '@entropyxyz/sdk/keys'
*
* async function main () {
* const keyring = new Keyring({ seed })
* const entropy = new Entropy({ keyring })
*
* await wasmGlobalsReady()
* await entropy.ready
* }
*
* main()
* ```
*/

constructor (opts: EntropyOpts) {
Expand Down Expand Up @@ -114,6 +143,7 @@ export default class Entropy {
const admin = this.keyring.getLazyLoadAccountProxy(ChildKey.registration)
const deviceKey = this.keyring.getLazyLoadAccountProxy(ChildKey.deviceKey)
const vk = admin.verifyingKeys || []

// HACK: these assignments trigger important `account-update` flows via the Proxy
admin.verifyingKeys = [...vk, verifyingKey]
deviceKey.verifyingKeys = [verifyingKey, ...vk]
Expand Down Expand Up @@ -179,6 +209,10 @@ export default class Entropy {
return this.signingManager.sign(params)
}

/**
* Shuts the Entropy SDK down gracefully.
* Closes substrate connections for you.
*/
async close () {
if (!this.substrate) return

Expand Down
44 changes: 30 additions & 14 deletions src/keys/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,56 +20,72 @@ const ACCOUNTS = Object.keys(ChildKey)
*/
export default class Keyring {
// private
// it's a unit8array if it comes from a mnemonic and a string if it comes from the user
// The seed used to generate keys, can be a Uint8Array (from mnemonic) or a string (user-provided).
// The seed used to generate keys. Can be a Uint8Array (from mnemonic) or a string (from seed).
#seed: Uint8Array | string
// The the names of accounts used in this keyring
#used: string[]

/** The accounts */
accounts: AccountsEmitter
crypto: Crypto

/**
* Initializes a new instance of the `Keyring` class.
*
* @param account - The key material and entropy account used for key generation.
* @param account - The key material (or account) used for key generation.
*
* @example
*
* ```ts
* import { Keyring } from '@entropyxyz/sdk/keys'
*
* const keyring = new Keyring({
* seed: '0xbc1ede780f784bb6991a585e4f6e61522c14e1cae6ad0895fb57b9a205a8f938'
* })
*
* keyring.accounts.on('account-update', (fullAccount) => {
* // TODO: persist this
* })
* ```
*/

constructor (account: KeyMaterial) {
// this repersents keys that are used by the user
// The the names of accounts used in this keyring
this.#used = ['admin', ChildKey.registration]
Object.keys(account).forEach((key) => {
if (typeof account[key] === 'object' && account[key].userContext) {
if (account[key]?.userContext) {
this.#used.push(key)
} else if ((account as EntropyAccount).debug) {
this.#used.push(key)
}
})

// set #seed
const { seed, mnemonic } = account
if (!seed && !mnemonic)
throw new Error('Need at least a seed or mnemonic to create keys')
if (mnemonic) {
this.#seed = utils.seedFromMnemonic(mnemonic)
} else {
this.#seed = seed
}
this.#seed = mnemonic
? utils.seedFromMnemonic(mnemonic)
: seed

// setup accounts
const accountsJson = this.#formatAccounts(account)
this.accounts = this.#createFunctionalAccounts(accountsJson)
this.accounts.masterAccountView = accountsJson
}

#formatAccounts (accounts: EntropyAccount): EntropyAccount {

#formatAccounts (accounts: EntropyAccount): EntropyAccount {
// TODO: refactor to use "account" not "accounts"
const { seed, type, admin } = accounts
const debug = true
const entropyAccountsJson = {
debug,
// previously was seed ? seed : utils.seedFromMnemonic(mnemonic) but this has already been derived in the constructor
// @frankie correct if im wrong here
seed: this.#seed,
type,
admin,
}


Object.keys(accounts)
.concat(ACCOUNTS)
.forEach((key) => {
Expand Down
2 changes: 1 addition & 1 deletion src/keys/types/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export type Mnemonic = string

export type KeyMaterial =
| (HexSeedMaterial & MnemonicSeedMaterial)
| EntropyAccount //HexSeedMaterial & MnemonicSeedMaterial
| EntropyAccount // HexSeedMaterial & MnemonicSeedMaterial

/**
* Represents key material using a hexadecimal seed.
Expand Down
3 changes: 2 additions & 1 deletion src/registration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { Signer } from '../keys/types/internal'
import { Address } from '../types/internal'

export interface RegistrationParams {
/** initial programs associated with the user */
programData: ProgramInstance[]
/** just testing this functionality, not intending to use this as the set program */
/** The account authorized to modify programs on behalf of the user. */
programDeployer?: SS58Address
}

Expand Down
2 changes: 1 addition & 1 deletion tests/sign.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
spinNetworkDown,
charlieStashSeed,
charlieSeed,
sleep,
} from './testing-utils'

const NETWORK_TYPE = 'two-nodes'
Expand Down Expand Up @@ -65,7 +66,6 @@ test('Sign: custom signatureVerifyingKey', async (t) => {

/* Setup Network */
await run('network up', spinNetworkUp(NETWORK_TYPE))
await sleep(process.env.GITHUB_WORKSPACE ? 30_000 : 5_000)
t.teardown(async () => {
// this gets called after all tests are run
await charlieStashEntropy.close()
Expand Down
7 changes: 3 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
"module": "Node16"
},
"exclude": [
"node_modules",
"dev",
"dist",
"build",
"examples",
"old",
"docs",
"node_modules",
"substrate-generated-types"
],
"ts-node": {
Expand Down
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig } from 'tsup'
export default defineConfig((options) => {
return {
entry: [
`src/index.ts`,
'src/index.ts',
'src/keys/index.ts',
'src/keys/utils.ts',
'src/utils/index.ts',
Expand Down
38 changes: 38 additions & 0 deletions typedoc.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/** @type {import('typedoc').TypeDocOptions} */

// see: https://typedoc.org/options/

module.exports = {
// NOTE: entryPoints reflects pakcage.json "exports"
entryPoints: [
'src/index.ts',
'src/keys/index.ts',
],
// entryPointStrategy: 'expand',

out: './docs',

tsconfig: './tsconfig.json',
excludePrivate: true,
// excludeInternal: true,
validation: {
notExported: true,
invalidLink: true,
notDocumented: true,
},
plugin: [
'@mxssfd/typedoc-theme',
'typedoc-plugin-rename-defaults',
'typedoc-plugin-merge-modules',
// 'typedoc-plugin-missing-exports',
],
/* typedoc-plugin-missing-exports:*/
// internalModule: 'internal',
// placeInternalsInOwningModule: true,

/* typedoc-plugin-merge-modules: */
mergeModulesRenameDefaults: true,
mergeModulesMergeMode: 'project',

theme: 'my-theme',
}
Loading