12345678910111213141516171819202122232425262728293031323334353637 |
- const SEA = require('./root')
- const Buffer = require('./buffer')
- const api = {Buffer: Buffer}
- var o = {};
- if(SEA.window){
- api.crypto = window.crypto || window.msCrypto
- api.subtle = (api.crypto||o).subtle || (api.crypto||o).webkitSubtle;
- api.TextEncoder = window.TextEncoder;
- api.TextDecoder = window.TextDecoder;
- api.random = (len) => Buffer.from(api.crypto.getRandomValues(new Uint8Array(Buffer.alloc(len))));
- }
- if(!api.TextDecoder)
- {
- const { TextEncoder, TextDecoder } = require('text-encoding');
- api.TextDecoder = TextDecoder;
- api.TextEncoder = TextEncoder;
- }
- if(!api.crypto)
- {
- try
- {
- var crypto = require('crypto', 1);
- Object.assign(api, {
- crypto,
- random: (len) => Buffer.from(crypto.randomBytes(len))
- });
- const { Crypto: WebCrypto } = require('@peculiar/webcrypto', 1);
- api.ossl = api.subtle = new WebCrypto({directory: 'ossl'}).subtle // ECDH
- }
- catch(e){
- console.log("text-encoding and peculiar/nwebcrypto may not be included by default, please add it to your package.json!");
- }}
- module.exports = api
-
|