How to use the base64url.fromBase64 function in base64url

To help you get started, we’ve selected a few base64url 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 StrontiumJS / Framework / src / cryptography / drivers / node / AsymmetricJWTSigner.ts View on Github external
// JSONify the claim
        let stringifiedClaim = JSON.stringify(claim)
        let encodedClaim = encode(stringifiedClaim)

        let stringifiedHeader = JSON.stringify({
            alg: this.algorithmCode,
            typ: "JWT",
            kid: this.keyId,
        })
        let encodedHeader = encode(stringifiedHeader)

        let signature = await this.signer.sign(
            new Buffer(`${encodedHeader}.${encodedClaim}`)
        )

        return `${encodedHeader}.${encodedClaim}.${fromBase64(
            signature.toString("base64")
        )}`
    }
github mojaloop / sdk-standard-components / src / lib / ilp / index.js View on Github external
payer: quoteRequest.payer,
            amount: quoteResponse.transferAmount,
            transactionType: quoteRequest.transactionType,
            note: quoteResponse.note
        };

        const ilpData = Buffer.from(base64url(JSON.stringify(transactionObject)));
        const packetInput = {
            amount: this._getIlpCurrencyAmount(quoteResponse.transferAmount), // unsigned 64bit integer as a string
            account: this._getIlpAddress(quoteRequest.payee), // ilp address
            data: ilpData // base64url encoded attached data
        };

        const packet = ilpPacket.serializeIlpPayment(packetInput);

        let base64encodedIlpPacket = base64url.fromBase64(packet.toString('base64')).replace('"', '');

        let generatedFulfilment = this.caluclateFulfil(base64encodedIlpPacket).replace('"', '');
        let generatedCondition = this.calculateConditionFromFulfil(generatedFulfilment).replace('"', '');

        const ret = {
            fulfilment: generatedFulfilment,
            ilpPacket: base64encodedIlpPacket,
            condition: generatedCondition
        };

        this.logger.log(`Generated ILP: transaction object: ${util.inspect(transactionObject)}\nPacket input: ${util.inspect(packetInput)}\nOutput: ${util.inspect(ret)}`);

        return ret;
    }
github mojaloop / central-ledger / test / util / ilpExample.js View on Github external
const caluclateFulfil = (base64EncodedPacket, rawSecret) => {
  const encodedSecret = Buffer.from(rawSecret).toString('base64')

  const hmacsignature = Crypto.createHmac('sha256', Buffer.from(encodedSecret, 'ascii'))
    .update(Buffer.from(base64EncodedPacket, 'ascii'))

  const generatedFulfilment = hmacsignature.digest('base64')

  console.log(`calculateFulfil:: generatedFulfilment=${generatedFulfilment} | length:${generatedFulfilment.length}`)

  return base64url.fromBase64(generatedFulfilment)
}
github mojaloop / sdk-standard-components / src / lib / ilp / index.js View on Github external
caluclateFulfil(base64EncodedPacket) {
        var encodedSecret = Buffer.from(this.secret).toString('base64');

        var hmacsignature = Crypto.createHmac('sha256', new Buffer(encodedSecret, 'ascii'))
            .update(new Buffer(base64EncodedPacket, 'ascii'));

        var generatedFulfilment = hmacsignature.digest('base64');

        return base64url.fromBase64(generatedFulfilment);
    }
github mojaloop / sdk-standard-components / src / lib / ilp / index.js View on Github external
calculateConditionFromFulfil (fulfilment) {
        var preimage = base64url.toBuffer(fulfilment);
        
        if (preimage.length !== 32) {
            throw new Error('Interledger preimages must be exactly 32 bytes.');
        }
        
        var calculatedConditionDigest = this._sha256(preimage);
        return base64url.fromBase64(calculatedConditionDigest);
    }
github kenrick95 / c4bot / node_modules / botbuilder / node_modules / jsonwebtoken / node_modules / jws / node_modules / jwa / node_modules / ecdsa-sig-formatter / src / ecdsa-sig-formatter.js View on Github external
var dst = Buffer.allocUnsafe(rPadding + rLength + sPadding + sLength);

	for (offset = 0; offset < rPadding; ++offset) {
		dst[offset] = 0;
	}
	signature.copy(dst, offset, rOffset + Math.max(-rPadding, 0), rOffset + rLength);

	offset = paramBytes;

	for (var o = offset; offset < o + sPadding; ++offset) {
		dst[offset] = 0;
	}
	signature.copy(dst, offset, sOffset + Math.max(-sPadding, 0), sOffset + sLength);

	dst = dst.toString('base64');
	dst = base64Url(dst);

	return dst;
}
github expo / expo-cli / packages / dev-tools / server / DevToolsServer.js View on Github external
crypto.randomBytes(32, (error, buffer) => {
      if (error) reject(error);
      else resolve(base64url.fromBase64(buffer.toString('base64')));
    });
  });
github anvilresearch / jose / src / algs / HMAC-SHA-2.js View on Github external
sign (input, key) {
    //assertSufficientKeyLength(key)
    let {bitlength} = this
    let hmac = crypto.createHmac(`sha${bitlength}`, key)
    hmac.update(input)
    return base64url.fromBase64(hmac.digest('base64'))
  }
github mojaloop / central-ledger / src / handlers / transfers / validator.js View on Github external
const fulfilmentToCondition = (fulfilment) => {
  const hashSha256 = Crypto.createHash('sha256')
  const preimage = base64url.toBuffer(fulfilment)

  if (preimage.length !== 32) {
    throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.INTERNAL_SERVER_ERROR, 'Interledger preimages must be exactly 32 bytes')
  }

  const calculatedConditionDigest = hashSha256.update(preimage).digest('base64')
  Logger.debug(`calculatedConditionDigest=${calculatedConditionDigest}`)
  const calculatedConditionUrlEncoded = base64url.fromBase64(calculatedConditionDigest)
  Logger.debug(`calculatedConditionUrlEncoded=${calculatedConditionUrlEncoded}`)
  return calculatedConditionUrlEncoded
}

base64url

For encoding to/from base64urls

MIT
Latest version published 6 years ago

Package Health Score

74 / 100
Full package analysis