Skip to content

Commit

Permalink
Merge pull request #1 from apporc/apporc
Browse files Browse the repository at this point in the history
Support scatter desktop
  • Loading branch information
aaroncox authored Sep 5, 2023
2 parents 916d83c + e4d178d commit 2045d00
Show file tree
Hide file tree
Showing 7 changed files with 698 additions and 291 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# @wharfkit/wallet-plugin-template
# @wharfkit/wallet-plugin-scatter

A template to create a `WalletPlugin` for use within the `@wharfkit/session` library.
A Session Kit wallet plugin for the [Scatter](https://github.com/GetScatter/ScatterDesktop) wallet.

## Usage

- [Use this as a template.](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template)
- Write your wallet plugin's logic.
- Publish it on Github or npmjs.com
- Include it in your project and use it.
Include this wallet plugin while initializing the SessionKit.

**NOTE**: This wallet plugin will only work with the SessionKit and requires a browser-based environment.

```ts
import {WalletPluginScatter} from '@wharfkit/wallet-plugin-scatter'

const kit = new SessionKit({
// ... your other options
walletPlugins: [new WalletPluginScatter()],
})
```

## Developing

Expand Down
39 changes: 22 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "@wharfkit/wallet-plugin-template",
"description": "A template to create wallet plugins for use with @wharfkit/session.",
"version": "1.0.0",
"homepage": "https://github.com/wharfkit/wallet-plugin-template",
"name": "@wharfkit/wallet-plugin-scatter",
"description": "A WalletPlugin for the Scatter wallet for use within the @wharfkit/session.",
"version": "1.0.1",
"homepage": "https://github.com/wharfkit/wallet-plugin-scatter",
"license": "BSD-3-Clause",
"main": "lib/wallet-plugin-template.js",
"module": "lib/wallet-plugin-template.m.js",
"types": "lib/wallet-plugin-template.d.ts",
"type": "module",
"main": "lib/wallet-plugin-scatter.js",
"module": "lib/wallet-plugin-scatter.m.js",
"types": "lib/wallet-plugin-scatter.d.ts",
"sideEffects": false,
"files": [
"lib/*",
Expand All @@ -16,27 +17,31 @@
"prepare": "make"
},
"dependencies": {
"@scatterjs/core": "^2.7.48",
"@scatterjs/eosjs2": "^1.5.30",
"eosjs": "20.0.0",
"tslib": "^2.1.0"
},
"peerDependencies": {
"@wharfkit/session": "^1.0.0"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.4",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^14.1.0",
"@babel/runtime": "^7.22.6",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-replace": "^5.0.1",
"@rollup/plugin-typescript": "^10.0.1",
"@rollup/plugin-virtual": "^2.0.3",
"@rollup/plugin-typescript": "^11.1.3",
"@scatterjs/core": "^2.7.48",
"@scatterjs/eosjs2": "^1.5.30",
"@types/chai": "^4.3.1",
"@types/mocha": "^9.0.0",
"@types/node": "^18.7.18",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"@wharfkit/mock-data": "^1.0.2",
"@wharfkit/session": "^1.0.0",
"chai": "^4.3.4",
"crypto-js": "^4.1.1",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^4.0.0",
Expand All @@ -45,9 +50,9 @@
"node-fetch": "^2.6.1",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"rollup": "^2.70.2",
"rollup-plugin-dts": "^4.2.1",
"rollup-plugin-terser": "^7.0.2",
"rollup": "^3.28.1",
"rollup-plugin-dts": "^6.0.0",
"rollup-plugin-polyfill-node": "^0.12.0",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.1",
"typedoc": "^0.23.14",
Expand Down
41 changes: 37 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import fs from 'fs'
import dts from 'rollup-plugin-dts'
import typescript from '@rollup/plugin-typescript'
import commonjs from '@rollup/plugin-commonjs'
import nodePolyfills from 'rollup-plugin-polyfill-node'
import replace from '@rollup/plugin-replace'
import resolve from '@rollup/plugin-node-resolve'
import json from '@rollup/plugin-json'

import pkg from './package.json'
import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const pkg = require('./package.json')

const name = pkg.name
const license = fs.readFileSync('LICENSE').toString('utf-8').trim()
Expand All @@ -16,7 +23,7 @@ const banner = `
*/
`.trim()

const external = Object.keys(pkg.peerDependencies)
const external = [...Object.keys(pkg.peerDependencies)]

/** @type {import('rollup').RollupOptions} */
export default [
Expand All @@ -29,7 +36,20 @@ export default [
sourcemap: true,
exports: 'named',
},
plugins: [typescript({target: 'es6'})],
plugins: [
typescript({target: 'es6'}),
commonjs({
defaultIsModuleExports: false,
}),
nodePolyfills(),
replace({
preventAssignment: true,
'})(commonjsGlobal);': '})(deviceUuid$1);',
delimiters: ['', ''],
}),
resolve({browser: true}),
json(),
],
external,
},
{
Expand All @@ -40,7 +60,20 @@ export default [
format: 'esm',
sourcemap: true,
},
plugins: [typescript({target: 'es2020'})],
plugins: [
typescript({target: 'es2020'}),
commonjs({
defaultIsModuleExports: false,
}),
nodePolyfills(),
replace({
preventAssignment: true,
'})(commonjsGlobal)': '})(deviceUuid$1)',
delimiters: ['', ''],
}),
resolve({browser: true}),
json(),
],
external,
},
{
Expand Down
183 changes: 149 additions & 34 deletions src/index.ts

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {Struct} from '@wharfkit/antelope'

@Struct.type('scatter_account')
export class ScatterAccount extends Struct {
@Struct.field('authority') authority!: string
@Struct.field('blockchain') blockchain!: string
@Struct.field('chainId') chainId!: string
@Struct.field('isHardware') isHardware!: boolean
@Struct.field('name') name!: string
@Struct.field('publicKey') publicKey!: string
}
@Struct.type('scatter_identity')
export class ScatterIdentity extends Struct {
@Struct.field('accounts') accounts!: ScatterAccount[]
@Struct.field('hash') hash!: string
@Struct.field('name') name!: string
@Struct.field('publicKey') publicKey!: string
}
99 changes: 54 additions & 45 deletions test/tests/common.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
import {assert} from 'chai'
import {PermissionLevel, SessionKit} from '@wharfkit/session'
import {
mockChainDefinition,
mockPermissionLevel,
mockSessionKitArgs,
mockSessionKitOptions,
} from '@wharfkit/mock-data'

import {WalletPluginTEMPLATE} from '$lib'
import {WalletPluginScatter} from '$lib'
import {mockFetch} from '$test/utils/mock-fetch'
import {MockStorage} from '$test/utils/mock-storage'
import {MockUserInterface} from '$test/utils/mock-ui'

const mockChainDefinition = {
id: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
url: 'https://eos.greymass.com',
}

const mockPermissionLevel = PermissionLevel.from('wharfkit1111@test')

const mockSessionKitOptions = {
appName: 'unittests',
chains: [mockChainDefinition],
fetch: mockFetch, // Required for unit tests
storage: new MockStorage(),
ui: new MockUserInterface(),
walletPlugins: [new WalletPluginScatter()],
}

suite('wallet plugin', function () {
test('login and sign', async function () {
const kit = new SessionKit(
{
...mockSessionKitArgs,
walletPlugins: [new WalletPluginTEMPLATE()],
},
mockSessionKitOptions
)
const {session} = await kit.login({
chain: mockChainDefinition.id,
permissionLevel: mockPermissionLevel,
})
assert.isTrue(session.chain.equals(mockChainDefinition))
assert.isTrue(session.actor.equals(PermissionLevel.from(mockPermissionLevel).actor))
assert.isTrue(
session.permission.equals(PermissionLevel.from(mockPermissionLevel).permission)
)
const result = await session.transact(
{
action: {
authorization: [PermissionLevel.from(mockPermissionLevel)],
account: 'eosio.token',
name: 'transfer',
data: {
from: PermissionLevel.from(mockPermissionLevel).actor,
to: 'wharfkittest',
quantity: '0.0001 EOS',
memo: 'wharfkit/session wallet plugin template',
},
},
},
{
broadcast: false,
}
)
assert.isTrue(result.signer.equals(mockPermissionLevel))
assert.equal(result.signatures.length, 1)
})
this.timeout(120 * 1000)
this.slow(5 * 1000)

// test('login and sign', async function () {

// const kit = new SessionKit(mockSessionKitOptions)
// const { session } = await kit.login({
// chain: mockChainDefinition.id,
// permissionLevel: mockPermissionLevel,
// })
// assert.isTrue(session.chain.equals(mockChainDefinition))
// assert.isTrue(session.actor.equals(mockPermissionLevel.actor))
// assert.isTrue(session.permission.equals(mockPermissionLevel.permission))
// const result = await session.transact(
// {
// action: {
// authorization: [mockPermissionLevel],
// account: 'eosio.token',
// name: 'transfer',
// data: {
// from: mockPermissionLevel.actor,
// to: 'wharfkittest',
// quantity: '0.0001 EOS',
// memo: 'wharfkit/session wallet plugin template',
// },
// },
// },
// {
// broadcast: false,
// }
// )
// assert.isTrue(result.signer.equals(mockPermissionLevel))
// assert.equal(result.signatures.length, 1)
// })
})
Loading

0 comments on commit 2045d00

Please sign in to comment.