Skip to content

Commit 8963395

Browse files
committed
moar docs
1 parent 1c67fa2 commit 8963395

File tree

4 files changed

+39
-26
lines changed

4 files changed

+39
-26
lines changed

src/index.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ export default class Entropy {
3838
/** A promise that resolves once all internal setup has been successfully completed. */
3939
ready: Promise<boolean>
4040

41-
/* Accessory for ... TODO: */
41+
/* Accessor for ... TODO: */
4242
registrationManager: RegistrationManager
4343

44-
/* Accessory for ... TODO: */
44+
/* Accessor for ... TODO: */
4545
programs: ProgramManager
4646

47-
/* Accessory for ... TODO: */
47+
/* Accessor for the SignatureRequestManager.
48+
* Generally you will use entropy.sign or entropy.signWithAdapter
49+
*
50+
*/
4851
signingManager: SignatureRequestManager
4952

5053
/** Accessor for the keyring passed at instantiation */
@@ -58,11 +61,18 @@ export default class Entropy {
5861
*
5962
* @example
6063
* ```ts
61-
* import { Entropy } from '@entropyxyz/sdk'
64+
* import { Entropy, wasmGlobalsReady } from '@entropyxyz/sdk'
6265
* import { Keyring } from '@entropyxyz/sdk/keys'
6366
*
64-
* const keyring = new Keyring({ seed })
65-
* const entropy = new Entropy({ keyring })
67+
* async function main () {
68+
* const keyring = new Keyring({ seed })
69+
* const entropy = new Entropy({ keyring })
70+
*
71+
* await wasmGlobalsReady()
72+
* await entropy.ready
73+
* }
74+
*
75+
* main()
6676
* ```
6777
*/
6878

@@ -124,15 +134,13 @@ export default class Entropy {
124134
* @throws {Error} If the address is already registered or if there's a problem during registration.
125135
*/
126136
async register (params?: RegistrationParams): Promise<HexString> {
137+
await this.ready
127138
const defaultProgram = DEVICE_KEY_PROXY_PROGRAM_INTERFACE
128-
129139
params = params || {
130140
programData: [defaultProgram],
131141
programDeployer: this.keyring.accounts.registration.address,
132142
}
133143

134-
await Promise.all([this.ready, this.substrate.isReady])
135-
136144
const deviceKey = this.keyring.getLazyLoadAccountProxy(ChildKey.deviceKey)
137145
deviceKey.used = true
138146
defaultProgram.program_config.sr25519_public_keys.push(
@@ -147,9 +155,11 @@ export default class Entropy {
147155
}
148156

149157
const verifyingKey = await this.registrationManager.register(params)
150-
// fuck frankie TODO: Make legit function
158+
159+
// TODO: Make legit function
151160
const admin = this.keyring.getLazyLoadAccountProxy(ChildKey.registration)
152161
const vk = admin.verifyingKeys || []
162+
153163
// HACK: these assignments trigger important `account-update` flows via the Proxy
154164
admin.verifyingKeys = [...vk, verifyingKey]
155165
deviceKey.verifyingKeys = [verifyingKey, ...vk]
@@ -178,7 +188,7 @@ export default class Entropy {
178188
*/
179189

180190
async signWithAdaptersInOrder (params: SigWithAdapptersOps): Promise<unknown> {
181-
(await this.ready) && this.substrate.isReady
191+
await this.ready
182192
return await this.signingManager.signWithAdaptersInOrder(params)
183193
}
184194

src/keys/index.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ const ACCOUNTS = Object.keys(ChildKey)
2020
*/
2121
export default class Keyring {
2222
// private
23-
// it's a unit8array if it comes from a mnemonic and a string if it comes from the user
24-
// The seed used to generate keys, can be a Uint8Array (from mnemonic) or a string (user-provided).
23+
// The seed used to generate keys. Can be a Uint8Array (from mnemonic) or a string (from seed).
2524
#seed: Uint8Array | string
25+
// The the names of accounts used in this keyring
2626
#used: string[]
27+
28+
/** The accounts */
2729
accounts: AccountsEmitter
2830
crypto: Crypto
2931

@@ -48,42 +50,42 @@ export default class Keyring {
4850
*/
4951

5052
constructor (account: KeyMaterial) {
51-
// this repersents keys that are used by the user
53+
// The the names of accounts used in this keyring
5254
this.#used = ['admin', ChildKey.registration]
5355
Object.keys(account).forEach((key) => {
54-
if (typeof account[key] === 'object' && account[key].userContext) {
56+
if (account[key]?.userContext) {
5557
this.#used.push(key)
5658
} else if ((account as EntropyAccount).debug) {
5759
this.#used.push(key)
5860
}
5961
})
62+
63+
// set #seed
6064
const { seed, mnemonic } = account
6165
if (!seed && !mnemonic)
6266
throw new Error('Need at least a seed or mnemonic to create keys')
63-
if (mnemonic) {
64-
this.#seed = utils.seedFromMnemonic(mnemonic)
65-
} else {
66-
this.#seed = seed
67-
}
67+
this.#seed = mnemonic
68+
? utils.seedFromMnemonic(mnemonic)
69+
: seed
70+
71+
// setup accounts
6872
const accountsJson = this.#formatAccounts(account)
6973
this.accounts = this.#createFunctionalAccounts(accountsJson)
7074
this.accounts.masterAccountView = accountsJson
7175
}
7276

73-
#formatAccounts (accounts: EntropyAccount): EntropyAccount {
7477

78+
#formatAccounts (accounts: EntropyAccount): EntropyAccount {
79+
// TODO: refactor to use "account" not "accounts"
7580
const { seed, type, admin } = accounts
7681
const debug = true
7782
const entropyAccountsJson = {
7883
debug,
79-
// previously was seed ? seed : utils.seedFromMnemonic(mnemonic) but this has already been derived in the constructor
80-
// @frankie correct if im wrong here
8184
seed: this.#seed,
8285
type,
8386
admin,
8487
}
8588

86-
8789
Object.keys(accounts)
8890
.concat(ACCOUNTS)
8991
.forEach((key) => {

src/registration/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { Signer } from '../keys/types/internal'
66
import { Address } from '../types/internal'
77

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

typedoc.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414

1515
tsconfig: './tsconfig.json',
1616
excludePrivate: true,
17-
excludeInternal: true,
17+
// excludeInternal: true,
1818
validation: {
1919
notExported: true,
2020
invalidLink: true,

0 commit comments

Comments
 (0)