Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bloks/wallet

Package Overview
Dependencies
Maintainers
1
Versions
202
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bloks/wallet - npm Package Compare versions

Comparing version 3.3.11 to 3.3.16

src/actions.js

7

package.json
{
"name": "@bloks/wallet",
"version": "3.3.11",
"version": "3.3.16",
"description": "",

@@ -13,5 +13,6 @@ "publishConfig": {

"dependencies": {
"@bloks/constants": "^3.3.11"
"@bloks/constants": "^3.3.16",
"store": "^2.0.12"
},
"gitHead": "4bc758a6a1c259ba98a81fde5b400941160dd098"
"gitHead": "83ca5d74d8318447f5fe8449a868eac2c59cd466"
}

@@ -1,586 +0,11 @@

import { constants } from '@bloks/constants'
import * as Actions from './actions'
import * as Callbacks from './callbacks'
import Provider from './provider'
import User from './users'
const defaultCallbacks = () => ({
onLoginToSign: ({ wallet, actions }) => {},
clearErrors: () => {},
getUser: () => { throw new Error('No User Found') },
onSuccess: (success) => { console.log('Success', success) },
onError: (error) => { throw new Error(error) },
onMultisig: (actions) => { return false },
isMultisigMode: () => { return false}
})
export default class EosWallet {
constructor(callbacks) {
this.callbacks = Object.assign(defaultCallbacks(), callbacks)
}
setProvider (provider) {
this.provider = provider
}
static isEosjs1 () {
const { wallet } = this.callbacks.getUser()
return this.callbacks.isMultisigMode() &&
['ScatterExtension', 'eostock'].includes(wallet)
}
/**
* General purpose transaction
*/
async transact (actions) {
this.callbacks.clearErrors()
// Get User
const {
actor,
permission,
wallet,
delay_sec
} = this.callbacks.getUser()
// Create authorization
const authorization = [{ actor, permission }]
// Check that wallet exists
if (!wallet) {
this.setError('Please log in first.')
return
}
// Check that provider exists and has transact
if (!this.provider || !this.provider.transact) {
console.log(`Provider not found: ${!this.provider}`)
this.callbacks.onLoginToSign({
wallet,
actions
})
return
}
// Add auth to all actions
actions = actions.map(action => {
action.authorization = authorization
return action
})
// Fetch ABI into cache if needed (EOSJS1)
if (this.provider && this.provider.fc && this.provider.fc.abiCache) {
for (const account of [...new Set(actions.map(action => action.account))]) {
await this.provider.fc.abiCache.abiAsync(account)
}
}
// MULTISIG (Msig)
if (this.callbacks.isMultisigMode()) {
const endTx = this.callbacks.onMultisig(actions)
if (endTx) {
return
}
}
// Standard TX
try {
let obj1 = {
delay_sec: delay_sec,
actions: actions
}
let obj2 = {
blocksBehind: 12,
expireSeconds: 3600,
broadcast: true
}
/**
* Special need to check for scatter, as transact is different for different EOSJS
*/
console.log(wallet, obj1, obj2)
const success = await this.provider.transact(obj1, obj2)
this.callbacks.onSuccess(success)
} catch (e) {
console.log(e.message || e.toString() || e)
this.callbacks.onError(
e.reason || e.message || e.toString() || e
)
}
}
/**
* Transfer function using standard system contract
*/
transfer (contract, from, to, quantity, memo) {
let actions = [{
account: contract,
name: 'transfer',
data: {
from,
to,
quantity,
memo
}
}]
return this.transact(actions)
}
/**
* Stake CPU and NET
*/
delegatebw (from, receiver, stake_net_quantity, stake_cpu_quantity, transfer) {
/** the below fix is for eosjs1 */
if (this.isEosjs1) {
transfer = +transfer
}
let actions = [this._delegatebw(from, receiver, stake_net_quantity, stake_cpu_quantity, transfer)]
return this.transact(actions)
}
_delegatebw (from, receiver, stake_net_quantity, stake_cpu_quantity, transfer) {
return {
account: constants.EOSIO,
name: 'delegatebw',
data: {
from,
receiver,
stake_net_quantity,
stake_cpu_quantity,
transfer
}
}
}
/**
* Unstake CPU and NET
*/
undelegatebw (from, receiver, unstake_net_quantity, unstake_cpu_quantity) {
let actions = [this._undelegatebw(from, receiver, unstake_net_quantity, unstake_cpu_quantity)]
return this.transact(actions)
}
_undelegatebw (from, receiver, unstake_net_quantity, unstake_cpu_quantity) {
return {
account: constants.EOSIO,
name: 'undelegatebw',
data: {
from,
receiver,
unstake_net_quantity,
unstake_cpu_quantity
}
}
}
/**
* Buy RAM
*/
buyram (payer, receiver, quant) {
let actions = [{
account: constants.EOSIO,
name: 'buyram',
data: {
payer,
receiver,
quant
}
}]
return this.transact(actions)
}
/**
* Buy RAM Bytes
*/
buyrambytes (payer, receiver, bytes) {
let actions = [this._buyrambytes(payer, receiver, bytes)]
return this.transact(actions)
}
_buyrambytes (payer, receiver, bytes) {
return {
account: constants.EOSIO,
name: 'buyrambytes',
data: {
payer,
receiver,
bytes
}
}
}
/**
* Sell RAM
*/
sellram (account, bytes) {
let actions = [{
account: constants.EOSIO,
name: 'sellram',
data: {
account,
bytes
}
}]
return this.transact(actions)
}
/**
* Custom refund
*/
refund (owner) {
let actions = [{
account: constants.EOSIO,
name: 'refund',
data: {
owner
}
}]
return this.transact(actions)
}
/**
* Add gravatar
*/
addgravatar (account_name, display_name, image_url, telegram) {
let actions = [{
account: constants.ACCOUNT_INFO,
name: 'update',
data: {
account_name,
title: display_name,
avatar: image_url,
desc: '',
modifier: account_name,
url: telegram
? `{"telegram":"${telegram}"`
: ''
}
}]
return this.transact(actions)
}
/**
* Change Basic (Owner and Active Keys) of an account
*/
changeBasicPermissions (account, newActiveKey, newOwnerKey) {
let actions = []
if (newActiveKey && newActiveKey !== '') {
actions.push(this._updateauthkey(account, 'active', 'owner', newActiveKey))
}
if (newOwnerKey && newOwnerKey !== '') {
actions.push(this._updateauthkey(account, 'owner', '', newOwnerKey))
}
return this.transact(actions)
}
/**
* Update auth action creator
*/
_updateauthkey (account, permission, parent, key) {
return {
account: constants.EOSIO,
name: 'updateauth',
data: {
account,
permission,
parent,
auth: {
threshold: 1,
keys: [{
key: key,
weight: 1
}],
accounts: [],
waits: []
}
}
}
}
/**
* Update auth
*/
updateAuth (account, perm_name, parent, required_auth) {
let actions = [{
account: constants.EOSIO,
name: 'updateauth',
data: {
account: account,
permission: perm_name,
parent: parent,
auth: required_auth
}
}]
return this.transact(actions)
}
/**
* New account
*/
_newaccount (creator, name, ownerKey, activeKey) {
return {
account: constants.EOSIO,
name: 'newaccount',
data: {
creator,
name,
owner: {
threshold: 1,
keys: [{
key: ownerKey,
weight: 1
}],
accounts: [],
waits: []
},
active: {
threshold: 1,
keys: [{
key: activeKey,
weight: 1
}],
accounts: [],
waits: []
}
}
}
}
/**
* Create Account
*/
createAccount (creator, name, ownerKey, activeKey, bytes, stake_net_quantity, stake_cpu_quantity, transfer) {
/** the below fix is for eosjs1 */
if (this.isEosjs1) {
transfer = +transfer
}
let actions = [
this._newaccount(creator, name, ownerKey, activeKey),
this._buyrambytes(creator, name, bytes),
this._delegatebw(creator, name, stake_net_quantity, stake_cpu_quantity, transfer)
]
return this.transact(actions)
}
/**
* Vote producers
*/
voteproducer (voter, proxy, producers) {
let actions = [{
account: constants.EOSIO,
name: 'voteproducer',
data: {
voter,
proxy,
producers
}
}]
return this.transact(actions)
}
/**
* Link and unlink auth
*/
linkAuth (account, contractName, contractAction, permission) {
let actions = [{
account: constants.EOSIO,
name: 'linkauth',
data: {
account: account,
code: contractName,
type: contractAction,
requirement: permission
}
}]
return this.transact(actions)
}
unlinkAuth (account, contractName, contractAction) {
let actions = [{
account: constants.EOSIO,
name: 'unlinkauth',
data: {
account: account,
code: contractName,
type: contractAction
}
}]
return this.transact(actions)
}
/**
* Delete auth
*/
deleteAuth (account, permission) {
let actions = [{
account: constants.EOSIO,
name: 'deleteauth',
data: {
account: account,
permission: permission
}
}]
return this.transact(actions)
}
/**
* Cancel deferred actions
*/
cancelDelay (actor, permission, trx_id) {
let actions = [{
account: constants.EOSIO,
name: 'canceldelay',
data: {
canceling_auth: {
actor: actor,
permission: permission
},
trx_id: trx_id
}
}]
return this.transact(actions)
}
/**
* Create or delete proxies (create is true, delete is false)
*/
updateProxy (account, createOrDelete) {
/** the below fix is for eosjs1 */
if (this.isEosjs1) {
createOrDelete = +createOrDelete
}
let actions = [{
account: constants.EOSIO,
name: 'regproxy',
data: {
proxy: account,
isproxy: createOrDelete
}
}]
return this.transact(actions)
}
/**
* Vote referendum (yes is 1, no is 0)
*/
voteReferendum (account, referendumName, vote) {
let actions = [{
account: constants.EOSFORUM,
name: 'vote',
data: {
vote_json: '',
voter: account,
proposal_name: referendumName,
vote: vote
}
}]
return this.transact(actions)
}
/**
* Set Code
*/
_setCode (account, code) {
return {
account: constants.EOSIO,
name: 'setcode',
data: {
account,
vmtype: 0,
vmversion: 0,
code
}
}
}
/**
* Set ABI
*/
_setAbi (account, abi) {
return {
account: constants.EOSIO,
name: 'setabi',
data: {
account,
abi
}
}
}
/**
* Multisig
*/
propose (proposer, proposal_name, requested, trx) {
let actions = [{
account: constants.EOSIO_MSIG,
name: 'propose',
data: {
proposer,
proposal_name,
requested,
trx
}
}]
return this.transact(actions)
}
approve (proposer, proposal_name, level) {
let actions = [{
account: constants.EOSIO_MSIG,
name: 'approve',
data: {
proposer,
proposal_name,
level
}
}]
return this.transact(actions)
}
execute (proposer, proposal_name, executer) {
let actions = [{
account: constants.EOSIO_MSIG,
name: 'exec',
data: {
proposer,
proposal_name,
executer
}
}]
return this.transact(actions)
}
bidname (bidder, newname, bid) {
let actions = [{
account: constants.EOSIO,
name: 'bidname',
data: {
bidder,
newname,
bid
}
}]
return this.transact(actions)
}
}
export default {
...Callbacks,
...Actions,
Provider,
User
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc