Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dist/vdxf/classes/data/DataPacketRequestDetails.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface DataPacketRequestDetailsInterface {
statements?: Array<string>;
signature?: VerifiableSignatureData;
requestID?: CompactIAddressObject;
salt?: Buffer;
}
export interface DataPacketRequestDetailsJson {
version: number;
Expand All @@ -37,6 +38,7 @@ export interface DataPacketRequestDetailsJson {
statements?: Array<string>;
signature?: VerifiableSignatureDataJson;
requestid?: CompactAddressObjectJson;
salt?: string;
}
export declare class DataPacketRequestDetails implements SerializableEntity {
static VERSION_INVALID: import("bn.js");
Expand All @@ -49,18 +51,22 @@ export declare class DataPacketRequestDetails implements SerializableEntity {
static FLAG_FOR_USERS_SIGNATURE: import("bn.js");
static FLAG_FOR_TRANSMITTAL_TO_USER: import("bn.js");
static FLAG_HAS_URL_FOR_DOWNLOAD: import("bn.js");
static FLAG_HAS_SALT: import("bn.js");
static FLAG_STATEMENTS_ARE_DATA_DESCRIPTORS: import("bn.js");
version: BigNumber;
flags: BigNumber;
signableObjects: Array<DataDescriptor>;
statements?: Array<string>;
signature?: VerifiableSignatureData;
requestID?: CompactIAddressObject;
salt?: Buffer;
constructor(data?: DataPacketRequestDetailsInterface);
setFlags(): void;
calcFlags(): BigNumber;
hasStatements(): boolean;
hasSignature(): boolean;
hasRequestID(): boolean;
hasSalt(): boolean;
isValid(): boolean;
getByteLength(): number;
toBuffer(): Buffer;
Expand Down
24 changes: 24 additions & 0 deletions dist/vdxf/classes/data/DataPacketRequestDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DataPacketRequestDetails {
this.statements = (data === null || data === void 0 ? void 0 : data.statements) || [];
this.signature = (data === null || data === void 0 ? void 0 : data.signature) || undefined;
this.requestID = data === null || data === void 0 ? void 0 : data.requestID;
this.salt = data === null || data === void 0 ? void 0 : data.salt;
this.setFlags();
}
setFlags() {
Expand All @@ -51,6 +52,9 @@ class DataPacketRequestDetails {
if (this.requestID) {
flags = flags.or(DataPacketRequestDetails.FLAG_HAS_REQUEST_ID);
}
if (this.salt) {
flags = flags.or(DataPacketRequestDetails.FLAG_HAS_SALT);
}
return flags;
}
hasStatements() {
Expand All @@ -62,6 +66,9 @@ class DataPacketRequestDetails {
hasRequestID() {
return this.flags.and(DataPacketRequestDetails.FLAG_HAS_REQUEST_ID).eq(DataPacketRequestDetails.FLAG_HAS_REQUEST_ID);
}
hasSalt() {
return this.flags.and(DataPacketRequestDetails.FLAG_HAS_SALT).eq(DataPacketRequestDetails.FLAG_HAS_SALT);
}
isValid() {
let valid = this.version.gte(DataPacketRequestDetails.FIRST_VERSION) &&
this.version.lte(DataPacketRequestDetails.LAST_VERSION);
Expand All @@ -73,6 +80,9 @@ class DataPacketRequestDetails {
if (this.hasSignature()) {
valid && (valid = this.signature !== undefined); // TODO: && this.signature.isValid();
}
if (this.hasSalt()) {
valid && (valid = this.salt !== undefined && Buffer.isBuffer(this.salt) && this.salt.length > 0);
}
return valid;
}
getByteLength() {
Expand All @@ -97,6 +107,10 @@ class DataPacketRequestDetails {
if (this.hasRequestID()) {
length += this.requestID.getByteLength();
}
if (this.hasSalt() && this.salt) {
length += varuint_1.default.encodingLength(this.salt.length);
length += this.salt.length;
}
return length;
}
toBuffer() {
Expand All @@ -120,6 +134,9 @@ class DataPacketRequestDetails {
if (this.hasRequestID()) {
writer.writeSlice(this.requestID.toBuffer());
}
if (this.hasSalt()) {
writer.writeVarSlice(this.salt);
}
return writer.buffer;
}
fromBuffer(buffer, offset) {
Expand Down Expand Up @@ -151,6 +168,9 @@ class DataPacketRequestDetails {
this.requestID = new CompactAddressObject_1.CompactIAddressObject();
reader.offset = this.requestID.fromBuffer(reader.buffer, reader.offset);
}
if (this.hasSalt()) {
this.salt = reader.readVarSlice();
}
return reader.offset;
}
toJson() {
Expand All @@ -162,6 +182,7 @@ class DataPacketRequestDetails {
statements: this.statements,
signature: this.signature ? this.signature.toJson() : undefined,
requestid: this.requestID ? this.requestID.toJson() : undefined,
salt: this.salt ? this.salt.toString('hex') : undefined
};
}
static fromJson(json) {
Expand All @@ -177,6 +198,7 @@ class DataPacketRequestDetails {
instance.statements = json.statements || [];
instance.signature = json.signature ? VerifiableSignatureData_1.VerifiableSignatureData.fromJson(json.signature) : undefined;
instance.requestID = json.requestid ? CompactAddressObject_1.CompactIAddressObject.fromCompactAddressObjectJson(json.requestid) : undefined;
instance.salt = json.salt ? Buffer.from(json.salt, 'hex') : undefined;
return instance;
}
}
Expand All @@ -192,3 +214,5 @@ DataPacketRequestDetails.FLAG_HAS_SIGNATURE = new bn_js_1.BN(4);
DataPacketRequestDetails.FLAG_FOR_USERS_SIGNATURE = new bn_js_1.BN(8);
DataPacketRequestDetails.FLAG_FOR_TRANSMITTAL_TO_USER = new bn_js_1.BN(16);
DataPacketRequestDetails.FLAG_HAS_URL_FOR_DOWNLOAD = new bn_js_1.BN(32);
DataPacketRequestDetails.FLAG_HAS_SALT = new bn_js_1.BN(64);
DataPacketRequestDetails.FLAG_STATEMENTS_ARE_DATA_DESCRIPTORS = new bn_js_1.BN(128);
6 changes: 4 additions & 2 deletions src/__tests__/vdxf/datapacketrequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("DataPacketRequestDetails", () => {
test("creates instance with custom values", () => {
const item = new DataPacketRequestDetails({
version: new BN(DataPacketRequestDetails.DEFAULT_VERSION),
flags: DataPacketRequestDetails.FLAG_HAS_STATEMENTS.or(DataPacketRequestDetails.FLAG_HAS_SIGNATURE).or(DataPacketRequestDetails.FLAG_HAS_REQUEST_ID),
flags: DataPacketRequestDetails.FLAG_HAS_STATEMENTS.or(DataPacketRequestDetails.FLAG_HAS_SIGNATURE).or(DataPacketRequestDetails.FLAG_HAS_REQUEST_ID).or(DataPacketRequestDetails.FLAG_HAS_SALT),
signableObjects: [DataDescriptor.fromJson({ version: new BN(1), label: "123", objectdata: "0011223344aabbcc", flags: DataDescriptor.FLAG_LABEL_PRESENT })],
statements: ["Statement 1", "Statement 2"],
signature: new VerifiableSignatureData({
Expand All @@ -24,7 +24,8 @@ describe("DataPacketRequestDetails", () => {
identityID: new CompactIAddressObject({ version: CompactAddressObject.DEFAULT_VERSION, type: CompactAddressObject.TYPE_I_ADDRESS, address: "i7LaXD2cdy1zeh33eHzZaEPyueT4yQmBfW", rootSystemName: "VRSC" }),
systemID: new CompactIAddressObject({ version: CompactAddressObject.DEFAULT_VERSION, type: CompactAddressObject.TYPE_FQN, address: "VRSC", rootSystemName: "VRSC" }),
}),
requestID: CompactIAddressObject.fromAddress("iD4CrjbJBZmwEZQ4bCWgbHx9tBHGP9mdSQ")
requestID: CompactIAddressObject.fromAddress("iD4CrjbJBZmwEZQ4bCWgbHx9tBHGP9mdSQ"),
salt: Buffer.from("4f66603f256d3f757b6dc3ea44802d4041d2a1901e06005028fd60b85a5878a2", "hex")
});

const detailsBuffer = item.toBuffer();
Expand All @@ -41,6 +42,7 @@ describe("DataPacketRequestDetails", () => {
expect(newDetails.statements?.length).toBe(2);
expect(newDetails.statements?.[0]).toBe("Statement 1");
expect(newDetails.signature?.signatureAsVch.toString('hex')).toBe("efc8d6b60c5b6efaeb3fce4b2c0749c317f2167549ec22b1bee411b8802d5aaf");
expect(newDetails.salt?.toString('hex')).toBe("4f66603f256d3f757b6dc3ea44802d4041d2a1901e06005028fd60b85a5878a2");
expect(newDetails.toBuffer().toString('hex')).toBe(detailsBuffer.toString('hex'));
});
});
Expand Down
6 changes: 4 additions & 2 deletions src/__tests__/vdxf/ordinalvdxfobject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ describe('OrdinalVDXFObject and subclasses round-trip serialization', () => {
it('should serialize / deserialize a DataPacketRequestOrdinalVDXFObject via buffer', () => {
const details = new DataPacketRequestDetails({
version: new BN(1),
flags: DataPacketRequestDetails.FLAG_HAS_STATEMENTS.or(DataPacketRequestDetails.FLAG_HAS_SIGNATURE),
flags: DataPacketRequestDetails.FLAG_HAS_STATEMENTS.or(DataPacketRequestDetails.FLAG_HAS_SIGNATURE).or(DataPacketRequestDetails.FLAG_HAS_SALT),
signableObjects: [DataDescriptor.fromJson({ version: new BN(1), label: "123", objectdata: "0011223344aabbcc", flags: DataDescriptor.FLAG_LABEL_PRESENT })],
statements: ["Statement 1", "Statement 2"],
signature: new VerifiableSignatureData({
Expand All @@ -564,7 +564,8 @@ describe('OrdinalVDXFObject and subclasses round-trip serialization', () => {
identityID: new CompactIAddressObject({ version: CompactAddressObject.DEFAULT_VERSION, type: CompactAddressObject.TYPE_I_ADDRESS, address: "i7LaXD2cdy1zeh33eHzZaEPyueT4yQmBfW", rootSystemName: "VRSC" }),
systemID: new CompactIAddressObject({ version: CompactAddressObject.DEFAULT_VERSION, type: CompactAddressObject.TYPE_FQN, address: "VRSC", rootSystemName: "VRSC" }),
}),
requestID: CompactIAddressObject.fromAddress("iD4CrjbJBZmwEZQ4bCWgbHx9tBHGP9mdSQ")
requestID: CompactIAddressObject.fromAddress("iD4CrjbJBZmwEZQ4bCWgbHx9tBHGP9mdSQ"),
salt: Buffer.from("4f66603f256d3f757b6dc3ea44802d4041d2a1901e06005028fd60b85a5878a2", "hex")
});

const obj = new DataPacketRequestOrdinalVDXFObject({ data: details });
Expand All @@ -577,6 +578,7 @@ describe('OrdinalVDXFObject and subclasses round-trip serialization', () => {
expect(d2.signableObjects.length).toBe(1);
expect(d2.statements?.length).toBe(2);
expect(d2.signature?.signatureAsVch.toString('hex')).toBe("efc8d6b60c5b6efaeb3fce4b2c0749c317f2167549ec22b1bee411b8802d5aaf");
expect(d2.salt?.toString('hex')).toBe("4f66603f256d3f757b6dc3ea44802d4041d2a1901e06005028fd60b85a5878a2");

const json = obj.toJson();
expect(json.data).toBeDefined();
Expand Down
32 changes: 31 additions & 1 deletion src/vdxf/classes/data/DataPacketRequestDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface DataPacketRequestDetailsInterface {
statements?: Array<string>;
signature?: VerifiableSignatureData;
requestID?: CompactIAddressObject;
salt?: Buffer;
}

export interface DataPacketRequestDetailsJson {
Expand All @@ -44,6 +45,7 @@ export interface DataPacketRequestDetailsJson {
statements?: Array<string>;
signature?: VerifiableSignatureDataJson;
requestid?: CompactAddressObjectJson;
salt?: string;
}

export class DataPacketRequestDetails implements SerializableEntity {
Expand All @@ -59,13 +61,16 @@ export class DataPacketRequestDetails implements SerializableEntity {
static FLAG_FOR_USERS_SIGNATURE = new BN(8);
static FLAG_FOR_TRANSMITTAL_TO_USER = new BN(16);
static FLAG_HAS_URL_FOR_DOWNLOAD = new BN(32);
static FLAG_HAS_SALT = new BN(64);
static FLAG_STATEMENTS_ARE_DATA_DESCRIPTORS = new BN(128);

version: BigNumber;
flags: BigNumber;
signableObjects: Array<DataDescriptor>;
statements?: Array<string>;
signature?: VerifiableSignatureData;
requestID?: CompactIAddressObject;
salt?: Buffer;

constructor(data?: DataPacketRequestDetailsInterface) {
this.version = data?.version || DataPacketRequestDetails.DEFAULT_VERSION;
Expand All @@ -74,7 +79,7 @@ export class DataPacketRequestDetails implements SerializableEntity {
this.statements = data?.statements || [];
this.signature = data?.signature || undefined;
this.requestID = data?.requestID;

this.salt = data?.salt;
this.setFlags();
}

Expand All @@ -96,6 +101,9 @@ export class DataPacketRequestDetails implements SerializableEntity {
if (this.requestID) {
flags = flags.or(DataPacketRequestDetails.FLAG_HAS_REQUEST_ID);
}
if (this.salt) {
flags = flags.or(DataPacketRequestDetails.FLAG_HAS_SALT);
}

return flags;
}
Expand All @@ -112,6 +120,10 @@ export class DataPacketRequestDetails implements SerializableEntity {
return this.flags.and(DataPacketRequestDetails.FLAG_HAS_REQUEST_ID).eq(DataPacketRequestDetails.FLAG_HAS_REQUEST_ID);
}

hasSalt(): boolean {
return this.flags.and(DataPacketRequestDetails.FLAG_HAS_SALT).eq(DataPacketRequestDetails.FLAG_HAS_SALT);
}

isValid(): boolean {
let valid = this.version.gte(DataPacketRequestDetails.FIRST_VERSION) &&
this.version.lte(DataPacketRequestDetails.LAST_VERSION);
Expand All @@ -125,6 +137,9 @@ export class DataPacketRequestDetails implements SerializableEntity {
if (this.hasSignature()) {
valid &&= this.signature !== undefined; // TODO: && this.signature.isValid();
}
if (this.hasSalt()) {
valid &&= this.salt !== undefined && Buffer.isBuffer(this.salt) && this.salt.length > 0;
}

return valid;
}
Expand Down Expand Up @@ -158,6 +173,11 @@ export class DataPacketRequestDetails implements SerializableEntity {
length += this.requestID.getByteLength();
}

if (this.hasSalt() && this.salt) {
length += varuint.encodingLength(this.salt.length);
length += this.salt.length;
}

return length;
}

Expand Down Expand Up @@ -189,6 +209,10 @@ export class DataPacketRequestDetails implements SerializableEntity {
writer.writeSlice(this.requestID.toBuffer());
}

if (this.hasSalt()) {
writer.writeVarSlice(this.salt);
}

return writer.buffer;
}

Expand Down Expand Up @@ -229,6 +253,10 @@ export class DataPacketRequestDetails implements SerializableEntity {
reader.offset = this.requestID.fromBuffer(reader.buffer, reader.offset);
}

if (this.hasSalt()) {
this.salt = reader.readVarSlice();
}

return reader.offset;
}

Expand All @@ -242,6 +270,7 @@ export class DataPacketRequestDetails implements SerializableEntity {
statements: this.statements,
signature: this.signature ? this.signature.toJson() : undefined,
requestid: this.requestID ? this.requestID.toJson() : undefined,
salt: this.salt ? this.salt.toString('hex') : undefined
};
}

Expand All @@ -261,6 +290,7 @@ export class DataPacketRequestDetails implements SerializableEntity {
instance.statements = json.statements || [];
instance.signature = json.signature ? VerifiableSignatureData.fromJson(json.signature) : undefined;
instance.requestID = json.requestid ? CompactIAddressObject.fromCompactAddressObjectJson(json.requestid) : undefined;
instance.salt = json.salt ? Buffer.from(json.salt, 'hex') : undefined;
return instance;
}
}