Skip to content

Commit 3a87b70

Browse files
committed
Rewrite imports
1 parent bca9e71 commit 3a87b70

11 files changed

Lines changed: 59 additions & 50 deletions

File tree

deno/src/context.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Duplex, finished } from "stream";
2-
import { Stream, STREAM_CHUNK_SIZE } from "./stream";
3-
import { ID } from "./kademlia";
4-
import util from "util";
5-
import { DataPacket, Opcode, ServiceResponsePacket } from "./packet";
6-
import { Provider } from "./provider";
7-
import { chunkBuffer } from "./node";
1+
import { Buffer } from "https://deno.land/std/node/buffer.ts";
2+
import { Duplex, finished } from "https://jspm.dev/stream";
3+
import { Stream, STREAM_CHUNK_SIZE } from "./stream.ts";
4+
import { ID } from "./kademlia.ts";
5+
import * as util from 'https://deno.land/std/node/util.ts'
6+
import { DataPacket, Opcode, ServiceResponsePacket } from "./packet.ts";
7+
import { Provider } from "./provider.ts";
8+
import { chunkBuffer } from "./node.ts";
89

910
export type Handler = (ctx: Context) => void;
1011

deno/src/kademlia.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import nacl from "tweetnacl";
2-
import ipaddr, { IPv4, IPv6 } from "ipaddr.js";
3-
import assert from "assert";
1+
import { Buffer } from "https://deno.land/std/node/buffer.ts";
2+
import nacl from "https://deno.land/x/tweetnacl_deno/src/nacl.ts";
3+
import ipaddr, { IPv4, IPv6 } from "https://jspm.dev/ipaddr.js";
4+
import assert from "https://deno.land/std/testing/asserts.ts";
45

56
export enum UpdateResult {
67
New,

deno/src/mod.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
export { Node, generateSecretKey } from "./node";
2-
export { Context } from "./context";
3-
export { ID, Table, UpdateResult } from "./kademlia";
4-
export { getAvailableAddress, splitHostPort } from "./net";
5-
export { Provider } from "./provider";
6-
export { x25519, serverHandshake, clientHandshake, Session } from "./session";
1+
export { Node, generateSecretKey } from "./node.ts";
2+
export { Context } from "./context.ts";
3+
export { ID, Table, UpdateResult } from "./kademlia.ts";
4+
export { getAvailableAddress, splitHostPort } from "./net.ts";
5+
export { Provider } from "./provider.ts";
6+
export { x25519, serverHandshake, clientHandshake, Session } from "./session.ts";
77
export {
88
drain,
99
lengthPrefixed,
1010
prefixLength,
1111
RPC,
1212
Stream,
1313
Streams,
14-
} from "./stream";
14+
} from "./stream.ts";

deno/src/net.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { IPv4, IPv6 } from "ipaddr.js";
2-
import net from "net";
3-
import events from "events";
4-
import ipaddr from "ipaddr.js";
1+
import { IPv4, IPv6 } from "https://jspm.dev/ipaddr.js";
2+
import net from "./std-node-net.ts";
3+
import events from "https://deno.land/std/node/events.ts";
4+
import ipaddr from "https://jspm.dev/ipaddr.js";
55

66
/**
77
* Returns an available TCP host/port that may be listened to.

deno/src/node.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Context, Handler } from "./context";
2-
import net from "net";
3-
import { ID, Table } from "./kademlia";
4-
import nacl from "tweetnacl";
5-
import { getAvailableAddress, splitHostPort } from "./net";
6-
import { IPv4, IPv6 } from "ipaddr.js";
1+
import { Buffer } from "https://deno.land/std/node/buffer.ts";
2+
import { Context, Handler } from "./context.ts";
3+
// import net from "net";
4+
import { ID, Table } from "./kademlia.ts";
5+
import * as nacl from 'https://deno.land/x/tweetnacl_deno/src/nacl.ts'
6+
import { getAvailableAddress, splitHostPort } from "./net.ts";
7+
import ipaddr from "https://jspm.dev/ipaddr.js";
78
import {
89
DataPacket,
910
FindNodeRequest,
@@ -12,11 +13,11 @@ import {
1213
Opcode,
1314
ServiceRequestPacket,
1415
ServiceResponsePacket,
15-
} from "./packet";
16-
import events from "events";
17-
import { clientHandshake, serverHandshake, Session } from "./session";
18-
import hash from "object-hash";
19-
import { Provider } from "./provider";
16+
} from "./packet.ts";
17+
import events from "https://deno.land/std/node/events.ts";
18+
import { clientHandshake, serverHandshake, Session } from "./session.ts";
19+
import { Provider } from "./provider.ts";
20+
import hash from "https://jspm.dev/object-hash";
2021

2122
const debug = require("debug")("flatend");
2223

@@ -74,7 +75,7 @@ export class Node {
7475
}
7576
}
7677

77-
let publicHost: IPv4 | IPv6;
78+
let publicHost: ipaddr.IPv4 | ipaddr.IPv6;
7879
let publicPort: number;
7980

8081
if (opts.publicAddr) {

deno/src/packet.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import nacl from "tweetnacl";
2-
import assert from "assert";
3-
import { ID } from "./kademlia";
1+
import { Buffer } from "https://deno.land/std/node/buffer.ts";
2+
import nacl from "https://deno.land/x/tweetnacl_deno/src/nacl.ts";
3+
import assert from "https://deno.land/std/testing/asserts.ts";
4+
import { ID } from "./kademlia.ts";
45

56
export enum Opcode {
67
Handshake,

deno/src/provider.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import { ID } from "./kademlia";
2-
import net from "net";
3-
import { Session } from "./session";
1+
import { Buffer } from "https://deno.land/std/node/buffer.ts";
2+
import { ID } from "./kademlia.ts";
3+
import net from "./std-node-net.ts";
4+
import { Session } from "./session.ts";
45
import {
56
drain,
67
lengthPrefixed,
78
prefixLength,
89
RPC,
910
Stream,
1011
Streams,
11-
} from "./stream";
12-
import { Opcode } from "./packet";
12+
} from "./stream.ts";
13+
import { Opcode } from "./packet.ts";
1314

1415
export class Provider {
1516
id?: ID;

deno/src/session.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import net from "net";
2-
import nacl from "tweetnacl";
3-
import events from "events";
4-
import crypto from "crypto";
1+
import { Buffer } from "https://deno.land/std/node/buffer.ts";
2+
import * as net from "./std-node-net.ts";
3+
import nacl from "https://deno.land/x/tweetnacl_deno/src/nacl.ts";
4+
import events from "https://deno.land/std/node/events.ts";
5+
import crypto from "./std-node-crypto.ts";
56

6-
const blake2b = require("blake2b");
7+
import { blake2b } from "https://deno.land/x/blake2b/mod.ts";
78

89
export function x25519(privateKey: Uint8Array, publicKey: Uint8Array): Buffer {
9-
return blake2b(32).update(nacl.scalarMult(privateKey, publicKey)).digest();
10+
return blake2b(nacl.scalarMult(privateKey, publicKey), "", "", 32);
1011
}
1112

1213
export async function serverHandshake(conn: net.Socket): Promise<Uint8Array> {

deno/src/std-node-crypto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {} as any

deno/src/std-node-net.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {} as any

0 commit comments

Comments
 (0)