123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- (function() {
- var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
- var __module = nodeEnv ? module : {exports:{}};
- var __filename = 'preview-scripts/__node_modules/browserify-sign/browser/index.js';
- var __require = nodeEnv ? function (request) {
- return cc.require(request);
- } : function (request) {
- return __quick_compile_project__.require(request, __filename);
- };
- function __define (exports, require, module) {
- if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}var Buffer = require('safe-buffer').Buffer
- var createHash = require('create-hash')
- var stream = require('readable-stream')
- var inherits = require('inherits')
- var sign = require('./sign')
- var verify = require('./verify')
- var algorithms = require('./algorithms.json')
- Object.keys(algorithms).forEach(function (key) {
- algorithms[key].id = Buffer.from(algorithms[key].id, 'hex')
- algorithms[key.toLowerCase()] = algorithms[key]
- })
- function Sign (algorithm) {
- stream.Writable.call(this)
- var data = algorithms[algorithm]
- if (!data) throw new Error('Unknown message digest')
- this._hashType = data.hash
- this._hash = createHash(data.hash)
- this._tag = data.id
- this._signType = data.sign
- }
- inherits(Sign, stream.Writable)
- Sign.prototype._write = function _write (data, _, done) {
- this._hash.update(data)
- done()
- }
- Sign.prototype.update = function update (data, enc) {
- if (typeof data === 'string') data = Buffer.from(data, enc)
- this._hash.update(data)
- return this
- }
- Sign.prototype.sign = function signMethod (key, enc) {
- this.end()
- var hash = this._hash.digest()
- var sig = sign(hash, key, this._hashType, this._signType, this._tag)
- return enc ? sig.toString(enc) : sig
- }
- function Verify (algorithm) {
- stream.Writable.call(this)
- var data = algorithms[algorithm]
- if (!data) throw new Error('Unknown message digest')
- this._hash = createHash(data.hash)
- this._tag = data.id
- this._signType = data.sign
- }
- inherits(Verify, stream.Writable)
- Verify.prototype._write = function _write (data, _, done) {
- this._hash.update(data)
- done()
- }
- Verify.prototype.update = function update (data, enc) {
- if (typeof data === 'string') data = Buffer.from(data, enc)
- this._hash.update(data)
- return this
- }
- Verify.prototype.verify = function verifyMethod (key, sig, enc) {
- if (typeof sig === 'string') sig = Buffer.from(sig, enc)
- this.end()
- var hash = this._hash.digest()
- return verify(sig, hash, key, this._signType, this._tag)
- }
- function createSign (algorithm) {
- return new Sign(algorithm)
- }
- function createVerify (algorithm) {
- return new Verify(algorithm)
- }
- module.exports = {
- Sign: createSign,
- Verify: createVerify,
- createSign: createSign,
- createVerify: createVerify
- }
- }
- if (nodeEnv) {
- __define(__module.exports, __require, __module);
- }
- else {
- __quick_compile_project__.registerModuleFunc(__filename, function () {
- __define(__module.exports, __require, __module);
- });
- }
- })();
|