@mysten/pas 0.0.1

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 (62) hide show
  1. package/README.md +1 -0
  2. package/dist/client.d.mts +117 -0
  3. package/dist/client.d.mts.map +1 -0
  4. package/dist/client.mjs +89 -0
  5. package/dist/client.mjs.map +1 -0
  6. package/dist/constants.mjs +9 -0
  7. package/dist/constants.mjs.map +1 -0
  8. package/dist/contracts/pas/deps/std/type_name.mjs +17 -0
  9. package/dist/contracts/pas/deps/std/type_name.mjs.map +1 -0
  10. package/dist/contracts/pas/deps/sui/vec_map.mjs +37 -0
  11. package/dist/contracts/pas/deps/sui/vec_map.mjs.map +1 -0
  12. package/dist/contracts/pas/deps/sui/vec_set.mjs +26 -0
  13. package/dist/contracts/pas/deps/sui/vec_set.mjs.map +1 -0
  14. package/dist/contracts/pas/policy.mjs +33 -0
  15. package/dist/contracts/pas/policy.mjs.map +1 -0
  16. package/dist/contracts/pas/versioning.mjs +25 -0
  17. package/dist/contracts/pas/versioning.mjs.map +1 -0
  18. package/dist/contracts/ptb/ptb.mjs +162 -0
  19. package/dist/contracts/ptb/ptb.mjs.map +1 -0
  20. package/dist/contracts/sui/dynamic_field.mjs +22 -0
  21. package/dist/contracts/sui/dynamic_field.mjs.map +1 -0
  22. package/dist/contracts/utils/index.mjs +37 -0
  23. package/dist/contracts/utils/index.mjs.map +1 -0
  24. package/dist/derivation.mjs +70 -0
  25. package/dist/derivation.mjs.map +1 -0
  26. package/dist/error.d.mts +16 -0
  27. package/dist/error.d.mts.map +1 -0
  28. package/dist/error.mjs +26 -0
  29. package/dist/error.mjs.map +1 -0
  30. package/dist/index.d.mts +4 -0
  31. package/dist/index.mjs +4 -0
  32. package/dist/intents.mjs +494 -0
  33. package/dist/intents.mjs.map +1 -0
  34. package/dist/resolution.mjs +185 -0
  35. package/dist/resolution.mjs.map +1 -0
  36. package/dist/types.d.mts +34 -0
  37. package/dist/types.d.mts.map +1 -0
  38. package/package.json +59 -0
  39. package/src/client.ts +173 -0
  40. package/src/constants.ts +15 -0
  41. package/src/contracts/pas/account.ts +343 -0
  42. package/src/contracts/pas/clawback_funds.ts +114 -0
  43. package/src/contracts/pas/deps/std/type_name.ts +24 -0
  44. package/src/contracts/pas/deps/sui/vec_map.ts +33 -0
  45. package/src/contracts/pas/deps/sui/vec_set.ts +22 -0
  46. package/src/contracts/pas/keys.ts +90 -0
  47. package/src/contracts/pas/namespace.ts +207 -0
  48. package/src/contracts/pas/policy.ts +212 -0
  49. package/src/contracts/pas/request.ts +87 -0
  50. package/src/contracts/pas/send_funds.ts +174 -0
  51. package/src/contracts/pas/templates.ts +101 -0
  52. package/src/contracts/pas/unlock_funds.ts +155 -0
  53. package/src/contracts/pas/versioning.ts +69 -0
  54. package/src/contracts/ptb/ptb.ts +821 -0
  55. package/src/contracts/sui/dynamic_field.ts +171 -0
  56. package/src/contracts/utils/index.ts +235 -0
  57. package/src/derivation.ts +107 -0
  58. package/src/error.ts +29 -0
  59. package/src/index.ts +6 -0
  60. package/src/intents.ts +852 -0
  61. package/src/resolution.ts +294 -0
  62. package/src/types.ts +34 -0
