Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(crypto): increase vendor field length to 255 bytes #2159

Merged
merged 10 commits into from
Feb 26, 2019
Prev Previous commit
Next Next commit
refactor(crypto): introduce vendorFieldLength constant in milestones
  • Loading branch information
Brian Faust committed Feb 26, 2019
commit 210e23b2d7e8f5b662007ebb7046021da045f2c8
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
"multiPayment": 0,
"delegateResignation": 0
}
}
},
"vendorFieldLength": 64
},
{
"height": 75600,
"reward": 200000000
},
{
"height": 100000,
"vendorField255": true
"vendorFieldLength": 255
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ describe("Transaction serializer / deserializer", () => {
expect(deserialized.data.recipientId).toBe(transfer.recipientId);
});

it("should ser/deserialize with long vendorfield when vendorField255 milestone is active", () => {
configManager.getMilestone().vendorField255 = true;
it("should ser/deserialize with long vendorfield when vendorFieldLength=255 milestone is active", () => {
configManager.getMilestone().vendorFieldLength = 255;

const transferWithLongVendorfield = client
.getBuilder()
Expand All @@ -77,10 +77,10 @@ describe("Transaction serializer / deserializer", () => {
expect(deserialized.data.vendorFieldHex).toHaveLength(510);
expect(deserialized.data.vendorField).toEqual("y".repeat(255));

configManager.getMilestone().vendorField255 = false;
configManager.getMilestone().vendorFieldLength = 64;
});

it("should not ser/deserialize long vendorfield when vendorField255 milestone is not active", () => {
it("should not ser/deserialize long vendorfield when vendorFieldLength=255 milestone is not active", () => {
const transferWithLongVendorfield = client
.getBuilder()
.transfer()
Expand Down
10 changes: 5 additions & 5 deletions packages/crypto/__tests__/validation/formats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ describe("format vendorField", () => {
});

it("should be ok with up to 255 bytes with milestone ", () => {
configManager.getMilestone().vendorField255 = true;
configManager.getMilestone().vendorFieldLength = 255;
const schema = { type: "string", format: "vendorField" };
const validate = ajv.compile(schema);
expect(validate("a".repeat(65))).toBeTrue();
expect(validate("⊁".repeat(85))).toBeTrue();
expect(validate("a".repeat(256))).toBeFalse();
expect(validate("⊁".repeat(86))).toBeFalse();

configManager.getMilestone().vendorField255 = false;
configManager.getMilestone().vendorFieldLength = 64;
});
});

Expand All @@ -49,15 +49,15 @@ describe("format vendorFieldHex", () => {
expect(validate("⊁".repeat(22))).toBeFalse();
});

it("should be ok with 510 hex when milestone vendorField255 is active", () => {
configManager.getMilestone().vendorField255 = true;
it("should be ok with 510 hex when milestone vendorFieldLength=255 is active", () => {
configManager.getMilestone().vendorFieldLength = 255;
const schema = { type: "string", format: "vendorFieldHex" };
const validate = ajv.compile(schema);

expect(validate("affe".repeat(127))).toBeTrue();
expect(validate("affe".repeat(128))).toBeFalse();

configManager.getMilestone().vendorField255 = false;
configManager.getMilestone().vendorFieldLength = 64;
});

it("should not be ok with non hex", () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/crypto/src/networks/devnet/milestones.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"delegateResignation": 0
}
},
"ignoreInvalidSecondSignatureField": true
"ignoreInvalidSecondSignatureField": true,
"vendorFieldLength": 64
},
{
"height": 10800,
Expand All @@ -49,6 +50,6 @@
},
{
"height": 1750000,
"vendorField255": true
"vendorFieldLength": 255
}
]
5 changes: 3 additions & 2 deletions packages/crypto/src/networks/mainnet/milestones.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"multiPayment": 0,
"delegateResignation": 0
}
}
},
"vendorFieldLength": 64
},
{
"height": 75600,
Expand All @@ -37,6 +38,6 @@
},
{
"height": 8000000,
"vendorField255": true
"vendorFieldLength": 255
}
]
5 changes: 3 additions & 2 deletions packages/crypto/src/networks/testnet/milestones.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
"multiPayment": 0,
"delegateResignation": 0
}
}
},
"vendorFieldLength": 64
},
{
"height": 75600,
"reward": 200000000
},
{
"height": 100000,
"vendorField255": true
"vendorFieldLength": 255
}
]
5 changes: 3 additions & 2 deletions packages/crypto/src/networks/unitnet/milestones.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
"multiPayment": 0,
"delegateResignation": 0
}
}
},
"vendorFieldLength": 64
},
{
"height": 75600,
"reward": 200000000
},
{
"height": 100000,
"vendorField255": true
"vendorFieldLength": 255
}
]
8 changes: 1 addition & 7 deletions packages/crypto/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ export const isGenesisTransaction = (id: string): boolean => {
return genesisTransactions[id];
};

export const maxVendorFieldLength = (height?: number): number => {
if (configManager.getMilestone(height).vendorField255) {
return 255;
}

return 64;
};
export const maxVendorFieldLength = (height?: number): number => configManager.getMilestone(height).vendorFieldLength;

export { Bignum };