Using polyfill for Buffer in browsers (#129)

This commit is contained in:
Pavel 2022-02-17 10:54:38 +03:00 committed by GitHub
parent 976cd0435c
commit d860ea6dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 2 deletions

2
package-lock.json generated
View File

@ -14,7 +14,9 @@
"@fluencelabs/avm-runner-background": "0.1.2",
"@fluencelabs/avm-runner-interface": "^0.2.0",
"async": "3.2.0",
"browser-or-node": "^2.0.0",
"bs58": "4.0.1",
"buffer": "^6.0.3",
"cids": "0.8.1",
"it-length-prefixed": "3.0.1",
"it-pipe": "1.1.0",

View File

@ -28,6 +28,7 @@
"@fluencelabs/avm-runner-interface": "^0.2.0",
"async": "3.2.0",
"bs58": "4.0.1",
"buffer": "^6.0.3",
"cids": "0.8.1",
"it-length-prefixed": "3.0.1",
"it-pipe": "1.1.0",
@ -40,7 +41,8 @@
"peer-id": "=0.15.4",
"rxjs": "^7.3.0",
"ts-pattern": "^3.3.3",
"uuid": "8.3.0"
"uuid": "8.3.0",
"browser-or-node": "^2.0.0"
},
"devDependencies": {
"@fluencelabs/aqua": "^0.5.3-258",

4
src/internal/Buffer.ts Normal file
View File

@ -0,0 +1,4 @@
import { isBrowser } from 'browser-or-node';
import { Buffer as BufferPolyfill } from 'buffer';
export default isBrowser ? BufferPolyfill : Buffer;

View File

@ -26,6 +26,7 @@ import PeerId from 'peer-id';
import { Multiaddr } from 'multiaddr';
import { all as allow_all } from 'libp2p-websockets/src/filters';
import { Connection } from 'libp2p-interfaces/src/topology';
import Buffer from './Buffer';
export const PROTOCOL_NAME = '/fluence/particle/2.0.0';

View File

@ -30,6 +30,7 @@ import { AvmRunner, InterpreterResult, LogLevel } from '@fluencelabs/avm-runner-
import { AvmRunnerBackground } from '@fluencelabs/avm-runner-background';
import { defaultSigGuard, Sig } from './builtins/Sig';
import { registerSig } from './_aqua/services';
import Buffer from './Buffer';
/**
* Node of the Fluence network specified as a pair of node's multiaddr and it's peer id

View File

@ -20,6 +20,7 @@ import { CallResultsArray, LogLevel } from '@fluencelabs/avm-runner-interface';
import log from 'loglevel';
import { ParticleContext } from './commonTypes';
import { dataToString, jsonify } from './utils';
import Buffer from './Buffer';
export class Particle {
id: string;

View File

@ -18,7 +18,7 @@ import log from 'loglevel';
import { CallServiceData, CallServiceResult, CallServiceResultType, ResultCodes } from './commonTypes';
import { FluencePeer } from './FluencePeer';
import { Particle, ParticleExecutionStage } from './Particle';
import { LogLevel as AvmLoglevel } from '@fluencelabs/avm-runner-interface';
import Buffer from './Buffer';
export const MakeServiceCall = (fn: (args: any[]) => CallServiceResultType) => {
return (req: CallServiceData): CallServiceResult => {