@@ -0,0 +1,171 @@
1
+ /**************************************************************
2
+ * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
3
+ **************************************************************/
4
+ import { type BcsType, bcs } from '@mysten/sui/bcs';
5
+ import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js';
6
+ import { type Transaction } from '@mysten/sui/transactions';
7
+ const $moduleName = '0x2::dynamic_field';
8
+ export function Field<T0 extends BcsType<any>, T1 extends BcsType<any>>(
9
+ ...typeParameters: [T0, T1]
10
+ ) {
11
+ return new MoveStruct({
12
+ name: `${$moduleName}::Field<${typeParameters[0].name as T0['name']}, ${typeParameters[1].name as T1['name']}>`,
13
+ fields: {
14
+ id: bcs.Address,
15
+ name: typeParameters[0],
16
+ value: typeParameters[1],
17
+ },
18
+ });
19
+ }
20
+ export interface AddOptions<T0 extends BcsType<any>, T1 extends BcsType<any>> {
21
+ package?: string;
22
+ arguments: [
23
+ RawTransactionArgument<string>,
24
+ RawTransactionArgument<T0>,
25
+ RawTransactionArgument<T1>,
26
+ ];
27
+ typeArguments: [string, string];
28
+ }
29
+ export function add<T0 extends BcsType<any>, T1 extends BcsType<any>>(options: AddOptions<T0, T1>) {
30
+ const packageAddress =
31
+ options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
32
+ const argumentsTypes = [
33
+ '0x2::object::ID',
34
+ `${options.typeArguments[0]}`,
35
+ `${options.typeArguments[1]}`,
36
+ ] satisfies (string | null)[];
37
+ return (tx: Transaction) =>
38
+ tx.moveCall({
39
+ package: packageAddress,
40
+ module: 'dynamic_field',
41
+ function: 'add',
42
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
43
+ typeArguments: options.typeArguments,
44
+ });
45
+ }
46
+ export interface BorrowOptions<T0 extends BcsType<any>> {
47
+ package?: string;
48
+ arguments: [RawTransactionArgument<string>, RawTransactionArgument<T0>];
49
+ typeArguments: [string, string];
50
+ }
51
+ export function borrow<T0 extends BcsType<any>>(options: BorrowOptions<T0>) {
52
+ const packageAddress =
53
+ options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
54
+ const argumentsTypes = ['0x2::object::ID', `${options.typeArguments[0]}`] satisfies (
55
+ | string
56
+ | null
57
+ )[];
58
+ return (tx: Transaction) =>
59
+ tx.moveCall({
60
+ package: packageAddress,
61
+ module: 'dynamic_field',
62
+ function: 'borrow',
63
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
64
+ typeArguments: options.typeArguments,
65
+ });
66
+ }
67
+ export interface BorrowMutOptions<T0 extends BcsType<any>> {
68
+ package?: string;
69
+ arguments: [RawTransactionArgument<string>, RawTransactionArgument<T0>];
70
+ typeArguments: [string, string];
71
+ }
72
+ export function borrowMut<T0 extends BcsType<any>>(options: BorrowMutOptions<T0>) {
73
+ const packageAddress =
74
+ options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
75
+ const argumentsTypes = ['0x2::object::ID', `${options.typeArguments[0]}`] satisfies (
76
+ | string
77
+ | null
78
+ )[];
79
+ return (tx: Transaction) =>
80
+ tx.moveCall({
81
+ package: packageAddress,
82
+ module: 'dynamic_field',
83
+ function: 'borrow_mut',
84
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
85
+ typeArguments: options.typeArguments,
86
+ });
87
+ }
88
+ export interface RemoveOptions<T0 extends BcsType<any>> {
89
+ package?: string;
90
+ arguments: [RawTransactionArgument<string>, RawTransactionArgument<T0>];
91
+ typeArguments: [string, string];
92
+ }
93
+ export function remove<T0 extends BcsType<any>>(options: RemoveOptions<T0>) {
94
+ const packageAddress =
95
+ options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
96
+ const argumentsTypes = ['0x2::object::ID', `${options.typeArguments[0]}`] satisfies (
97
+ | string
98
+ | null
99
+ )[];
100
+ return (tx: Transaction) =>
101
+ tx.moveCall({
102
+ package: packageAddress,
103
+ module: 'dynamic_field',
104
+ function: 'remove',
105
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
106
+ typeArguments: options.typeArguments,
107
+ });
108
+ }
109
+ export interface Exists_Options<T0 extends BcsType<any>> {
110
+ package?: string;
111
+ arguments: [RawTransactionArgument<string>, RawTransactionArgument<T0>];
112
+ typeArguments: [string];
113
+ }
114
+ export function exists_<T0 extends BcsType<any>>(options: Exists_Options<T0>) {
115
+ const packageAddress =
116
+ options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
117
+ const argumentsTypes = ['0x2::object::ID', `${options.typeArguments[0]}`] satisfies (
118
+ | string
119
+ | null
120
+ )[];
121
+ return (tx: Transaction) =>
122
+ tx.moveCall({
123
+ package: packageAddress,
124
+ module: 'dynamic_field',
125
+ function: 'exists_',
126
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
127
+ typeArguments: options.typeArguments,
128
+ });
129
+ }
130
+ export interface RemoveIfExistsOptions<T0 extends BcsType<any>> {
131
+ package?: string;
132
+ arguments: [RawTransactionArgument<string>, RawTransactionArgument<T0>];
133
+ typeArguments: [string, string];
134
+ }
135
+ export function removeIfExists<T0 extends BcsType<any>>(options: RemoveIfExistsOptions<T0>) {
136
+ const packageAddress =
137
+ options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
138
+ const argumentsTypes = ['0x2::object::ID', `${options.typeArguments[0]}`] satisfies (
139
+ | string
140
+ | null
141
+ )[];
142
+ return (tx: Transaction) =>
143
+ tx.moveCall({
144
+ package: packageAddress,
145
+ module: 'dynamic_field',
146
+ function: 'remove_if_exists',
147
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
148
+ typeArguments: options.typeArguments,
149
+ });
150
+ }
151
+ export interface ExistsWithTypeOptions<T0 extends BcsType<any>> {
152
+ package?: string;
153
+ arguments: [RawTransactionArgument<string>, RawTransactionArgument<T0>];
154
+ typeArguments: [string, string];
155
+ }
156
+ export function existsWithType<T0 extends BcsType<any>>(options: ExistsWithTypeOptions<T0>) {
157
+ const packageAddress =
158
+ options.package ?? '0x0000000000000000000000000000000000000000000000000000000000000002';
159
+ const argumentsTypes = ['0x2::object::ID', `${options.typeArguments[0]}`] satisfies (
160
+ | string
161
+ | null
162
+ )[];
163
+ return (tx: Transaction) =>
164
+ tx.moveCall({
165
+ package: packageAddress,
166
+ module: 'dynamic_field',
167
+ function: 'exists_with_type',
168
+ arguments: normalizeMoveArguments(options.arguments, argumentsTypes),
169
+ typeArguments: options.typeArguments,
170
+ });
171
+ }
@@ -0,0 +1,235 @@
1
+ import {
2
+ bcs,
3
+ BcsType,
4
+ TypeTag,
5
+ TypeTagSerializer,
6
+ BcsStruct,
7
+ BcsEnum,
8
+ BcsTuple,
9
+ } from '@mysten/sui/bcs';
10
+ import { normalizeSuiAddress } from '@mysten/sui/utils';
11
+ import { TransactionArgument, isArgument } from '@mysten/sui/transactions';
12
+ import { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
13
+ import { PASClientError } from '../../error.js';
14
+
15
+ const MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1');
16
+ const SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');
17
+
18
+ export type RawTransactionArgument<T> = T | TransactionArgument;
19
+
20
+ export interface GetOptions<
21
+ Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {},
22
+ > extends SuiClientTypes.GetObjectOptions<Include> {
23
+ client: ClientWithCoreApi;
24
+ }
25
+
26
+ export interface GetManyOptions<
27
+ Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {},
28
+ > extends SuiClientTypes.GetObjectsOptions<Include> {
29
+ client: ClientWithCoreApi;
30
+ }
31
+
32
+ export function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {
33
+ const parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;
34
+
35
+ if ('u8' in parsedTag) {
36
+ return bcs.U8;
37
+ } else if ('u16' in parsedTag) {
38
+ return bcs.U16;
39
+ } else if ('u32' in parsedTag) {
40
+ return bcs.U32;
41
+ } else if ('u64' in parsedTag) {
42
+ return bcs.U64;
43
+ } else if ('u128' in parsedTag) {
44
+ return bcs.U128;
45
+ } else if ('u256' in parsedTag) {
46
+ return bcs.U256;
47
+ } else if ('address' in parsedTag) {
48
+ return bcs.Address;
49
+ } else if ('bool' in parsedTag) {
50
+ return bcs.Bool;
51
+ } else if ('vector' in parsedTag) {
52
+ const type = getPureBcsSchema(parsedTag.vector);
53
+ return type ? bcs.vector(type) : null;
54
+ } else if ('struct' in parsedTag) {
55
+ const structTag = parsedTag.struct;
56
+ const pkg = normalizeSuiAddress(structTag.address);
57
+
58
+ if (pkg === MOVE_STDLIB_ADDRESS) {
59
+ if (
60
+ (structTag.module === 'ascii' || structTag.module === 'string') &&
61
+ structTag.name === 'String'
62
+ ) {
63
+ return bcs.String;
64
+ }
65
+
66
+ if (structTag.module === 'option' && structTag.name === 'Option') {
67
+ const type = getPureBcsSchema(structTag.typeParams[0]);
68
+ return type ? bcs.option(type) : null;
69
+ }
70
+ }
71
+
72
+ if (
73
+ pkg === SUI_FRAMEWORK_ADDRESS &&
74
+ structTag.module === 'object' &&
75
+ (structTag.name === 'ID' || structTag.name === 'UID')
76
+ ) {
77
+ return bcs.Address;
78
+ }
79
+ }
80
+
81
+ return null;
82
+ }
83
+
84
+ export function normalizeMoveArguments(
85
+ args: unknown[] | object,
86
+ argTypes: readonly (string | null)[],
87
+ parameterNames?: string[],
88
+ ) {
89
+ const argLen = Array.isArray(args) ? args.length : Object.keys(args).length;
90
+ if (parameterNames && argLen !== parameterNames.length) {
91
+ throw new PASClientError(
92
+ `Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`,
93
+ );
94
+ }
95
+
96
+ const normalizedArgs: TransactionArgument[] = [];
97
+
98
+ let index = 0;
99
+ for (const [i, argType] of argTypes.entries()) {
100
+ if (argType === '0x2::clock::Clock') {
101
+ normalizedArgs.push((tx) => tx.object.clock());
102
+ continue;
103
+ }
104
+
105
+ if (argType === '0x2::random::Random') {
106
+ normalizedArgs.push((tx) => tx.object.random());
107
+ continue;
108
+ }
109
+
110
+ if (argType === '0x2::deny_list::DenyList') {
111
+ normalizedArgs.push((tx) => tx.object.denyList());
112
+ continue;
113
+ }
114
+
115
+ if (argType === '0x3::sui_system::SuiSystemState') {
116
+ normalizedArgs.push((tx) => tx.object.system());
117
+ continue;
118
+ }
119
+
120
+ let arg;
121
+ if (Array.isArray(args)) {
122
+ if (index >= args.length) {
123
+ throw new PASClientError(
124
+ `Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`,
125
+ );
126
+ }
127
+ arg = args[index];
128
+ } else {
129
+ if (!parameterNames) {
130
+ throw new PASClientError(`Expected arguments to be passed as an array`);
131
+ }
132
+ const name = parameterNames[index];
133
+ arg = args[name as keyof typeof args];
134
+
135
+ if (arg === undefined) {
136
+ throw new PASClientError(`Parameter ${name} is required`);
137
+ }
138
+ }
139
+
140
+ index += 1;
141
+
142
+ if (typeof arg === 'function' || isArgument(arg)) {
143
+ normalizedArgs.push(arg as TransactionArgument);
144
+ continue;
145
+ }
146
+
147
+ const type = argTypes[i];
148
+ const bcsType = type === null ? null : getPureBcsSchema(type);
149
+
150
+ if (bcsType) {
151
+ const bytes = bcsType.serialize(arg as never);
152
+ normalizedArgs.push((tx) => tx.pure(bytes));
153
+ continue;
154
+ } else if (typeof arg === 'string') {
155
+ normalizedArgs.push((tx) => tx.object(arg));
156
+ continue;
157
+ }
158
+
159
+ throw new PASClientError(`Invalid argument ${stringify(arg)} for type ${type}`);
160
+ }
161
+
162
+ return normalizedArgs;
163
+ }
164
+
165
+ export class MoveStruct<
166
+ T extends Record<string, BcsType<any>>,
167
+ const Name extends string = string,
168
+ > extends BcsStruct<T, Name> {
169
+ async get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
170
+ objectId,
171
+ ...options
172
+ }: GetOptions<Include>): Promise<
173
+ SuiClientTypes.Object<Include & { content: true; json: true }> & {
174
+ json: BcsStruct<T>['$inferType'];
175
+ }
176
+ > {
177
+ const [res] = await this.getMany<Include>({
178
+ ...options,
179
+ objectIds: [objectId],
180
+ });
181
+
182
+ return res;
183
+ }
184
+
185
+ async getMany<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({
186
+ client,
187
+ ...options
188
+ }: GetManyOptions<Include>): Promise<
189
+ Array<
190
+ SuiClientTypes.Object<Include & { content: true; json: true }> & {
191
+ json: BcsStruct<T>['$inferType'];
192
+ }
193
+ >
194
+ > {
195
+ const response = (await client.core.getObjects({
196
+ ...options,
197
+ include: {
198
+ ...options.include,
199
+ content: true,
200
+ },
201
+ })) as SuiClientTypes.GetObjectsResponse<Include & { content: true }>;
202
+
203
+ return response.objects.map((obj) => {
204
+ if (obj instanceof Error) {
205
+ throw obj;
206
+ }
207
+
208
+ return {
209
+ ...obj,
210
+ json: this.parse(obj.content),
211
+ };
212
+ });
213
+ }
214
+ }
215
+
216
+ export class MoveEnum<
217
+ T extends Record<string, BcsType<any> | null>,
218
+ const Name extends string,
219
+ > extends BcsEnum<T, Name> {}
220
+
221
+ export class MoveTuple<
222
+ const T extends readonly BcsType<any>[],
223
+ const Name extends string,
224
+ > extends BcsTuple<T, Name> {}
225
+
226
+ function stringify(val: unknown) {
227
+ if (typeof val === 'object') {
228
+ return JSON.stringify(val, (val: unknown) => val);
229
+ }
230
+ if (typeof val === 'bigint') {
231
+ return val.toString();
232
+ }
233
+
234
+ return val;
235
+ }
@@ -0,0 +1,107 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { bcs } from '@mysten/sui/bcs';
5
+ import { deriveDynamicFieldID, deriveObjectID, normalizeSuiAddress } from '@mysten/sui/utils';
6
+
7
+ import type { PASPackageConfig } from './types.js';
8
+
9
+ /**
10
+ * Derives the account address for a given owner address.
11
+ *
12
+ * Accounts are derived using the namespace UID and a AccountKey(owner).
13
+ * The key structure in Move is: `AccountKey(address)`
14
+ *
15
+ * @param owner - The owner address (can be a user address or object address)
16
+ * @param packageConfig - PAS package configuration
17
+ * @returns The derived account object ID
18
+ */
19
+ export function deriveAccountAddress(owner: string, packageConfig: PASPackageConfig): string {
20
+ const { packageId, namespaceId } = packageConfig;
21
+
22
+ // Serialize the AccountKey(address) as the key
23
+ // AccountKey is a struct with a single field: address
24
+ const accountKeyBcs = bcs.struct('AccountKey', {
25
+ owner: bcs.Address,
26
+ });
27
+
28
+ const key = accountKeyBcs.serialize({ owner: normalizeSuiAddress(owner) }).toBytes();
29
+
30
+ // The type tag is the AccountKey type from the PAS package
31
+ const typeTag = `${packageId}::keys::AccountKey`;
32
+
33
+ return deriveObjectID(namespaceId, typeTag, key);
34
+ }
35
+
36
+ const DEFAULT_WRAP_TYPE = (t: string) => `0x2::balance::Balance<${t}>`;
37
+
38
+ export interface DerivePolicyOptions {
39
+ /** Transform the asset type before using it in the PolicyKey type tag.
40
+ * Defaults to wrapping with `0x2::balance::Balance<T>`.
41
+ * Pass `(t) => t` to use the raw type. */
42
+ wrapType?: (assetType: string) => string;
43
+ }
44
+
45
+ /**
46
+ * Derives the policy address for a given asset type T.
47
+ *
48
+ * Policies are derived using the namespace UID and a PolicyKey<T>().
49
+ * The key structure in Move is: `PolicyKey<phantom T>()`
50
+ *
51
+ * By default the asset type is wrapped as `Balance<T>` to match the current
52
+ * on-chain convention. Pass `options.wrapType` to override.
53
+ *
54
+ * @param assetType - The full type of the asset (e.g., "0x2::sui::SUI")
55
+ * @param packageConfig - PAS package configuration
56
+ * @param options - Optional derivation options
57
+ * @returns The derived policy object ID
58
+ */
59
+ export function derivePolicyAddress(
60
+ assetType: string,
61
+ packageConfig: PASPackageConfig,
62
+ options?: DerivePolicyOptions,
63
+ ): string {
64
+ const { packageId, namespaceId } = packageConfig;
65
+
66
+ const policyKeyBcs = new Uint8Array([0]);
67
+
68
+ const wrap = options?.wrapType ?? DEFAULT_WRAP_TYPE;
69
+ const typeTag = `${packageId}::keys::PolicyKey<${wrap(assetType)}>`;
70
+ return deriveObjectID(namespaceId, typeTag, policyKeyBcs);
71
+ }
72
+
73
+ /**
74
+ * Derives the templates object address for a given package configuration.
75
+ *
76
+ * Templates are derived using the namespace UID and a TemplateKey().
77
+ * The key structure in Move is: `TemplateKey()`
78
+ *
79
+ * @param packageConfig - PAS package configuration
80
+ * @returns The derived templates object ID
81
+ */
82
+ export function deriveTemplateRegistryAddress(packageConfig: PASPackageConfig): string {
83
+ const { packageId, namespaceId } = packageConfig;
84
+
85
+ // The type tag is the TemplateKey type from the PAS package
86
+ const typeTag = `${packageId}::keys::TemplateKey`;
87
+
88
+ return deriveObjectID(namespaceId, typeTag, new Uint8Array([0]));
89
+ }
90
+
91
+ /**
92
+ * Derives the dynamic field address for a template command on the Templates object.
93
+ *
94
+ * Templates store Commands as dynamic fields keyed by `TypeName` (the approval type's
95
+ * `type_name::with_defining_ids` value). The DF key type is `std::type_name::TypeName`
96
+ * which is a struct with a single `name: String` field.
97
+ *
98
+ * @param templatesId - The Templates object ID
99
+ * @param approvalTypeName - The fully qualified approval type name (e.g., "0x123::demo_usd::TransferApproval")
100
+ * @returns The derived dynamic field object ID
101
+ */
102
+ export function deriveTemplateAddress(templatesId: string, approvalTypeName: string): string {
103
+ // TypeName is a struct { name: String }, serialized as BCS string
104
+ const key = bcs.string().serialize(approvalTypeName).toBytes();
105
+
106
+ return deriveDynamicFieldID(templatesId, '0x1::type_name::TypeName', key);
107
+ }
package/src/error.ts ADDED
@@ -0,0 +1,29 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Base error class for PAS client errors
6
+ */
7
+ export class PASClientError extends Error {
8
+ constructor(message: string) {
9
+ super(message);
10
+ this.name = 'PASClientError';
11
+ }
12
+ }
13
+
14
+ export class PolicyNotFoundError extends PASClientError {
15
+ constructor(assetType: string, message?: string) {
16
+ super(message ?? `Policy not found for asset type ${assetType}.`);
17
+ this.name = 'PolicyNotFoundError';
18
+ }
19
+ }
20
+
21
+ export class InvalidObjectOwnershipError extends PASClientError {
22
+ constructor(objectId: string, ownerKind: string) {
23
+ super(
24
+ `Object ${objectId} has ownership kind "${ownerKind}" which is not allowed in PAS templates. ` +
25
+ `Only shared and immutable objects can be referenced by templates.`,
26
+ );
27
+ this.name = 'InvalidObjectOwnershipError';
28
+ }
29
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { PASClient, pas } from './client.js';
5
+ export type { PASClientConfig, PASPackageConfig, PASOptions } from './types.js';
6
+ export * from './error.js';