mirror of
https://github.com/amark/gun.git
synced 2026-03-19 06:39:10 +00:00
* Thank you Murage Martin @murageyun for donating!!! * Fix opt.s3.fakes3 parsing issue (#1318) * Fix opt.s3.fakes3 parsing issue * Fix second typo within if block * Support variable number of auth retry attempts through opt.retries (#1325) Maintain default to 9 to ensure backwards compatibility * Thanks Jason Stallings @octalmage !!! * Remove unused imports (#1337) * Update README.md * yay format change * encode objects * WS ws.path fix (#1343) * Update wire.js * Update wire.js * Update wire.js * add one click deploy to readme (#1342) * update src/index (#1254) * update src/index * update * src/index fix * added src/core * is ??? this a MVP of book & rad ???? thanks to @rogowski * book & rad APIs stabilizing * RAD & Book promoted! + buggy example: test/rad/book.html * bump path * cleaned up Book results & sorting & caching * sea blobs! (#1353) * sea blobs! * and null origins * null fix * null check is last * add a way to select stats file from url (#1351) * react-native detection, and load needed shims (#1349) * react-native detection * added lib mobile * changed back to gun. for another solution * have unbuild function wrap to prevent scope leaks & allow RETURN hehehe so I can reject @bmatusiak 's lS change O:) O:) I love you you're a hero! later with @bmatusiak check sea.then for '../gun.js' vs '../' vs ... note: src/index -> core.js TODO: something about WebRTC candidates hitting ack decrement limits? * quick-fix (#1355) * Fix SEA certificate verification, allow multiple pubs (#1358) * Create SECURITY.md (#1364) * ... works (#1357) * Loading fix (#1356) * does this load better * check window.Gun too in rfs * update SECURITY.md file and change the versions to 0.2020.x (#1365) * webrtc accept getUserMedia streams as peer * Check atom exists in graph when deciding to read from disk (#1371) * fix: ERROR: Radisk needs `store.put` interface (#1374) * Update STUN servers (#1381) Commented out sipgate.net STUN server. Added Cloudflare STUN server. * universal notification system --------- Co-authored-by: ritchia1 <andrew.ritchie@estimateone.com> Co-authored-by: Anton <dev@atjn.dk> Co-authored-by: Bradley Matusiak <bmatusiak@gmail.com> Co-authored-by: Jay Byoun <jay8061@pm.me> Co-authored-by: mimiza <dev@mimiza.com> Co-authored-by: Simardeep Singh <1003simar@gmail.com> Co-authored-by: Malcolm Blaney <mblaney@gmail.com> Co-authored-by: Andreas Heissenberger <andreas@heissenberger.at> Co-authored-by: carlin978 <120719190+carlin978@users.noreply.github.com>
81 lines
3.6 KiB
JavaScript
81 lines
3.6 KiB
JavaScript
;(function(){
|
|
|
|
require('./base64');
|
|
// This is Buffer implementation used in SEA. Functionality is mostly
|
|
// compatible with NodeJS 'safe-buffer' and is used for encoding conversions
|
|
// between binary and 'hex' | 'utf8' | 'base64'
|
|
// See documentation and validation for safe implementation in:
|
|
// https://github.com/feross/safe-buffer#update
|
|
var SeaArray = require('./array');
|
|
function SafeBuffer(...props) {
|
|
console.warn('new SafeBuffer() is depreciated, please use SafeBuffer.from()')
|
|
return SafeBuffer.from(...props)
|
|
}
|
|
SafeBuffer.prototype = Object.create(Array.prototype)
|
|
Object.assign(SafeBuffer, {
|
|
// (data, enc) where typeof data === 'string' then enc === 'utf8'|'hex'|'base64'
|
|
from() {
|
|
if (!Object.keys(arguments).length || arguments[0]==null) {
|
|
throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
|
|
}
|
|
const input = arguments[0]
|
|
let buf
|
|
if (typeof input === 'string') {
|
|
const enc = arguments[1] || 'utf8'
|
|
if (enc === 'hex') {
|
|
const bytes = input.match(/([\da-fA-F]{2})/g)
|
|
.map((byte) => parseInt(byte, 16))
|
|
if (!bytes || !bytes.length) {
|
|
throw new TypeError('Invalid first argument for type \'hex\'.')
|
|
}
|
|
buf = SeaArray.from(bytes)
|
|
} else if (enc === 'utf8' || 'binary' === enc) { // EDIT BY MARK: I think this is safe, tested it against a couple "binary" strings. This lets SafeBuffer match NodeJS Buffer behavior more where it safely btoas regular strings.
|
|
const length = input.length
|
|
const words = new Uint16Array(length)
|
|
Array.from({ length: length }, (_, i) => words[i] = input.charCodeAt(i))
|
|
buf = SeaArray.from(words)
|
|
} else if (enc === 'base64') {
|
|
const dec = atob(input)
|
|
const length = dec.length
|
|
const bytes = new Uint8Array(length)
|
|
Array.from({ length: length }, (_, i) => bytes[i] = dec.charCodeAt(i))
|
|
buf = SeaArray.from(bytes)
|
|
} else if (enc === 'binary') { // deprecated by above comment
|
|
buf = SeaArray.from(input) // some btoas were mishandled.
|
|
} else {
|
|
console.info('SafeBuffer.from unknown encoding: '+enc)
|
|
}
|
|
return buf
|
|
}
|
|
const byteLength = input.byteLength // what is going on here? FOR MARTTI
|
|
const length = input.byteLength ? input.byteLength : input.length
|
|
if (length) {
|
|
let buf
|
|
if (input instanceof ArrayBuffer) {
|
|
buf = new Uint8Array(input)
|
|
}
|
|
return SeaArray.from(buf || input)
|
|
}
|
|
},
|
|
// This is 'safe-buffer.alloc' sans encoding support
|
|
alloc(length, fill = 0 /*, enc*/ ) {
|
|
return SeaArray.from(new Uint8Array(Array.from({ length: length }, () => fill)))
|
|
},
|
|
// This is normal UNSAFE 'buffer.alloc' or 'new Buffer(length)' - don't use!
|
|
allocUnsafe(length) {
|
|
return SeaArray.from(new Uint8Array(Array.from({ length : length })))
|
|
},
|
|
// This puts together array of array like members
|
|
concat(arr) { // octet array
|
|
if (!Array.isArray(arr)) {
|
|
throw new TypeError('First argument must be Array containing ArrayBuffer or Uint8Array instances.')
|
|
}
|
|
return SeaArray.from(arr.reduce((ret, item) => ret.concat(Array.from(item)), []))
|
|
}
|
|
})
|
|
SafeBuffer.prototype.from = SafeBuffer.from
|
|
SafeBuffer.prototype.toString = SeaArray.prototype.toString
|
|
|
|
module.exports = SafeBuffer;
|
|
|
|
}()); |