From 437a10bca29c95174a224d930cabf778699a2f06 Mon Sep 17 00:00:00 2001 From: gagdiez Date: Mon, 11 Mar 2024 16:11:50 +0100 Subject: [PATCH 1/4] fix: DelegateAction Schema The current schema has two fields swapped (actions and nonce), which makes it impossible to create DelegateActions, since the borsh serialization ends up mixing the nonce with the action --- packages/transactions/src/schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/transactions/src/schema.ts b/packages/transactions/src/schema.ts index 4f909a685f..cb1ddf8806 100644 --- a/packages/transactions/src/schema.ts +++ b/packages/transactions/src/schema.ts @@ -187,8 +187,8 @@ export const SCHEMA = new class BorshSchema { struct: { senderId: 'string', receiverId: 'string', - nonce: 'u64', actions: { array: { type: this.ClassicActions } }, + nonce: 'u64', maxBlockHeight: 'u64', publicKey: this.PublicKey, } From 294c56940af1bb994b08456ddf4003d68bcda8b5 Mon Sep 17 00:00:00 2001 From: gagdiez Date: Mon, 11 Mar 2024 16:27:48 +0100 Subject: [PATCH 2/4] chore: add test --- packages/transactions/test/serialize.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/transactions/test/serialize.test.js b/packages/transactions/test/serialize.test.js index 78d34a47a5..13e9f05f28 100644 --- a/packages/transactions/test/serialize.test.js +++ b/packages/transactions/test/serialize.test.js @@ -43,6 +43,14 @@ test('serialize object', async () => { expect(new_value.q).toEqual([1, 2, 3]); }); +test('deserialize delegate', async () => { + const serialized = [8,16,0,0,0,116,104,101,45,117,115,101,114,46,116,101,115,116,110,101,116,27,0,0,0,104,101,108,108,111,46,110,101,97,114,45,101,120,97,109,112,108,101,115,46,116,101,115,116,110,101,116,1,0,0,0,2,12,0,0,0,115,101,116,95,103,114,101,101,116,105,110,103,20,0,0,0,123,34,103,114,101,101,116,105,110,103,34,58,34,72,101,108,108,111,34,125,0,224,87,235,72,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,9,120,166,131,144,0,0,61,158,123,9,0,0,0,0,0,154,156,80,116,108,65,42,39,47,253,146,109,67,106,83,230,57,183,195,122,150,6,246,220,173,35,120,139,167,94,183,29,0,41,98,10,45,51,177,89,159,190,247,41,255,243,17,186,140,168,139,9,81,33,8,74,73,85,254,127,62,54,193,60,50,235,49,13,37,152,94,172,24,198,220,119,148,99,89,19,187,251,80,76,230,77,28,80,140,133,81,139,159,62,245,167,4]; + const { signedDelegate: { delegateAction, signature } } = deserialize(SCHEMA.Action, serialized); + expect(delegateAction.senderId).toEqual('the-user.testnet'); + expect(delegateAction.receiverId).toEqual('hello.near-examples.testnet'); + expect(delegateAction.nonce).toEqual(158895108000003n); +}); + test('serialize and sign multi-action tx', async () => { const keyStore = new InMemoryKeyStore(); const keyPair = KeyPair.fromString('ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw'); From de375f1c5745fdd92a42c44f521448de72260abe Mon Sep 17 00:00:00 2001 From: gagdiez Date: Mon, 11 Mar 2024 16:37:26 +0100 Subject: [PATCH 3/4] fix: test --- packages/transactions/test/serialize.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/transactions/test/serialize.test.js b/packages/transactions/test/serialize.test.js index 13e9f05f28..d6977e1664 100644 --- a/packages/transactions/test/serialize.test.js +++ b/packages/transactions/test/serialize.test.js @@ -44,11 +44,11 @@ test('serialize object', async () => { }); test('deserialize delegate', async () => { - const serialized = [8,16,0,0,0,116,104,101,45,117,115,101,114,46,116,101,115,116,110,101,116,27,0,0,0,104,101,108,108,111,46,110,101,97,114,45,101,120,97,109,112,108,101,115,46,116,101,115,116,110,101,116,1,0,0,0,2,12,0,0,0,115,101,116,95,103,114,101,101,116,105,110,103,20,0,0,0,123,34,103,114,101,101,116,105,110,103,34,58,34,72,101,108,108,111,34,125,0,224,87,235,72,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,9,120,166,131,144,0,0,61,158,123,9,0,0,0,0,0,154,156,80,116,108,65,42,39,47,253,146,109,67,106,83,230,57,183,195,122,150,6,246,220,173,35,120,139,167,94,183,29,0,41,98,10,45,51,177,89,159,190,247,41,255,243,17,186,140,168,139,9,81,33,8,74,73,85,254,127,62,54,193,60,50,235,49,13,37,152,94,172,24,198,220,119,148,99,89,19,187,251,80,76,230,77,28,80,140,133,81,139,159,62,245,167,4]; - const { signedDelegate: { delegateAction, signature } } = deserialize(SCHEMA.Action, serialized); + const serialized = [8, 16, 0, 0, 0, 116, 104, 101, 45, 117, 115, 101, 114, 46, 116, 101, 115, 116, 110, 101, 116, 27, 0, 0, 0, 104, 101, 108, 108, 111, 46, 110, 101, 97, 114, 45, 101, 120, 97, 109, 112, 108, 101, 115, 46, 116, 101, 115, 116, 110, 101, 116, 1, 0, 0, 0, 2, 12, 0, 0, 0, 115, 101, 116, 95, 103, 114, 101, 101, 116, 105, 110, 103, 20, 0, 0, 0, 123, 34, 103, 114, 101, 101, 116, 105, 110, 103, 34, 58, 34, 72, 101, 108, 108, 111, 34, 125, 0, 224, 87, 235, 72, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 9, 120, 166, 131, 144, 0, 0, 61, 158, 123, 9, 0, 0, 0, 0, 0, 154, 156, 80, 116, 108, 65, 42, 39, 47, 253, 146, 109, 67, 106, 83, 230, 57, 183, 195, 122, 150, 6, 246, 220, 173, 35, 120, 139, 167, 94, 183, 29, 0, 41, 98, 10, 45, 51, 177, 89, 159, 190, 247, 41, 255, 243, 17, 186, 140, 168, 139, 9, 81, 33, 8, 74, 73, 85, 254, 127, 62, 54, 193, 60, 50, 235, 49, 13, 37, 152, 94, 172, 24, 198, 220, 119, 148, 99, 89, 19, 187, 251, 80, 76, 230, 77, 28, 80, 140, 133, 81, 139, 159, 62, 245, 167, 4]; + const { signedDelegate: { delegateAction } } = deserialize(SCHEMA.Action, serialized); expect(delegateAction.senderId).toEqual('the-user.testnet'); expect(delegateAction.receiverId).toEqual('hello.near-examples.testnet'); - expect(delegateAction.nonce).toEqual(158895108000003n); + expect(String(delegateAction.nonce)).toEqual('158895108000003'); }); test('serialize and sign multi-action tx', async () => { From d3feb0d111107b01510abb9b97dcee2d8a5ae192 Mon Sep 17 00:00:00 2001 From: gagdiez Date: Mon, 11 Mar 2024 16:40:13 +0100 Subject: [PATCH 4/4] chore: add changeset --- .changeset/happy-onions-wave.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/happy-onions-wave.md diff --git a/.changeset/happy-onions-wave.md b/.changeset/happy-onions-wave.md new file mode 100644 index 0000000000..d946494ea3 --- /dev/null +++ b/.changeset/happy-onions-wave.md @@ -0,0 +1,5 @@ +--- +"@near-js/transactions": patch +--- + +Fixed delegateAction Schema