Skip to content

Commit

Permalink
wallet_id 32bit
Browse files Browse the repository at this point in the history
  • Loading branch information
rise1507 committed Jun 25, 2024
1 parent 43fabdf commit 68a0866
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion build/wallet_v5.compiled.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"hex":"b5ee9c724102120100027a000114ff00f4a413f4bcf2c80b01020120030201eaf220d70b1f82107369676ebaf2af7f8ee3eda2edfb218308d722028308d723208020d721d34fd31fd31fed44d0d200d31f20d34fd70bff09f90140b9f9109927945f09db31e1f223df01f2a05122baf2a15036baf2a2f823bbf2642292f800dea47fc8ca00cb1f01cf16c9ed542092f80fdedb3cd80f0201480d0402012006050019be5f0f6a2684080b8eb90fa02c0201200c0702012009080019b45d1da89a10043ae43ae169f00201200b0a0011b262fb513435c280200017b325fb51341c75c875c2c7e00019bb39ced44d08071d721d70bff80280d020c702dc01d0d60301c713dc01d72c232bc3a3748ea701fa4030fa44f828fa443058badded44d0810171d721f4058307f40e6fa131dd8040d72170db3ce30e0f0e01f83120d70b1f821073696e74badd20d7498102b1b9dc708ee3eda2edfb218308d722028308d723208020d721d34fd31fd31fed44d0d200d31f20d34fd70bff09f90140b9f9109927945f09db31e1f223df01f2a05122baf2a15036baf2a2f823bbf2642292f800dea47fc8ca00cb1f01cf16c9ed542092f80fdedb3cd80f02ae9401d200018eccd72c08142091709601d72c081c12e25210b18e3230d72c08248e27d200ed44d0d2005113baf26b54503091319b01810170d721d70a00f2aae2c8ca0058cf16c9ed5492f229e2e30dd74cd001e8d74c011110005021d739309420c700b38e19d72820761e436c20d71d06c712c2005220b0f265d74cd73930e85bed55008e01fa4001fa44f828fa443058baf2aded44d0810171d718f405049c7fc8ca0040048307f453f2a78e12038307f45bf2a822d70a00216e01b3b0f26ce2c85003cf1612f400c9ed54edaac72e"}
{"hex":"b5ee9c724102120100027a000114ff00f4a413f4bcf2c80b01020120030201eaf220d70b1f82107369676ebaf2af7f8ee3eda2edfb218308d722028308d723208020d721d31fd31fd31fed44d0d200d31f20d31fd70bff09f90140b9f9109927945f09db31e1f223df01f2a05122baf2a15036baf2a2f823bbf2642292f800dea47fc8ca00cb1f01cf16c9ed542092f80fdedb3cd80f0201480d0402012006050019be5f0f6a2684080a0eb90fa02c0201200c0702012009080019b45d1da89a10043ae43ae163f00201200b0a0011b262fb513435c280200017b325fb51341c75c875c2c7e00019bb39ced44d08041d721d70bff80280d020c702dc01d0d60301c713dc01d72c232bc3a3748ea701fa4030fa44f828fa443058badded44d0810141d721f4058307f40e6fa131dd8040d72170db3ce30e0f0e01f83120d70b1f821073696e74badd20d749810281b9dc708ee3eda2edfb218308d722028308d723208020d721d31fd31fd31fed44d0d200d31f20d31fd70bff09f90140b9f9109927945f09db31e1f223df01f2a05122baf2a15036baf2a2f823bbf2642292f800dea47fc8ca00cb1f01cf16c9ed542092f80fdedb3cd80f02ae9401d200018eccd72c08142091709601d72c081c12e25210b18e3230d72c08248e27d200ed44d0d2005113baf26b54503091319b01810140d721d70a00f2aae2c8ca0058cf16c9ed5492f229e2e30dd74cd001e8d74c011110005021d739309420c700b38e19d72820761e436c20d71d06c712c2005220b0f265d74cd73930e85bed55008e01fa4001fa44f828fa443058baf2aded44d0810141d718f405049c7fc8ca0040048307f453f2a78e12038307f45bf2a822d70a00216e01b3b0f26ce2c85003cf1612f400c9ed54a9269d25"}
2 changes: 1 addition & 1 deletion contracts/wallet_v5.fc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const int error::invalid_message_type = 47;

