mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-05-16 11:21:19 +00:00
Trying to update to v37.0
This commit is contained in:
parent
2b752492c1
commit
c22ac12af2
@ -2,4 +2,5 @@ module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
testTimeout: 10000,
|
||||
testPathIgnorePatterns: ['/node_modules/', 'dist'],
|
||||
};
|
4225
package-lock.json
generated
4225
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@ -2,8 +2,12 @@
|
||||
"name": "@fluencelabs/fluence",
|
||||
"version": "0.0.0",
|
||||
"description": "TypeScript implementation of Fluence Peer",
|
||||
"main": "./dist/index.js",
|
||||
"exports": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": ">=16.0"
|
||||
},
|
||||
"scripts": {
|
||||
"compile-aqua": "npm run compile-aqua:src && npm run compile-aqua:test",
|
||||
"compile-aqua:src": "aqua -i ./aqua/src/ -o ./src/internal/_aqua",
|
||||
@ -22,9 +26,13 @@
|
||||
"copy-marine": "dist/tools/copyMarine.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@chainsafe/libp2p-noise": "^4.1.1",
|
||||
"@chainsafe/libp2p-noise": "^6.1.1",
|
||||
"@fluencelabs/avm": "0.24.2",
|
||||
"@fluencelabs/marine-js": "0.2.5",
|
||||
"@libp2p/mplex": "^1.0.5",
|
||||
"@libp2p/peer-id": "^1.1.10",
|
||||
"@libp2p/websockets": "^1.0.8",
|
||||
"@multiformats/multiaddr": "^10.1.8",
|
||||
"async": "3.2.3",
|
||||
"browser-or-node": "^2.0.0",
|
||||
"bs58": "5.0.0",
|
||||
@ -32,14 +40,9 @@
|
||||
"cids": "1.1.9",
|
||||
"it-length-prefixed": "5.0.3",
|
||||
"it-pipe": "1.1.0",
|
||||
"libp2p": "0.36.2",
|
||||
"libp2p": "0.37.0",
|
||||
"libp2p-crypto": "0.21.2",
|
||||
"libp2p-mplex": "0.10.7",
|
||||
"libp2p-websockets": "0.16.2",
|
||||
"loglevel": "1.8.0",
|
||||
"multiaddr": "10.0.1",
|
||||
"multiformats": "9.6.5",
|
||||
"peer-id": "0.16.0",
|
||||
"platform": "^1.3.6",
|
||||
"rxjs": "^7.5.5",
|
||||
"ts-pattern": "3.3.3",
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Multiaddr } from 'multiaddr';
|
||||
import { Multiaddr } from '@multiformats/multiaddr';
|
||||
|
||||
import { nodes } from '../connection';
|
||||
import { FluencePeer } from '../../index';
|
||||
|
@ -26,7 +26,7 @@ describe('KeyPair tests', () => {
|
||||
|
||||
// assert
|
||||
const expectedPeerId = '12D3KooWH1W3VznVZ87JH4FwABK4mkntcspTVWJDta6c2xg9Pzbp';
|
||||
expect(keyPair.Libp2pPeerId.toB58String()).toStrictEqual(expectedPeerId);
|
||||
expect(keyPair.libp2pPeerId.toString()).toStrictEqual(expectedPeerId);
|
||||
});
|
||||
|
||||
it('create keypair from a seed phrase', async function () {
|
||||
@ -38,6 +38,6 @@ describe('KeyPair tests', () => {
|
||||
|
||||
// assert
|
||||
const expectedPeerId = '12D3KooWK99VoVxNE7XzyBwXEzW7xhK7Gpv85r9F3V3fyKSUKPH5';
|
||||
expect(keyPair.Libp2pPeerId.toB58String()).toStrictEqual(expectedPeerId);
|
||||
expect(keyPair.libp2pPeerId.toString()).toStrictEqual(expectedPeerId);
|
||||
});
|
||||
});
|
||||
|
@ -177,7 +177,7 @@ const context = (async () => {
|
||||
const kp = await KeyPair.fromEd25519SK(keyBytes);
|
||||
const res = {
|
||||
peerKeyPair: kp,
|
||||
peerId: kp.Libp2pPeerId.toB58String(),
|
||||
peerId: kp.libp2pPeerId.toString(),
|
||||
};
|
||||
return res;
|
||||
})();
|
||||
|
@ -13,22 +13,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @ts-ignore
|
||||
import Websockets from 'libp2p-websockets';
|
||||
// @ts-ignore
|
||||
import Mplex from 'libp2p-mplex';
|
||||
import Lib2p2Peer from 'libp2p';
|
||||
|
||||
import { WebSockets } from '@libp2p/websockets';
|
||||
import { Mplex } from '@libp2p/mplex';
|
||||
import { Libp2p as Lib2p2Peer, createLibp2p } from 'libp2p';
|
||||
import { decode, encode } from 'it-length-prefixed';
|
||||
import { pipe } from 'it-pipe';
|
||||
import * as log from 'loglevel';
|
||||
import { Noise } from '@chainsafe/libp2p-noise';
|
||||
import { Particle } from './Particle';
|
||||
import PeerId from 'peer-id';
|
||||
import { Multiaddr } from 'multiaddr';
|
||||
// @ts-ignore
|
||||
import { all as allow_all } from 'libp2p-websockets/src/filters';
|
||||
import { Connection } from 'libp2p-interfaces/src/topology';
|
||||
import { Multiaddr } from '@multiformats/multiaddr';
|
||||
import { PeerId } from '@libp2p/interfaces/peer-id/';
|
||||
import { Connection } from '@libp2p/interfaces/connection/';
|
||||
import Buffer from './Buffer';
|
||||
import * as log from 'loglevel';
|
||||
|
||||
export const PROTOCOL_NAME = '/fluence/particle/2.0.0';
|
||||
|
||||
@ -60,25 +57,13 @@ export interface FluenceConnectionOptions {
|
||||
export class FluenceConnection {
|
||||
constructor(private _lib2p2Peer: Lib2p2Peer, private _relayAddress: Multiaddr) {}
|
||||
|
||||
private _connection?: Connection;
|
||||
|
||||
static async createConnection(options: FluenceConnectionOptions): Promise<FluenceConnection> {
|
||||
const transportKey = Websockets.prototype[Symbol.toStringTag];
|
||||
const lib2p2Peer = await Lib2p2Peer.create({
|
||||
const lib2p2Peer = await createLibp2p({
|
||||
peerId: options.peerId,
|
||||
modules: {
|
||||
transport: [Websockets],
|
||||
streamMuxer: [Mplex],
|
||||
connEncryption: [new Noise()],
|
||||
},
|
||||
config: {
|
||||
transport: {
|
||||
[transportKey]: {
|
||||
filter: allow_all,
|
||||
},
|
||||
},
|
||||
},
|
||||
dialer: {
|
||||
transports: [new WebSockets()],
|
||||
streamMuxers: [new Mplex()],
|
||||
connectionEncryption: [new Noise()],
|
||||
connectionManager: {
|
||||
dialTimeout: options?.dialTimeoutMs,
|
||||
},
|
||||
});
|
||||
@ -140,7 +125,7 @@ export class FluenceConnection {
|
||||
async connect() {
|
||||
await this._lib2p2Peer.start();
|
||||
|
||||
log.debug(`dialing to the node with client's address: ` + this._lib2p2Peer.peerId.toB58String());
|
||||
log.debug(`dialing to the node with client's address: ` + this._lib2p2Peer.peerId);
|
||||
|
||||
try {
|
||||
this._connection = await this._lib2p2Peer.dial(this._relayAddress);
|
||||
@ -153,4 +138,6 @@ export class FluenceConnection {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _connection: Connection | undefined;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Multiaddr } from 'multiaddr';
|
||||
import { Multiaddr } from '@multiformats/multiaddr';
|
||||
import { CallServiceData, CallServiceResult, GenericCallServiceHandler, ResultCodes } from './commonTypes';
|
||||
import { PeerIdB58 } from './commonTypes';
|
||||
import { FluenceConnection } from './FluenceConnection';
|
||||
@ -200,7 +200,7 @@ export class FluencePeer {
|
||||
if (this._connection === undefined || this._relayPeerId === null) {
|
||||
return {
|
||||
isInitialized: true,
|
||||
peerId: this._keyPair.Libp2pPeerId.toB58String(),
|
||||
peerId: this._keyPair.libp2pPeerId.toString(),
|
||||
isConnected: false,
|
||||
relayPeerId: null,
|
||||
};
|
||||
@ -208,7 +208,7 @@ export class FluencePeer {
|
||||
|
||||
return {
|
||||
isInitialized: true,
|
||||
peerId: this._keyPair.Libp2pPeerId.toB58String(),
|
||||
peerId: this._keyPair.libp2pPeerId.toString(),
|
||||
isConnected: true,
|
||||
relayPeerId: this._relayPeerId,
|
||||
};
|
||||
@ -225,7 +225,7 @@ export class FluencePeer {
|
||||
const keyPair = config?.KeyPair ?? (await KeyPair.randomEd25519());
|
||||
this._keyPair = keyPair;
|
||||
|
||||
const peerId = keyPair.Libp2pPeerId.toB58String();
|
||||
const peerId = keyPair.libp2pPeerId.toString();
|
||||
|
||||
if (config?.debug?.printParticleId) {
|
||||
this._printParticleId = true;
|
||||
@ -262,7 +262,7 @@ export class FluencePeer {
|
||||
}
|
||||
|
||||
this._connection = await FluenceConnection.createConnection({
|
||||
peerId: this._keyPair.Libp2pPeerId,
|
||||
peerId: this._keyPair.libp2pPeerId,
|
||||
relayAddress: connectToMultiAddr,
|
||||
dialTimeoutMs: config.dialTimeoutMs,
|
||||
onIncomingParticle: (p) => this._incomingParticles.next({ particle: p, onStageChange: () => {} }),
|
||||
|
@ -14,17 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import * as PeerId from 'peer-id';
|
||||
import { PeerId } from '@libp2p/interfaces/peer-id';
|
||||
import { peerIdFromBytes } from '@libp2p/peer-id';
|
||||
import { keys } from 'libp2p-crypto';
|
||||
|
||||
type SK = keys.supportedKeys.ed25519.Ed25519PrivateKey;
|
||||
export class KeyPair {
|
||||
/**
|
||||
* Key pair in libp2p format. Used for backward compatibility with the current FluencePeer implementation
|
||||
*/
|
||||
public Libp2pPeerId: PeerId;
|
||||
constructor(public libp2pPeerId: PeerId, private secretKey: SK) {}
|
||||
|
||||
constructor(libp2pPeerId: PeerId) {
|
||||
this.Libp2pPeerId = libp2pPeerId;
|
||||
private static async fromSk(sk: SK) {
|
||||
const lib2p2Pid = await peerIdFromBytes(sk.bytes);
|
||||
return new KeyPair(lib2p2Pid, sk);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,9 +34,8 @@ export class KeyPair {
|
||||
*/
|
||||
static async fromEd25519SK(arr: Uint8Array): Promise<KeyPair> {
|
||||
// generateKeyPairFromSeed takes seed and copies it to private key as is
|
||||
const privateKey = await keys.generateKeyPairFromSeed('Ed25519', arr, 256);
|
||||
const lib2p2Pid = await PeerId.createFromPrivKey(privateKey.bytes);
|
||||
return new KeyPair(lib2p2Pid);
|
||||
const sk = await keys.generateKeyPairFromSeed('Ed25519', arr, 256);
|
||||
return await this.fromSk(sk);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,26 +43,26 @@ export class KeyPair {
|
||||
* @returns - Promise with the created KeyPair
|
||||
*/
|
||||
static async randomEd25519(): Promise<KeyPair> {
|
||||
const lib2p2Pid = await PeerId.create({ keyType: 'Ed25519' });
|
||||
return new KeyPair(lib2p2Pid);
|
||||
const sk = await keys.generateKeyPair('Ed25519');
|
||||
return await this.fromSk(sk);
|
||||
}
|
||||
|
||||
toB58String(): string {
|
||||
return this.Libp2pPeerId.toB58String();
|
||||
return this.libp2pPeerId.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns 32 byte private key
|
||||
*/
|
||||
toEd25519PrivateKey(): Uint8Array {
|
||||
return this.Libp2pPeerId.privKey.marshal().subarray(0, 32);
|
||||
return this.secretKey.bytes;
|
||||
}
|
||||
|
||||
signBytes(data: Uint8Array): Promise<Uint8Array> {
|
||||
return this.Libp2pPeerId.privKey.sign(data);
|
||||
return this.secretKey.sign(data);
|
||||
}
|
||||
|
||||
verify(data: Uint8Array, signature: Uint8Array): Promise<boolean> {
|
||||
return this.Libp2pPeerId.privKey.public.verify(data, signature);
|
||||
return this.secretKey.public.verify(data, signature);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user