@tari-project/tari-permissions 0.4.0

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.
package/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, The Tari Developer Community
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1 @@
1
+ export * from './tari_permissions';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './tari_permissions';
@@ -0,0 +1,216 @@
1
+ export declare class Hash {
2
+ private value;
3
+ constructor(value: number[]);
4
+ toJSON(): number[];
5
+ }
6
+ export declare enum TAG {
7
+ ComponentAddress = 128,
8
+ Metadata = 129,
9
+ NonFungibleAddress = 130,
10
+ ResourceAddress = 131,
11
+ VaultId = 132,
12
+ TransactionReceipt = 134,
13
+ FeeClaim = 135
14
+ }
15
+ export declare class Tagged {
16
+ private value;
17
+ private tag;
18
+ constructor(tag: number, value: any);
19
+ toJSON(): {
20
+ "@@TAGGED@@": any[];
21
+ };
22
+ }
23
+ export declare class ResourceAddress {
24
+ private tagged;
25
+ constructor(hash: Hash);
26
+ toJSON(): {
27
+ "@@TAGGED@@": any[];
28
+ };
29
+ }
30
+ export declare class UnclaimedConfidentialOutputAddress {
31
+ private hash;
32
+ constructor(hash: Hash);
33
+ toJSON(): number[];
34
+ }
35
+ export type u64 = number;
36
+ export type u32 = number;
37
+ export declare class U256 {
38
+ private value;
39
+ constructor(value: number[]);
40
+ toJSON(): number[];
41
+ }
42
+ export type NonFungibleIdType = u32 | u64 | string | U256;
43
+ export declare class NonFungibleId {
44
+ private value;
45
+ constructor(value: NonFungibleIdType);
46
+ toJSON(): {
47
+ string: string;
48
+ Uint64?: undefined;
49
+ U256?: undefined;
50
+ } | {
51
+ Uint64: number;
52
+ string?: undefined;
53
+ U256?: undefined;
54
+ } | {
55
+ U256: U256;
56
+ string?: undefined;
57
+ Uint64?: undefined;
58
+ };
59
+ }
60
+ export declare class NonFungibleAddressContents {
61
+ private resource_address;
62
+ private id;
63
+ constructor(resource_address: ResourceAddress, id: NonFungibleId);
64
+ toJSON(): {
65
+ resource_address: ResourceAddress;
66
+ id: NonFungibleId;
67
+ };
68
+ }
69
+ export declare class NonFungibleAddress {
70
+ private tagged;
71
+ constructor(value: NonFungibleAddressContents);
72
+ toJSON(): {
73
+ "@@TAGGED@@": any[];
74
+ };
75
+ }
76
+ export declare class NonFungibleIndexAddress {
77
+ private resource_address;
78
+ private index;
79
+ constructor(resource_address: ResourceAddress, index: number);
80
+ toJSON(): {
81
+ resource_address: ResourceAddress;
82
+ index: number;
83
+ };
84
+ }
85
+ export declare class ComponentAddress {
86
+ private tagged;
87
+ constructor(hash: Hash);
88
+ toJSON(): {
89
+ "@@TAGGED@@": any[];
90
+ };
91
+ }
92
+ export declare class VaultId {
93
+ private tagged;
94
+ constructor(hash: Hash);
95
+ toJSON(): {
96
+ "@@TAGGED@@": any[];
97
+ };
98
+ }
99
+ export type SubstateAddressType = ResourceAddress | ComponentAddress | VaultId | UnclaimedConfidentialOutputAddress | NonFungibleAddress | NonFungibleIndexAddress;
100
+ export declare class SubstateAddress {
101
+ private value;
102
+ constructor(value: SubstateAddressType);
103
+ toJSON(): {
104
+ Component: ComponentAddress;
105
+ Resource?: undefined;
106
+ Vault?: undefined;
107
+ UnclaimedConfidentialOutput?: undefined;
108
+ NonFungible?: undefined;
109
+ NonFungibleIndex?: undefined;
110
+ } | {
111
+ Resource: ResourceAddress;
112
+ Component?: undefined;
113
+ Vault?: undefined;
114
+ UnclaimedConfidentialOutput?: undefined;
115
+ NonFungible?: undefined;
116
+ NonFungibleIndex?: undefined;
117
+ } | {
118
+ Vault: VaultId;
119
+ Component?: undefined;
120
+ Resource?: undefined;
121
+ UnclaimedConfidentialOutput?: undefined;
122
+ NonFungible?: undefined;
123
+ NonFungibleIndex?: undefined;
124
+ } | {
125
+ UnclaimedConfidentialOutput: UnclaimedConfidentialOutputAddress;
126
+ Component?: undefined;
127
+ Resource?: undefined;
128
+ Vault?: undefined;
129
+ NonFungible?: undefined;
130
+ NonFungibleIndex?: undefined;
131
+ } | {
132
+ NonFungible: NonFungibleAddress;
133
+ Component?: undefined;
134
+ Resource?: undefined;
135
+ Vault?: undefined;
136
+ UnclaimedConfidentialOutput?: undefined;
137
+ NonFungibleIndex?: undefined;
138
+ } | {
139
+ NonFungibleIndex: NonFungibleIndexAddress;
140
+ Component?: undefined;
141
+ Resource?: undefined;
142
+ Vault?: undefined;
143
+ UnclaimedConfidentialOutput?: undefined;
144
+ NonFungible?: undefined;
145
+ };
146
+ }
147
+ export declare class TariPermissionAccountBalance {
148
+ private value;
149
+ constructor(value: SubstateAddress);
150
+ toJSON(): {
151
+ AccountBalance: SubstateAddress;
152
+ };
153
+ }
154
+ export declare class TariPermissionAccountInfo {
155
+ constructor();
156
+ toJSON(): string;
157
+ }
158
+ export declare class TariPermissionAccountList {
159
+ private value?;
160
+ constructor(value?: ComponentAddress);
161
+ toJSON(): {
162
+ AccountList: ComponentAddress | null;
163
+ };
164
+ }
165
+ export declare class TariPermissionKeyList {
166
+ constructor();
167
+ toJSON(): string;
168
+ }
169
+ export declare class TariPermissionTransactionGet {
170
+ constructor();
171
+ toJSON(): string;
172
+ }
173
+ export declare class TariPermissionTransactionSend {
174
+ private value?;
175
+ constructor(value?: SubstateAddress);
176
+ toJSON(): {
177
+ TransactionSend: null;
178
+ } | {
179
+ TransactionSend: SubstateAddress;
180
+ };
181
+ }
182
+ export declare class TariPermissionGetNft {
183
+ private value0?;
184
+ private value1?;
185
+ constructor(value0?: SubstateAddress, value1?: ResourceAddress);
186
+ toJSON(): {
187
+ GetNft: (ResourceAddress | SubstateAddress | undefined)[];
188
+ };
189
+ }
190
+ export declare class TariPermissionNftGetOwnershipProof {
191
+ private value?;
192
+ constructor(value?: ResourceAddress);
193
+ toJSON(): {
194
+ NftGetOwnershipProof: ResourceAddress | undefined;
195
+ };
196
+ }
197
+ export declare class TariPermissionTransactionsGet {
198
+ constructor();
199
+ toJSON(): string;
200
+ }
201
+ export declare class TariPermissionSubstatesRead {
202
+ constructor();
203
+ toJSON(): string;
204
+ }
205
+ export declare class TariPermissionTemplatesRead {
206
+ constructor();
207
+ toJSON(): string;
208
+ }
209
+ export type TariPermission = TariPermissionNftGetOwnershipProof | TariPermissionAccountBalance | TariPermissionAccountInfo | TariPermissionAccountList | TariPermissionKeyList | TariPermissionTransactionGet | TariPermissionTransactionSend | TariPermissionGetNft | TariPermissionTransactionsGet | TariPermissionSubstatesRead | TariPermissionTemplatesRead | string;
210
+ export declare class TariPermissions {
211
+ private permissions;
212
+ constructor();
213
+ addPermission(permission: TariPermission): this;
214
+ addPermissions(other: TariPermissions): this;
215
+ toJSON(): TariPermission[];
216
+ }
@@ -0,0 +1,282 @@
1
+ export class Hash {
2
+ value;
3
+ constructor(value) {
4
+ this.value = value;
5
+ }
6
+ toJSON() {
7
+ return this.value;
8
+ }
9
+ }
10
+ export var TAG;
11
+ (function (TAG) {
12
+ TAG[TAG["ComponentAddress"] = 128] = "ComponentAddress";
13
+ TAG[TAG["Metadata"] = 129] = "Metadata";
14
+ TAG[TAG["NonFungibleAddress"] = 130] = "NonFungibleAddress";
15
+ TAG[TAG["ResourceAddress"] = 131] = "ResourceAddress";
16
+ TAG[TAG["VaultId"] = 132] = "VaultId";
17
+ TAG[TAG["TransactionReceipt"] = 134] = "TransactionReceipt";
18
+ TAG[TAG["FeeClaim"] = 135] = "FeeClaim";
19
+ })(TAG || (TAG = {}));
20
+ export class Tagged {
21
+ value;
22
+ tag;
23
+ constructor(tag, value) {
24
+ this.tag = tag;
25
+ this.value = value;
26
+ }
27
+ toJSON() {
28
+ return { "@@TAGGED@@": [this.tag, this.value] };
29
+ }
30
+ }
31
+ export class ResourceAddress {
32
+ tagged;
33
+ constructor(hash) {
34
+ this.tagged = new Tagged(TAG.ResourceAddress, hash);
35
+ }
36
+ toJSON() {
37
+ return this.tagged.toJSON();
38
+ }
39
+ }
40
+ export class UnclaimedConfidentialOutputAddress {
41
+ hash;
42
+ constructor(hash) {
43
+ this.hash = hash;
44
+ }
45
+ toJSON() {
46
+ return this.hash.toJSON();
47
+ }
48
+ }
49
+ export class U256 {
50
+ value;
51
+ constructor(value) {
52
+ this.value = value;
53
+ }
54
+ toJSON() {
55
+ return this.value;
56
+ }
57
+ }
58
+ export class NonFungibleId {
59
+ value;
60
+ constructor(value) {
61
+ this.value = value;
62
+ }
63
+ toJSON() {
64
+ switch (typeof this.value) {
65
+ case 'string':
66
+ return { 'string': this.value };
67
+ case 'number':
68
+ return { 'Uint64': this.value };
69
+ }
70
+ return { 'U256': this.value };
71
+ }
72
+ }
73
+ export class NonFungibleAddressContents {
74
+ resource_address;
75
+ id;
76
+ constructor(resource_address, id) {
77
+ this.resource_address = resource_address;
78
+ this.id = id;
79
+ }
80
+ toJSON() {
81
+ return { "resource_address": this.resource_address, "id": this.id };
82
+ }
83
+ }
84
+ export class NonFungibleAddress {
85
+ tagged;
86
+ constructor(value) {
87
+ this.tagged = new Tagged(TAG.NonFungibleAddress, value);
88
+ }
89
+ toJSON() {
90
+ return this.tagged.toJSON();
91
+ }
92
+ }
93
+ export class NonFungibleIndexAddress {
94
+ resource_address;
95
+ index;
96
+ constructor(resource_address, index) {
97
+ this.resource_address = resource_address;
98
+ this.index = index;
99
+ }
100
+ toJSON() {
101
+ return { "resource_address": this.resource_address, "index": this.index };
102
+ }
103
+ }
104
+ export class ComponentAddress {
105
+ tagged;
106
+ constructor(hash) {
107
+ this.tagged = new Tagged(TAG.ComponentAddress, hash);
108
+ }
109
+ toJSON() {
110
+ return this.tagged.toJSON();
111
+ }
112
+ }
113
+ export class VaultId {
114
+ tagged;
115
+ constructor(hash) {
116
+ this.tagged = new Tagged(TAG.VaultId, hash);
117
+ }
118
+ toJSON() {
119
+ return this.tagged.toJSON();
120
+ }
121
+ }
122
+ export class SubstateAddress {
123
+ value;
124
+ constructor(value) {
125
+ this.value = value;
126
+ }
127
+ toJSON() {
128
+ if (this.value instanceof ComponentAddress) {
129
+ return { "Component": this.value };
130
+ }
131
+ else if (this.value instanceof ResourceAddress) {
132
+ return { "Resource": this.value };
133
+ }
134
+ else if (this.value instanceof VaultId) {
135
+ return { "Vault": this.value };
136
+ }
137
+ else if (this.value instanceof UnclaimedConfidentialOutputAddress) {
138
+ return { "UnclaimedConfidentialOutput": this.value };
139
+ }
140
+ else if (this.value instanceof NonFungibleAddress) {
141
+ return { "NonFungible": this.value };
142
+ }
143
+ else if (this.value instanceof NonFungibleIndexAddress) {
144
+ return { "NonFungibleIndex": this.value };
145
+ }
146
+ throw "Unknown type";
147
+ }
148
+ }
149
+ export class TariPermissionAccountBalance {
150
+ value;
151
+ constructor(value) {
152
+ this.value = value;
153
+ }
154
+ toJSON() {
155
+ console.log("stringify", this.value);
156
+ return { "AccountBalance": this.value };
157
+ }
158
+ }
159
+ export class TariPermissionAccountInfo {
160
+ constructor() { }
161
+ toJSON() {
162
+ return "AccountInfo";
163
+ }
164
+ }
165
+ export class TariPermissionAccountList {
166
+ value;
167
+ constructor(value) {
168
+ if (value === undefined) {
169
+ this.value = null;
170
+ }
171
+ else {
172
+ this.value = value;
173
+ }
174
+ }
175
+ toJSON() {
176
+ console.log('JSON TariPermissionAccountList', this.value);
177
+ if (this.value === undefined) {
178
+ return { "AccountList": null };
179
+ }
180
+ else {
181
+ return { "AccountList": this.value };
182
+ }
183
+ }
184
+ }
185
+ export class TariPermissionKeyList {
186
+ constructor() { }
187
+ toJSON() {
188
+ return "KeyList";
189
+ }
190
+ }
191
+ export class TariPermissionTransactionGet {
192
+ constructor() { }
193
+ toJSON() {
194
+ return "TransactionGet";
195
+ }
196
+ }
197
+ export class TariPermissionTransactionSend {
198
+ value;
199
+ constructor(value) {
200
+ this.value = value;
201
+ }
202
+ toJSON() {
203
+ console.log('JSON TariPermissionTransactionSend', this.value);
204
+ if (this.value === undefined) {
205
+ return { "TransactionSend": null };
206
+ }
207
+ else {
208
+ return { "TransactionSend": this.value };
209
+ }
210
+ }
211
+ }
212
+ export class TariPermissionGetNft {
213
+ value0;
214
+ value1;
215
+ constructor(value0, value1) {
216
+ this.value0 = value0;
217
+ this.value1 = value1;
218
+ }
219
+ toJSON() {
220
+ return { "GetNft": [this.value0, this.value1] };
221
+ }
222
+ }
223
+ export class TariPermissionNftGetOwnershipProof {
224
+ value;
225
+ constructor(value) {
226
+ this.value = value;
227
+ }
228
+ toJSON() {
229
+ return { "NftGetOwnershipProof": this.value };
230
+ }
231
+ }
232
+ export class TariPermissionTransactionsGet {
233
+ constructor() { }
234
+ toJSON() {
235
+ return "TransactionGet";
236
+ }
237
+ }
238
+ export class TariPermissionSubstatesRead {
239
+ constructor() { }
240
+ toJSON() {
241
+ return "SubstatesRead";
242
+ }
243
+ }
244
+ export class TariPermissionTemplatesRead {
245
+ constructor() { }
246
+ toJSON() {
247
+ return "TemplatesRead";
248
+ }
249
+ }
250
+ // export enum TariPermission {
251
+ // AccountBalance = "AccountBalance",
252
+ // AccountInfo = "AccountInfo",
253
+ // AccountList = "AccountList",
254
+ // KeyList = "KeyList",
255
+ // TransactionGet = "TransactionGet",
256
+ // TransactionSend = "TransactionSend",
257
+ // GetNft = "GetNft",
258
+ // NftGetOwnershipProof = "NftGetOwnershipProof",
259
+ // TransactionsGet = "TransactionsGet",
260
+ // SubstatesRead = "SubstatesRead",
261
+ // TemplatesRead = "TemplatesRead",
262
+ // }
263
+ export class TariPermissions {
264
+ permissions;
265
+ constructor() {
266
+ this.permissions = [];
267
+ }
268
+ addPermission(permission) {
269
+ this.permissions.push(permission);
270
+ return this;
271
+ }
272
+ addPermissions(other) {
273
+ this.permissions.push(...other.permissions);
274
+ return this;
275
+ }
276
+ toJSON() {
277
+ return this.permissions;
278
+ }
279
+ }
280
+ // TariPermissionType.prototype.toString = function () {
281
+ // return "wtf"
282
+ // }
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@tari-project/tari-permissions",
3
+ "version": "0.4.0",
4
+ "description": "",
5
+ "type": "module",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "dependencies": {},
13
+ "devDependencies": {
14
+ "@types/node": "^22.13.1",
15
+ "typescript": "^5.0.4"
16
+ },
17
+ "files": [
18
+ "/dist"
19
+ ],
20
+ "main": "dist/index.js",
21
+ "types": "dist/index.d.ts",
22
+ "scripts": {
23
+ "build": "tsc -b"
24
+ }
25
+ }