How to use eosjs - 10 common examples

To help you get started, we’ve selected a few eosjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eosdac / eosdac-api / deferred_watcher / eosdac-deferred-handler.js View on Github external
const data_sb = new Serialize.SerialBuffer({
                                textEncoder: new TextEncoder,
                                textDecoder: new TextDecoder,
                                array: row.data
                            })
                            const data = type.deserialize(data_sb)


                            if (this.interested(data[1].sender) || (data[1].sender === '.............' && this.interested(data[1].payer))){
                                // console.log(row)
                                // console.log(data[1].sender_id)
                                const actor = (data[1].sender === '.............')?data[1].payer:data[1].sender;

                                const packed = Serialize.hexToUint8Array(data[1].packed_trx)
                                const type_trx = types.get('transaction')
                                const sb_trx = new Serialize.SerialBuffer({
                                    textEncoder: new TextEncoder,
                                    textDecoder: new TextDecoder,
                                    array: packed
                                })
                                const data_trx = type_trx.deserialize(sb_trx)
                                delete data_trx.max_cpu_usage_ms
                                delete data_trx.max_net_usage_words
                                delete data_trx.ref_block_num
                                delete data_trx.ref_block_prefix
                                delete data_trx.context_free_actions
                                delete data_trx.transaction_extensions

                                var trx_id = crypto.createHash('sha256').update(packed).digest('hex');

                                data_trx.actions = await this.api.deserializeActions(data_trx.actions)
github eosdac / eosdac-api / connection.js View on Github external
deserialize(type, array) {
        const buffer = new Serialize.SerialBuffer({textEncoder: new TextEncoder, textDecoder: new TextDecoder, array});
        let result = Serialize.getType(this.types, type).deserialize(buffer, new Serialize.SerializerState({bytesAsUint8Array: true}));
        if (buffer.readPos !== array.length)
            throw new Error('oops: ' + type); // todo: remove check
        // {
        //     console.log(result.actions[0].authorization[0].actor);
        //     //console.log('oops: ' + type);
        // }
        return result;
    }
github EOSIO / eosio-webauthn-example-app / src / server / server.ts View on Github external
if (unloadedModule)
        return;
    // console.log(k);
    // console.log(JSON.stringify(JSON.parse(textDecoder.decode(Serialize.hexToUint8Array(k.clientDataJSON))), null, 4));
    const att = await (cbor as any).decodeFirst(Serialize.hexToUint8Array(k.attestationObject));
    // console.log(att);
    // console.log(Serialize.arrayToHex(new Uint8Array(att.authData.buffer)));
    const data = new DataView(att.authData.buffer);
    let pos = 30;   // skip unknown
    pos += 32;      // RP ID hash
    const flags = data.getUint8(pos++);
    const signCount = data.getUint32(pos);
    pos += 4;
    if (!(flags & AttestationFlags.attestedCredentialPresent))
        throw new Error('attestedCredentialPresent flag not set');
    const aaguid = Serialize.arrayToHex(new Uint8Array(data.buffer, pos, 16));
    pos += 16;
    const credentialIdLength = data.getUint16(pos);
    pos += 2;
    const credentialId = new Uint8Array(data.buffer, pos, credentialIdLength);
    pos += credentialIdLength;
    const pubKey = await (cbor as any).decodeFirst(new Uint8Array(data.buffer, pos));
    if (Serialize.arrayToHex(credentialId) !== k.id)
        throw new Error('Credential ID does not match');
    if (pubKey.get(1) !== 2)
        throw new Error('Public key is not EC2');
    if (pubKey.get(3) !== -7)
        throw new Error('Public key is not ES256');
    if (pubKey.get(-1) !== 1)
        throw new Error('Public key has unsupported curve');
    const x = pubKey.get(-2);
    const y = pubKey.get(-3);
github bagaking / eosplayer / src / types / libs.ts View on Github external
import * as debug from 'debug';
import * as EosLib from 'eosjs';
const { ecc } = EosLib.modules;

export const Eos = EosLib;
export const Ecc = ecc;
export const Debug = debug;
//
// console.log("Eos", Eos)
// console.log("Ecc", Ecc)
// console.log("Debug", Debug)
github eosdac / eosdac-api / connection.js View on Github external
deserialize(type, array) {
        const buffer = new Serialize.SerialBuffer({textEncoder: new TextEncoder, textDecoder: new TextDecoder, array});
        let result = Serialize.getType(this.types, type).deserialize(buffer, new Serialize.SerializerState({bytesAsUint8Array: true}));
        if (buffer.readPos !== array.length)
            throw new Error('oops: ' + type); // todo: remove check
        // {
        //     console.log(result.actions[0].authorization[0].actor);
        //     //console.log('oops: ' + type);
        // }
        return result;
    }
github eosdac / eosdac-api / deferred_watcher / eosdac-deferred-handler.js View on Github external
for (const row of delta[1].rows) {
                            const type = types.get(delta[1].name)
                            const data_sb = new Serialize.SerialBuffer({
                                textEncoder: new TextEncoder,
                                textDecoder: new TextDecoder,
                                array: row.data
                            })
                            const data = type.deserialize(data_sb)


                            if (this.interested(data[1].sender) || (data[1].sender === '.............' && this.interested(data[1].payer))){
                                // console.log(row)
                                // console.log(data[1].sender_id)
                                const actor = (data[1].sender === '.............')?data[1].payer:data[1].sender;

                                const packed = Serialize.hexToUint8Array(data[1].packed_trx)
                                const type_trx = types.get('transaction')
                                const sb_trx = new Serialize.SerialBuffer({
                                    textEncoder: new TextEncoder,
                                    textDecoder: new TextDecoder,
                                    array: packed
                                })
                                const data_trx = type_trx.deserialize(sb_trx)
                                delete data_trx.max_cpu_usage_ms
                                delete data_trx.max_net_usage_words
                                delete data_trx.ref_block_num
                                delete data_trx.ref_block_prefix
                                delete data_trx.context_free_actions
                                delete data_trx.transaction_extensions

                                var trx_id = crypto.createHash('sha256').update(packed).digest('hex');
github EOSIO / eosio-webauthn-example-app / src / server / server.ts View on Github external
async function decodeKey(k: AddKeyArgs): Promise {
    // todo: check RP ID hash
    // todo: check signature
    if (unloadedModule)
        return;
    // console.log(k);
    // console.log(JSON.stringify(JSON.parse(textDecoder.decode(Serialize.hexToUint8Array(k.clientDataJSON))), null, 4));
    const att = await (cbor as any).decodeFirst(Serialize.hexToUint8Array(k.attestationObject));
    // console.log(att);
    // console.log(Serialize.arrayToHex(new Uint8Array(att.authData.buffer)));
    const data = new DataView(att.authData.buffer);
    let pos = 30;   // skip unknown
    pos += 32;      // RP ID hash
    const flags = data.getUint8(pos++);
    const signCount = data.getUint32(pos);
    pos += 4;
    if (!(flags & AttestationFlags.attestedCredentialPresent))
        throw new Error('attestedCredentialPresent flag not set');
    const aaguid = Serialize.arrayToHex(new Uint8Array(data.buffer, pos, 16));
    pos += 16;
    const credentialIdLength = data.getUint16(pos);
    pos += 2;
    const credentialId = new Uint8Array(data.buffer, pos, credentialIdLength);
    pos += credentialIdLength;
github eosiosg / pomelo / Api.js View on Github external
console.log( this.accountPublicKey );
        let nodeAddress = 'http://52.77.224.13:8888';
        config = {
            keyProvider: this.accountPrivateKey, // WIF string or array of keys..
            httpEndpoint: nodeAddress,
//    mockTransactions: () => 'pass', // or 'fail'
//    transactionHeaders: (expireInSeconds, callback) => {
//      callback(null/*error*/, headers)
//    },
            expireInSeconds: 60,
            broadcast: true,
            debug: false,
            sign: true,
          chainId: '706a7ddd808de9fc2b8879904f3b392256c83104c1d544b38302cc07d9fca477',
        };
        this.eos = Eos.Testnet( config );
        console.log( this.eos );
    }
github EOSIO / demux-js-eos / src / v1.7 / readers / state-history / StateHistoryPostgresBlock.ts View on Github external
import fetch from 'node-fetch'
import { TextDecoder, TextEncoder } from 'util'
import { EosAction, TransactionActions } from '../../interfaces'
import { StateHistoryPostgresAbiProvider } from './StateHistoryPostgresAbiProvider'

// Wrapper to deal with differences between the definitions of fetch for the browser built-in
// and the node-fetch polyfill for node
// Is there a better way to do this?
const fetchWrapper = (input?: string | Request, init?: RequestInit): Promise => {
  const anyInput = input as any
  const anyInit = init as any
  return fetch(anyInput, anyInit) as any
}

const signatureProvider = new JsSignatureProvider([])
const rpc = new JsonRpc('', { fetch: fetchWrapper } )
const abiProvider = new StateHistoryPostgresAbiProvider()
const api = new Api({
  rpc,
  abiProvider,
  signatureProvider,
  textDecoder: new TextDecoder(),
  textEncoder: new TextEncoder()
})

const getApi = (blockNumber: number, massiveInstance: any, dbSchema: string, log: Logger) => {
  const instanceAbiProvider = api.abiProvider as StateHistoryPostgresAbiProvider
  instanceAbiProvider.setState(blockNumber, massiveInstance, dbSchema, log)
  return api
}

export class StateHistoryPostgresBlock implements Block {
github EOSIO / demux-js-eos / src / v1.8 / readers / state-history / StateHistoryPostgresBlock.ts View on Github external
import fetch from 'node-fetch'
import { TextDecoder, TextEncoder } from 'util'
import { EosAction, TransactionActions } from '../../'
import { StateHistoryPostgresAbiProvider } from './StateHistoryPostgresAbiProvider'

// Wrapper to deal with differences between the definitions of fetch for the browser built-in
// and the node-fetch polyfill for node
// Is there a better way to do this?
const fetchWrapper = (input?: string | Request, init?: RequestInit): Promise => {
  const anyInput = input as any
  const anyInit = init as any
  return fetch(anyInput, anyInit) as any
}

const signatureProvider = new JsSignatureProvider([])
const rpc = new JsonRpc('', { fetch: fetchWrapper } )
const abiProvider = new StateHistoryPostgresAbiProvider()
const api = new Api({
  rpc,
  abiProvider,
  signatureProvider,
  textDecoder: new TextDecoder(),
  textEncoder: new TextEncoder()
})

const getApi = (blockNumber: number, massiveInstance: any, dbSchema: string, log: Logger) => {
  const instanceAbiProvider = api.abiProvider as StateHistoryPostgresAbiProvider
  instanceAbiProvider.setState(blockNumber, massiveInstance, dbSchema, log)
  return api
}

export class StateHistoryPostgresBlock implements Block {