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

0.2.0 - Release #20

Merged
merged 26 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
868f5b4
Removal of the beforeBroadcast hook.
aaroncox Jan 10, 2023
731246a
Added default esrOptions to the TransactContext
aaroncox Jan 10, 2023
33a335e
Renamed Context `session` to `permissionLevel`
aaroncox Jan 11, 2023
0e67581
Renamed getters to be more specific
aaroncox Jan 11, 2023
d5e41b1
Added getters to the TransactContext
aaroncox Jan 11, 2023
034d1e1
Deduplicating code by adding a helper function
aaroncox Jan 11, 2023
624610b
Added the ABICache and implemented in the TransactContext
aaroncox Jan 13, 2023
9339d33
Removed unused import
aaroncox Jan 13, 2023
dac6ae6
Allow specifying `expireSeconds` throughout the stack
aaroncox Jan 15, 2023
828d37a
An ENV variable to dump http request traffic for debugging
aaroncox Jan 15, 2023
823b2b3
Add creation of a wharfkitnoop account for cosigning tests
aaroncox Jan 15, 2023
b9229aa
Ignore any local notes
aaroncox Jan 16, 2023
ed067fb
Refector TransactContext and ABICache
aaroncox Jan 16, 2023
bcb77a8
Allow context to resolve transactions (ease for developers)
aaroncox Jan 16, 2023
6b8e833
Retain a revision history of request modifications in the TransactResult
aaroncox Jan 17, 2023
d6a2085
Removed unused import
aaroncox Jan 17, 2023
1b4fe0d
Fix for nodejs v14
aaroncox Jan 17, 2023
dd61225
Manually clone incoming SigningRequest
aaroncox Jan 17, 2023
373181d
Migrate plugin tests into new suite
aaroncox Jan 17, 2023
7d1e7f6
Split cloneRequest into its own function
aaroncox Jan 17, 2023
15cf193
Added and implemented updateRequest method
aaroncox Jan 17, 2023
9a1c437
Syntax
aaroncox Jan 17, 2023
8185dfb
Adding an appendAction and prependAction helper
aaroncox Jan 17, 2023
4b8b5ef
Finished testing resolve
aaroncox Jan 17, 2023
c059c4c
Fixed browser test runner
aaroncox Jan 17, 2023
81f8bbd
Allow either actor + permission or permissionLevel during Session ins…
aaroncox Jan 17, 2023
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
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