const int size::bool = 1;
const int size::seqno = 32;
const int size::wallet_id = 80;
const int size::wallet_id = 32;
const int size::public_key = 256;
const int size::valid_until = 32;
const int size::message_flags = 4;
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet-v5-extensions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Wallet V5 extensions auth', () => {
function createBody(actionsList: Cell) {
const payload = beginCell()
.storeUint(Opcodes.auth_signed_internal, 32)
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(validUntil(), 32)
.storeUint(seqno, 32) // seqno
.storeSlice(actionsList.beginParse())
Expand Down
16 changes: 8 additions & 8 deletions tests/wallet-v5-external.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Wallet V5 sign auth external', () => {
function createBody(actionsList: Cell) {
const payload = beginCell()
.storeUint(Opcodes.auth_signed, 32)
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(validUntil(), 32)
.storeUint(seqno, 32) // seqno
.storeSlice(actionsList.beginParse())
Expand Down Expand Up @@ -475,15 +475,15 @@ describe('Wallet V5 sign auth external', () => {
const vu = validUntil();

const payload = beginCell()
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(vu, 32)
.storeUint(seqno, 32) // seqno
.storeSlice(actionsList.beginParse())
.endCell();

const fakePayload = beginCell()
.storeUint(Opcodes.auth_signed, 32)
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(vu, 32)
.storeUint(seqno + 1, 32) // seqno
.storeSlice(actionsList.beginParse())
Expand Down Expand Up @@ -514,7 +514,7 @@ describe('Wallet V5 sign auth external', () => {

const payload = beginCell()
.storeUint(Opcodes.auth_signed, 32)
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(validUntil(), 32)
.storeUint(seqno, 32) // seqno
.storeSlice(actionsList.beginParse())
Expand Down Expand Up @@ -547,7 +547,7 @@ describe('Wallet V5 sign auth external', () => {

const payload = beginCell()
.storeUint(Opcodes.auth_signed, 32)
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(validUntil(), 32)
.storeUint(seqno + 1, 32) // seqno
.storeSlice(actionsList.beginParse())
Expand Down Expand Up @@ -578,7 +578,7 @@ describe('Wallet V5 sign auth external', () => {

const payload = beginCell()
.storeUint(Opcodes.auth_signed, 32)
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(Math.round(Date.now() / 1000) - 600, 32)
.storeUint(seqno, 32)
.storeSlice(actionsList.beginParse())
Expand Down Expand Up @@ -609,7 +609,7 @@ describe('Wallet V5 sign auth external', () => {

const payload = beginCell()
.storeUint(Opcodes.auth_signed, 32)
.storeUint(new WalletId({ ...WALLET_ID, subwalletNumber: 1 }).serialized, 80)
.storeUint(new WalletId({ ...WALLET_ID, subwalletNumber: 1 }).serialized, 32)
.storeUint(validUntil(), 32)
.storeUint(seqno, 32)
.storeSlice(actionsList.beginParse())
Expand Down Expand Up @@ -640,7 +640,7 @@ describe('Wallet V5 sign auth external', () => {

const payload = beginCell() // auth_signed_internal used instead of auth_signed
.storeUint(Opcodes.auth_signed_internal, 32)
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(validUntil(), 32)
.storeUint(seqno, 32)
.storeSlice(actionsList.beginParse())
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet-v5-get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Wallet V5 get methods', () => {
});
await deploy({ walletId: expectedWalletId.serialized });
const actualWalletId = await walletV5.getWalletId();
expect(expectedWalletId.serialized).toEqual(actualWalletId.serialized);
expect(expectedWalletId.subwalletNumber).toEqual(actualWalletId.subwalletNumber);
});

it('Get subwallet number', async () => {
Expand Down
16 changes: 8 additions & 8 deletions tests/wallet-v5-internal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('Wallet V5 sign auth internal', () => {
function createBody(actionsList: Cell) {
const payload = beginCell()
.storeUint(Opcodes.auth_signed_internal, 32)
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(validUntil(), 32)
.storeUint(seqno, 32) // seqno
.storeSlice(actionsList.beginParse())
Expand Down Expand Up @@ -471,14 +471,14 @@ describe('Wallet V5 sign auth internal', () => {

const payload = beginCell()
.storeUint(Opcodes.auth_signed_internal, 32)
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(vu, 32)
.storeUint(seqno, 32) // seqno
.storeSlice(actionsList.beginParse())
.endCell();

const fakePayload = beginCell()
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(vu, 32)
.storeUint(seqno + 1, 32) // seqno
.storeSlice(actionsList.beginParse())
Expand Down Expand Up @@ -523,7 +523,7 @@ describe('Wallet V5 sign auth internal', () => {

const payload = beginCell()
.storeUint(Opcodes.auth_signed_internal, 32)
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(validUntil(), 32)
.storeUint(seqno, 32) // seqno
.storeSlice(actionsList.beginParse())
Expand Down Expand Up @@ -577,7 +577,7 @@ describe('Wallet V5 sign auth internal', () => {

const payload = beginCell()
.storeUint(Opcodes.auth_signed_internal, 32)
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(validUntil(), 32)
.storeUint(seqno + 1, 32) // seqno
.storeSlice(actionsList.beginParse())
Expand Down Expand Up @@ -622,7 +622,7 @@ describe('Wallet V5 sign auth internal', () => {

const payload = beginCell()
.storeUint(Opcodes.auth_signed_internal, 32)
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(Math.round(Date.now() / 1000) - 600, 32)
.storeUint(seqno, 32)
.storeSlice(actionsList.beginParse())
Expand Down Expand Up @@ -667,7 +667,7 @@ describe('Wallet V5 sign auth internal', () => {

const payload = beginCell()
.storeUint(Opcodes.auth_signed_internal, 32)
.storeUint(new WalletId({ ...WALLET_ID, subwalletNumber: 1 }).serialized, 80)
.storeUint(new WalletId({ ...WALLET_ID, subwalletNumber: 1 }).serialized, 32)
.storeUint(validUntil(), 32)
.storeUint(seqno, 32)
.storeSlice(actionsList.beginParse())
Expand Down Expand Up @@ -712,7 +712,7 @@ describe('Wallet V5 sign auth internal', () => {

const payload = beginCell() // auth_signed used instead of auth_signed_internal
.storeUint(Opcodes.auth_signed, 32)
.storeUint(WALLET_ID.serialized, 80)
.storeUint(WALLET_ID.serialized, 32)
.storeUint(validUntil(), 32)
.storeUint(seqno, 32)
.storeSlice(actionsList.beginParse())
Expand Down
62 changes: 31 additions & 31 deletions wrappers/wallet-v5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function walletV5ConfigToCell(config: WalletV5Config): Cell {
return beginCell()
.storeBit(config.signatureAllowed)
.storeUint(config.seqno, 32)
.storeUint(config.walletId, 80)
.storeUint(config.walletId, 32)
.storeBuffer(config.publicKey, 32)
.storeDict(config.extensions, Dictionary.Keys.BigUint(256), Dictionary.Values.BigInt(1))
.endCell();
Expand All @@ -49,30 +49,30 @@ export class WalletId {
v5: 0
};

static deserialize(walletId: bigint | Buffer): WalletId {
const bitReader = new BitReader(
new BitString(
typeof walletId === 'bigint' ? Buffer.from(walletId.toString(16), 'hex') : walletId,
0,
80
)
);
const networkGlobalId = bitReader.loadInt(32);
const workChain = bitReader.loadInt(8);
const walletVersionRaw = bitReader.loadUint(8);
const subwalletNumber = bitReader.loadUint(32);

const walletVersion = Object.entries(this.versionsSerialisation).find(
([_, value]) => value === walletVersionRaw
)?.[0] as WalletId['walletVersion'] | undefined;

if (walletVersion === undefined) {
throw new Error(
`Can't deserialize walletId: unknown wallet version ${walletVersionRaw}`
);
}

return new WalletId({ networkGlobalId, workChain, walletVersion, subwalletNumber });
static deserialize(walletId: bigint): WalletId {
// const bitReader = new BitReader(
// new BitString(
// typeof walletId === 'bigint' ? Buffer.from(walletId.toString(16), 'hex') : walletId,
// 0,
// 32
// )
// );
// const networkGlobalId = bitReader.loadInt(32);
// const workChain = bitReader.loadInt(8);
// const walletVersionRaw = bitReader.loadUint(8);
const subwalletNumber = walletId;
//
// const walletVersion = Object.entries(this.versionsSerialisation).find(
// ([_, value]) => value === walletVersionRaw
// )?.[0] as WalletId['walletVersion'] | undefined;
//
// if (walletVersion === undefined) {
// throw new Error(
// `Can't deserialize walletId: unknown wallet version ${walletVersionRaw}`
// );
// }
//
return new WalletId({ networkGlobalId: 0, workChain: 0, walletVersion: 'v5', subwalletNumber: Number(walletId) });
}

readonly walletVersion: 'v5';
Expand All @@ -97,13 +97,13 @@ export class WalletId {
this.subwalletNumber = args?.subwalletNumber ?? 0;
this.walletVersion = args?.walletVersion ?? 'v5';

const bitBuilder = new BitBuilder(80);
bitBuilder.writeInt(this.networkGlobalId, 32);
bitBuilder.writeInt(this.workChain, 8);
bitBuilder.writeUint(WalletId.versionsSerialisation[this.walletVersion], 8);
bitBuilder.writeUint(this.subwalletNumber, 32);
// const bitBuilder = new BitBuilder(32);
// bitBuilder.writeInt(this.networkGlobalId, 32);
// bitBuilder.writeInt(this.workChain, 8);
// bitBuilder.writeUint(WalletId.versionsSerialisation[this.walletVersion], 8);
// bitBuilder.writeUint(this.subwalletNumber, 32);

this.serialized = bufferToBigInt(bitBuilder.buffer());
this.serialized = BigInt(this.subwalletNumber) // bufferToBigInt(bitBuilder.buffer());
}
}

Expand Down

0 comments on commit 68a0866

Please sign in to comment.