diff --git a/package-lock.json b/package-lock.json index 7a0db4e5..9907a45b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index b709fb63..a57e7778 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/internal/Buffer.ts b/src/internal/Buffer.ts new file mode 100644 index 00000000..a22bd96f --- /dev/null +++ b/src/internal/Buffer.ts @@ -0,0 +1,4 @@ +import { isBrowser } from 'browser-or-node'; +import { Buffer as BufferPolyfill } from 'buffer'; + +export default isBrowser ? BufferPolyfill : Buffer; diff --git a/src/internal/FluenceConnection.ts b/src/internal/FluenceConnection.ts index 8523b119..f5f82493 100644 --- a/src/internal/FluenceConnection.ts +++ b/src/internal/FluenceConnection.ts @@ -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'; diff --git a/src/internal/FluencePeer.ts b/src/internal/FluencePeer.ts index 23ee016b..683b7bcd 100644 --- a/src/internal/FluencePeer.ts +++ b/src/internal/FluencePeer.ts @@ -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 diff --git a/src/internal/Particle.ts b/src/internal/Particle.ts index 118c8fd4..9df33797 100644 --- a/src/internal/Particle.ts +++ b/src/internal/Particle.ts @@ -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; diff --git a/src/internal/utils.ts b/src/internal/utils.ts index 22d71e59..81b2df12 100644 --- a/src/internal/utils.ts +++ b/src/internal/utils.ts @@ -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 => {