How to use the eosjs.Serialize.SerialBuffer function in eosjs

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 CoinageCrypto / lamington / src / contracts / contractDeployer.ts View on Github external
public static async deployToAccount(
		contractIdentifier: string,
		account: Account
	) {
		EOSManager.addSigningAccountIfMissing(account);

		// Initialize the serialization buffer
		const buffer = new Serialize.SerialBuffer({
			textEncoder: EOSManager.api.textEncoder,
			textDecoder: EOSManager.api.textDecoder,
		});
		// Construct resource paths
		const abiPath = path.join(
			ConfigManager.outDir,
			'compiled_contracts',
			`${contractIdentifier}.abi`
		);

		if (!(await exists(abiPath))) {
			throw new Error(
				`Couldn't find ABI at ${abiPath}. Are you sure you used the correct contract identifier?`
			);
		}
github EOSIO / eosio-explorer / packages / api-eosio-compiler / service-logic.js View on Github external
async function deployContract(blockchainUrl, account_name, private_key, permission, wasm_path, abi_path){
  if(blockchainUrl.indexOf("http://") < 0)
  {
    blockchainUrl = "http://" + blockchainUrl;
  }

  const rpc = new JsonRpc(blockchainUrl, { fetch });
  const signatureProvider = new JsSignatureProvider([private_key]);
  const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });

  const buffer = new Serialize.SerialBuffer({
    textEncoder: api.textEncoder,
    textDecoder: api.textDecoder,
  });

  const wasm = fs.readFileSync(wasm_path).toString('hex');
  let abi = JSON.parse(fs.readFileSync(abi_path, 'utf8'));

  const abiDefinition = api.abiTypes.get('abi_def');
  // need to make sure abi has every field in abiDefinition.fields
  // otherwise serialize throws error
  abi = abiDefinition.fields.reduce(
      (acc, { name: fieldName }) => Object.assign(acc, { [fieldName]: acc[fieldName] || [] }),
      abi,
  );
  abiDefinition.serialize(buffer, abi);
github EOSIO / eosio-webauthn-example-app / src / server / server.ts View on Github external
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);
    if (x.length !== 32 || y.length !== 32)
        throw new Error('Public key has invalid X or Y size');
    const ser = new Serialize.SerialBuffer({textEncoder: new util.TextEncoder(), textDecoder: new util.TextDecoder()});
    ser.push((y[31] & 1) ? 3 : 2);
    ser.pushArray(x);
    ser.push(flagsToPresence(flags));
    ser.pushString(k.rpid);
    const compact = ser.asUint8Array();
    const key = Numeric.publicKeyToString({
        type: Numeric.KeyType.wa,
        data: compact,
    });
    console.log({
        flags: ('00' + flags.toString(16)).slice(-2),
        signCount,
        aaguid,
        credentialIdLength,
        credentialId: Serialize.arrayToHex(credentialId),
        rpid: k.rpid,
github eosdac / eosdac-api / connection.js View on Github external
serialize(type, value) {
        const buffer = new Serialize.SerialBuffer({textEncoder: new TextEncoder, textDecoder: new TextDecoder});
        Serialize.getType(this.types, type).serialize(buffer, value);
        return buffer.asUint8Array();
    }
github EOSIO / eosio-webauthn-example-app / src / client / wasig.ts View on Github external
public async sign(
        { chainId, requiredKeys, serializedTransaction, serializedContextFreeData }: ApiInterfaces.SignatureProviderArgs,
    ) {
        const signBuf = new Serialize.SerialBuffer();
        signBuf.pushArray(Serialize.hexToUint8Array(chainId));
        signBuf.pushArray(serializedTransaction);
        if (serializedContextFreeData)
            signBuf.pushArray(new Uint8Array(await crypto.subtle.digest('SHA-256', serializedContextFreeData.buffer)));
        else
            signBuf.pushArray(new Uint8Array(32));
        const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', signBuf.asUint8Array().slice().buffer));

        const signatures = [] as string[];
        for (const key of requiredKeys) {
            const id = Serialize.hexToUint8Array(this.keys.get(key));
            const assertion = await (navigator as any).credentials.get({
                publicKey: {
                    timeout: 60000,
                    allowCredentials: [{
                        id,
github EOSIO / eosio-reference-chrome-extension-authenticator-app / src / utils / manifest / AssertActionCreator.ts View on Github external
private getChainHash(params: AssertActionParams): string {
    const { dappInfo: { appMetadataInfo: { appMetadata } }, transactionBundle: { requestEnvelope } } = params
    const { chainId } = requestEnvelope.request.transactionSignature
    const chainInfo = appMetadata.chains.find((chain) => chain.chainId === chainId)
    const [, hash] = this.splitHashFromURL(chainInfo.icon)
    const chainInfoUp = {
      icon: hash,
      chain_id: chainInfo.chainId,
      chain_name: chainInfo.chainName,
    }

    const buffer = new Serialize.SerialBuffer({ textEncoder: new TextEncoder(), textDecoder: new TextDecoder() })
    const chainKey = 'setchain'
    this.api.serialize(buffer, chainKey, chainInfoUp)
    const serializedChainInfo = buffer.asUint8Array()

    const chainHash = sha256().update(serializedChainInfo).digest('hex')

    return chainHash
  }