diff --git a/types/ndn-js/blob.d.ts b/types/ndn-js/blob.d.ts new file mode 100644 index 0000000000..8a84e66b58 --- /dev/null +++ b/types/ndn-js/blob.d.ts @@ -0,0 +1,23 @@ +export class Blob { + constructor(value?: Blob); + constructor(value: Buffer, copy?: boolean); + constructor(value: number[]); + constructor(value: string); + + size(): number; + buf(): Buffer; + isNull(): boolean; + toHex(): string; + toString(): string; + equals(other: Blob): boolean; +} + +export class SignedBlob extends Blob { + constructor(); + constructor(value: Blob|Buffer|number[], signedPortionBeginOffset: number, signedPortionEndOffset: number); + + signedSize(): number; + signedBuf(): Buffer; + getSignedPortionBeginOffset(): number; + getSignedPortionEndOffset(): number; +} diff --git a/types/ndn-js/index.d.ts b/types/ndn-js/index.d.ts index da75f56e6c..c1dbeb6a76 100644 --- a/types/ndn-js/index.d.ts +++ b/types/ndn-js/index.d.ts @@ -1,3 +1,4 @@ export as namespace ndn; +export * from "./blob"; export * from "./face"; export * from "./transport"; diff --git a/types/ndn-js/ndn-js-tests.ts b/types/ndn-js/ndn-js-tests.ts index 2364a6e377..ceeb00effe 100644 --- a/types/ndn-js/ndn-js-tests.ts +++ b/types/ndn-js/ndn-js-tests.ts @@ -1,7 +1,31 @@ +/// import ndn = require("ndn-js"); -let face = new ndn.Face(); -face = new ndn.Face({host: 'hobo.cs.arizona.edu', port: 6363}); -face = new ndn.Face(new ndn.TcpTransport(), new ndn.TcpTransport.ConnectionInfo("hobo.cs.arizona.edu", 9696)); -face = new ndn.Face(new ndn.UnixTransport(), new ndn.UnixTransport.ConnectionInfo("/run/nfd.sock")); -face = new ndn.Face(new ndn.WebSocketTransport(), new ndn.WebSocketTransport.ConnectionInfo("hobo.cs.arizona.edu", 9696)); +function testBlob() { + let blob = new ndn.Blob(); + blob = new ndn.Blob(blob); + blob = new ndn.Blob(Buffer.alloc(4)); + blob = new ndn.Blob("str"); + + let n: number = blob.size(); + let buf: Buffer = blob.buf(); + let b: boolean = blob.equals(blob); + let s: string = blob.toHex(); + s = blob.toString(); + b = blob.isNull(); + + let sb = new ndn.SignedBlob(); + sb = new ndn.SignedBlob(sb, 20, 40); + n = sb.signedSize(); + buf = sb.signedBuf(); + n = sb.getSignedPortionBeginOffset(); + n = sb.getSignedPortionEndOffset(); +} + +function testFaceTransport() { + let face = new ndn.Face(); + face = new ndn.Face({host: 'hobo.cs.arizona.edu', port: 6363}); + face = new ndn.Face(new ndn.TcpTransport(), new ndn.TcpTransport.ConnectionInfo("hobo.cs.arizona.edu", 9696)); + face = new ndn.Face(new ndn.UnixTransport(), new ndn.UnixTransport.ConnectionInfo("/run/nfd.sock")); + face = new ndn.Face(new ndn.WebSocketTransport(), new ndn.WebSocketTransport.ConnectionInfo("hobo.cs.arizona.edu", 9696)); +}