Skip to content

Commit

Permalink
0.2.0 - Release (#20)
Browse files Browse the repository at this point in the history
* Removal of the beforeBroadcast hook.

Resolves #13.

After discussions with other developers, it became clear that the `afterSign` and `beforeBroadcast` hooks currently serve the same function. To simplify the approach developers can take for plugin development, the `beforeBroadcast` hook was removed, and if required, can be added back at a later date.

* Added default esrOptions to the TransactContext

Resolves #15.

This gives developers a default set of options when creating ESR requests.

* Renamed Context `session` to `permissionLevel`

* Renamed getters to be more specific

Motivation was that I imagine we'll want the `.account` getter to return an Account Kit instance.

* Added getters to the TransactContext

* Deduplicating code by adding a helper function

* Added the ABICache and implemented in the TransactContext

* Removed unused import

* Allow specifying `expireSeconds` throughout the stack

Resolves #22

* An ENV variable to dump http request traffic for debugging

* Add creation of a wharfkitnoop account for cosigning tests

* Ignore any local notes

* Refector TransactContext and ABICache

* Allow context to resolve transactions (ease for developers)

* Retain a revision history of request modifications in the TransactResult

This will

* Removed unused import

* Fix for nodejs v14

Cannot use the at method in older nodejs versions

* Manually clone incoming SigningRequest

This is to preserve all data and override the zlib/abiProvider values.

* Migrate plugin tests into new suite

* Split cloneRequest into its own function

* Added and implemented updateRequest method

Resolves #18.

This new update method ensures the metadata from the original request will persist through modification by a `beforeSign` plugin.

The original metadata will take precedent over metadata from the new request, ensuring no plugin upstream can overwrite it. A warning will be displayed when this happens to let the developer know.

* Syntax

* Adding an appendAction and prependAction helper

* Finished testing resolve

* Fixed browser test runner

* Allow either actor + permission or permissionLevel during Session instantiation

Fixes #17
  • Loading branch information
aaroncox authored Jan 17, 2023
1 parent 83b598d commit 26f4dea
Show file tree
Hide file tree
Showing 27 changed files with 1,231 additions and 350 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
lib/
build/
build/
notes.md
33 changes: 33 additions & 0 deletions src/abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {ABI, API, APIClient, Name} from '@greymass/eosio'
import {AbiProvider} from 'eosio-signing-request'

/**
* Given an APIClient instance, this class provides an AbiProvider interface for retrieving and caching ABIs.
*/
export class ABICache implements AbiProvider {
public readonly cache: Map<string, ABI> = new Map()
public readonly pending: Map<string, Promise<API.v1.GetAbiResponse>> = new Map()

constructor(public readonly client: APIClient) {}

public async getAbi(account: Name): Promise<ABI> {
const key = String(account)
let record = this.cache.get(key)
if (!record) {
let getAbi = this.pending.get(key)
if (!getAbi) {
getAbi = this.client.v1.chain.get_abi(account)
this.pending.set(key, getAbi)
}
const response = await getAbi
this.pending.delete(key)
if (response.abi) {
record = ABI.from(response.abi)
this.cache.set(key, record)
} else {
throw new Error(`ABI for ${key} could not be loaded.`)
}
}
return record
}
}
2 changes: 2 additions & 0 deletions src/index-module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export * from './abi'
export * from './kit'
export * from './plugins'
export * from './session'
export * from './transact'
export * from './types'
28 changes: 21 additions & 7 deletions src/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import {
PermissionLevelType,
} from '@greymass/eosio'

import {ChainDefinition, ChainDefinitionType, Fetch} from './types'

import {
AbstractTransactPlugin,
BaseTransactPlugin,
Session,
SessionOptions,
TransactPlugin,
TransactPluginsOptions,
WalletPlugin,
WalletPluginContext,
WalletPluginLoginOptions,
} from './session'
import {
AbstractTransactPlugin,
BaseTransactPlugin,
TransactPlugin,
TransactPluginsOptions,
} from './transact'
import {ChainDefinition, ChainDefinitionType, Fetch} from './types'

export enum LoginHookTypes {
beforeLogin = 'beforeLogin',
Expand Down Expand Up @@ -96,6 +98,7 @@ export interface LoginOptions {
export interface SessionKitOptions {
appName: NameType
chains: ChainDefinitionType[]
expireSeconds?: number
fetch?: Fetch
loginPlugins?: LoginPlugin[]
transactPlugins?: TransactPlugin[]
Expand All @@ -109,6 +112,7 @@ export interface SessionKitOptions {
export class SessionKit {
readonly appName: Name
readonly chains: ChainDefinition[]
readonly expireSeconds: number = 120
readonly fetch?: Fetch
readonly loginPlugins: AbstractLoginPlugin[]
readonly transactPlugins: AbstractTransactPlugin[]
Expand All @@ -119,6 +123,10 @@ export class SessionKit {
// Store options passed on the kit
this.appName = Name.from(options.appName)
this.chains = options.chains.map((chain) => ChainDefinition.from(chain))
// Override default expireSeconds for all sessions if specified
if (options.expireSeconds) {
this.expireSeconds = options.expireSeconds
}
// Override fetch if provided
if (options.fetch) {
this.fetch = options.fetch
Expand Down Expand Up @@ -168,17 +176,23 @@ export class SessionKit {
const chain = this.chains[0]
const context: SessionOptions = {
chain,
expireSeconds: this.expireSeconds,
fetch: this.fetch,
permissionLevel: 'eosio@active',
transactPlugins: options?.transactPlugins || this.transactPlugins,
transactPluginsOptions: options?.transactPluginsOptions || this.transactPluginsOptions,
walletPlugin: this.walletPlugins[0],
}

const walletContext: WalletPluginContext = {
chain,
permissionLevel: PermissionLevel.from('eosio@active'),
}

const walletOptions: WalletPluginLoginOptions = {
appName: this.appName,
chains: this.chains,
context,
context: walletContext,
}

// Allow overriding of the default wallet plugin by specifying one in the options
Expand Down
Loading

0 comments on commit 26f4dea

Please sign in to comment.