@thru/programs 0.2.27 → 0.2.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/multicall/index.cjs +166 -24
  2. package/dist/multicall/index.cjs.map +1 -1
  3. package/dist/multicall/index.d.cts +39 -3
  4. package/dist/multicall/index.d.ts +39 -3
  5. package/dist/multicall/index.js +166 -25
  6. package/dist/multicall/index.js.map +1 -1
  7. package/dist/passkey-manager/index.cjs +1235 -345
  8. package/dist/passkey-manager/index.cjs.map +1 -1
  9. package/dist/passkey-manager/index.d.cts +45 -11
  10. package/dist/passkey-manager/index.d.ts +45 -11
  11. package/dist/passkey-manager/index.js +1225 -346
  12. package/dist/passkey-manager/index.js.map +1 -1
  13. package/package.json +2 -2
  14. package/src/multicall/abi/thru/common/primitives/types.ts +14 -9
  15. package/src/multicall/abi/thru/program/multicall/types.ts +136 -4
  16. package/src/multicall/index.ts +6 -17
  17. package/src/passkey-manager/abi/thru/blockchain/state_proof/types.ts +11 -6
  18. package/src/passkey-manager/abi/thru/common/primitives/types.ts +19 -14
  19. package/src/passkey-manager/abi/thru/program/passkey_manager/types.ts +1069 -271
  20. package/src/passkey-manager/accounts.ts +79 -40
  21. package/src/passkey-manager/constants.ts +10 -1
  22. package/src/passkey-manager/index.ts +18 -2
  23. package/src/passkey-manager/instructions/add-authority.ts +31 -3
  24. package/src/passkey-manager/instructions/create.ts +106 -11
  25. package/src/passkey-manager/instructions/invoke.ts +9 -0
  26. package/src/passkey-manager/instructions/shared.ts +15 -0
  27. package/src/passkey-manager/instructions/transfer.ts +1 -1
  28. package/src/passkey-manager/instructions/validate.ts +13 -43
  29. package/src/passkey-manager/types.ts +7 -2
  30. package/src/passkey-manager/validate.test.ts +71 -3
@@ -2,7 +2,14 @@ import { createHash } from 'node:crypto';
2
2
  import { describe, expect, it } from 'vitest';
3
3
  import { encodeAddress } from '@thru/sdk/helpers';
4
4
  import { createValidateChallenge } from './challenge';
5
+ import { parseWalletAuthorities } from './accounts';
6
+ import { LONG_LIVED_AUTHORITY_EXPIRY_SECONDS } from './constants';
5
7
  import { encodeAddAuthorityInstruction } from './instructions/add-authority';
8
+ import {
9
+ buildAuthorityRecord,
10
+ createAuthorityRecord,
11
+ createSessionAuthorityRecord,
12
+ } from './instructions/create';
6
13
  import { encodeRemoveAuthorityInstruction } from './instructions/remove-authority';
7
14
  import { encodeValidateInstruction } from './instructions/validate';
8
15
  import {
@@ -133,16 +140,17 @@ describe('passkey manager validate helpers', () => {
133
140
  it('encodes wallet indexes in add/remove authority instructions', () => {
134
141
  const add = encodeAddAuthorityInstruction({
135
142
  walletAccountIdx: 0x1234,
136
- authority: {
143
+ authorityRecord: createAuthorityRecord({
137
144
  tag: 1,
138
145
  pubkeyX: bytes(0x01, 32),
139
146
  pubkeyY: bytes(0x02, 32),
140
- },
147
+ }),
141
148
  });
142
149
  expect(add[0]).toBe(0x04);
143
150
  expect(add.slice(1, 3)).toEqual(u16le(0x1234));
144
151
  expect(add[3]).toBe(1);
145
- expect(add.length).toBe(68);
152
+ expect(add.slice(68, 76)).toEqual(u64le(LONG_LIVED_AUTHORITY_EXPIRY_SECONDS));
153
+ expect(add.length).toBe(76);
146
154
 
147
155
  const remove = encodeRemoveAuthorityInstruction({
148
156
  walletAccountIdx: 0x1234,
@@ -151,6 +159,66 @@ describe('passkey manager validate helpers', () => {
151
159
  expect(remove).toEqual(new Uint8Array([0x05, 0x34, 0x12, 0x09]));
152
160
  });
153
161
 
162
+ it('encodes and parses authority records with expiry seconds', () => {
163
+ const passkeyRecord = createAuthorityRecord({
164
+ tag: 1,
165
+ pubkeyX: bytes(0x01, 32),
166
+ pubkeyY: bytes(0x02, 32),
167
+ });
168
+ const sessionRecord = createSessionAuthorityRecord({
169
+ pubkey: bytes(0x03, 32),
170
+ expiresAtBlockTimeSeconds: 1234n,
171
+ });
172
+
173
+ const encodedSession = buildAuthorityRecord(sessionRecord);
174
+ expect(encodedSession.length).toBe(73);
175
+ expect(encodedSession[0]).toBe(2);
176
+ expect(encodedSession.slice(1, 33)).toEqual(bytes(0x03, 32));
177
+ expect(encodedSession.slice(33, 65)).toEqual(bytes(0x00, 32));
178
+ expect(encodedSession.slice(65, 73)).toEqual(u64le(1234n));
179
+
180
+ const walletData = concat([
181
+ new Uint8Array([1]),
182
+ u64le(9n),
183
+ buildAuthorityRecord(passkeyRecord),
184
+ encodedSession,
185
+ ]);
186
+ const parsed = parseWalletAuthorities(walletData);
187
+ expect(parsed.nonce).toBe(9n);
188
+ expect(parsed.authorities).toHaveLength(2);
189
+ expect(parsed.authorities[0]?.expiresAtBlockTimeSeconds).toBe(
190
+ LONG_LIVED_AUTHORITY_EXPIRY_SECONDS
191
+ );
192
+ expect(parsed.authorities[1]).toMatchObject({
193
+ idx: 1,
194
+ kind: 'pubkey',
195
+ expiresAtBlockTimeSeconds: 1234n,
196
+ });
197
+ });
198
+
199
+ it('bounds authority record expiry seconds to u64', () => {
200
+ const u64Max = 0xffffffffffffffffn;
201
+ const pubkey = bytes(0x03, 32);
202
+
203
+ expect(() =>
204
+ buildAuthorityRecord(
205
+ createSessionAuthorityRecord({
206
+ pubkey,
207
+ expiresAtBlockTimeSeconds: u64Max,
208
+ })
209
+ )
210
+ ).not.toThrow();
211
+
212
+ expect(() =>
213
+ buildAuthorityRecord(
214
+ createSessionAuthorityRecord({
215
+ pubkey,
216
+ expiresAtBlockTimeSeconds: u64Max + 1n,
217
+ })
218
+ )
219
+ ).toThrow('expiresAtBlockTimeSeconds must fit in u64');
220
+ });
221
+
154
222
  it('encodes multicall instructions with the known program address', () => {
155
223
  expect(MULTICALL_PROGRAM_ADDRESS).toBe(
156
224
  'taAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkJ'