How to use the buffer/.Buffer.from function in buffer

To help you get started, we’ve selected a few buffer 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 node-a-team / ts-amino / src / binary-encode.ts View on Github external
// TODO: handling unpacked list https://github.com/tendermint/go-amino/blob/master/binary-encode.go#L409

        buf = Buffer.concat([
          buf,
          Buffer.from(
            encodeFieldNumberAndTyp3(
              field.fieldOptions.binFieldNum,
              typeToTyp3(finfo!.type, field.fieldOptions)
            )
          )
        ]);

        buf = Buffer.concat([
          buf,
          Buffer.from(
            encodeReflectBinary(codec, finfo, frv, field.fieldOptions, false)
          )
        ]);

        // TODO: ??? https://github.com/tendermint/go-amino/blob/master/binary-encode.go#L431
      }
  }

  if (bare) {
    return buf;
  }
  return Encoder.encodeByteSlice(buf);
}
github node-a-team / ts-amino / src / binary-encode.ts View on Github external
needDisamb = true;
  }
  // TODO: judge whether disamb is necessary https://github.com/tendermint/go-amino/blob/master/binary-encode.go#L211

  if (needDisamb) {
    buf = Buffer.concat([
      Buffer.alloc(1),
      Buffer.from(cinfo.concreteInfo.disamb)
    ]);
  }

  buf = Buffer.concat([buf, Buffer.from(cinfo.concreteInfo.prefix)]);

  buf = Buffer.concat([
    buf,
    Buffer.from(encodeReflectBinary(codec, cinfo, value, fopts, true))
  ]);

  if (bare) {
    return buf;
  }
  return Encoder.encodeByteSlice(buf);
}
github node-a-team / ts-amino / src / json-encode.ts View on Github external
codec: Codec,
  info: TypeInfo,
  value: any[],
  fopts: FieldOptions
): string {
  // if null
  if (!value || value.length === 0) {
    return "null";
  }

  // if type is byte array
  if (
    value instanceof Uint8Array ||
    (info.arrayOf && info.arrayOf.type === Type.Uint8)
  ) {
    return `"${Buffer.from(value).toString("base64")}"`;
  }

  if (!info.arrayOf) {
    throw new Error("should set a type of array element");
  }
  const etype = info.arrayOf!;
  const einfo: TypeInfo = {
    type: etype.type,
    arrayOf: etype.arrayOf
  };

  let result = "[";
  for (let i = 0; i < value.length; i++) {
    const v = value[i];
    result += encodeReflectJSON(codec, einfo, v, fopts);
    // Add a comma if it isn't the last item.
github aws-amplify / amplify-js / packages / amazon-cognito-identity-js / src / CognitoJwtToken.js View on Github external
decodePayload() {
    const payload = this.jwtToken.split('.')[1];
    try {
      return JSON.parse(Buffer.from(payload, 'base64').toString('utf8'));
    } catch (err) {
      return {};
    }
  }
}
github aws-amplify / amplify-js / packages / amazon-cognito-identity-js / es / CognitoUser.js View on Github external
authenticationHelper.generateHashDevice(dataAuthenticate.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey, dataAuthenticate.AuthenticationResult.NewDeviceMetadata.DeviceKey, function (errGenHash) {
        if (errGenHash) {
          return callback.onFailure(errGenHash);
        }

        var deviceSecretVerifierConfig = {
          Salt: Buffer.from(authenticationHelper.getSaltDevices(), 'hex').toString('base64'),
          PasswordVerifier: Buffer.from(authenticationHelper.getVerifierDevices(), 'hex').toString('base64')
        };

        _this8.verifierDevices = deviceSecretVerifierConfig.PasswordVerifier;
        _this8.deviceGroupKey = dataAuthenticate.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey;
        _this8.randomPassword = authenticationHelper.getRandomPassword();

        _this8.client.request('ConfirmDevice', {
          DeviceKey: dataAuthenticate.AuthenticationResult.NewDeviceMetadata.DeviceKey,
          AccessToken: _this8.signInUserSession.getAccessToken().getJwtToken(),
          DeviceSecretVerifierConfig: deviceSecretVerifierConfig,
          DeviceName: navigator.userAgent
        }, function (errConfirm, dataConfirm) {
          if (errConfirm) {
            return callback.onFailure(errConfirm);
          }
github aws-amplify / amplify-js / packages / amazon-cognito-identity-js / src / CognitoUser.js View on Github external
errGenHash => {
				if (errGenHash) {
					return callback.onFailure(errGenHash);
				}

				const deviceSecretVerifierConfig = {
					Salt: Buffer.from(
						authenticationHelper.getSaltDevices(),
						'hex'
					).toString('base64'),
					PasswordVerifier: Buffer.from(
						authenticationHelper.getVerifierDevices(),
						'hex'
					).toString('base64'),
				};

				this.verifierDevices = deviceSecretVerifierConfig.PasswordVerifier;
				this.deviceGroupKey = newDeviceMetadata.DeviceGroupKey;
				this.randomPassword = authenticationHelper.getRandomPassword();

				this.client.request(
					'ConfirmDevice',
					{
						DeviceKey: newDeviceMetadata.DeviceKey,
						AccessToken: this.signInUserSession.getAccessToken().getJwtToken(),
						DeviceSecretVerifierConfig: deviceSecretVerifierConfig,
						DeviceName: navigator.userAgent,
github aws-amplify / amplify-js / packages / aws-amplify-react-native / src / Interactions / ChatBot.js View on Github external
micText: MIC_BUTTON_TEXT.PASSIVE,
			},
			() => {
				setTimeout(() => {
					this.listItemsRef.current.scrollToEnd();
				}, 50);
			}
		);

		if (this.state.voice) {
			this.setState({
				voice: false,
			});

			const path = `${RNFS.DocumentDirectoryPath}/responseAudio.mp3`;
			const data = Buffer.from(response.audioStream).toString('base64');
			await RNFS.writeFile(path, data, 'base64');
			const speech = new Sound(path, '', async err => {
				if (!err) {
					speech.play(async () => {
						speech.release();
						RNFS.exists(path).then(res => {
							if (res) {
								RNFS.unlink(path);
							}
						});
						if (
							response.dialogState === 'ElicitSlot' &&
							this.props.conversationModeOn
						) {
							await this.startRecognizing();
						}