@tari-project/tari-permissions 0.4.0 → 0.5.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.
@@ -0,0 +1,2 @@
1
+ import { TariPermission } from "./tari_permissions";
2
+ export declare function createPermissionFromType(permission: any): TariPermission;
@@ -0,0 +1,29 @@
1
+ import { TariPermissionAccountBalance, TariPermissionAccountInfo, TariPermissionAccountList, TariPermissionGetNft, TariPermissionKeyList, TariPermissionNftGetOwnershipProof, TariPermissionTransactionGet, TariPermissionTransactionSend, } from "./tari_permissions";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ export function createPermissionFromType(permission) {
4
+ if (Object.prototype.hasOwnProperty.call(permission, "AccountBalance")) {
5
+ return new TariPermissionAccountBalance(permission.AccountBalance);
6
+ }
7
+ else if (permission === "AccountInfo") {
8
+ return new TariPermissionAccountInfo();
9
+ }
10
+ else if (Object.prototype.hasOwnProperty.call(permission, "AccountList")) {
11
+ return new TariPermissionAccountList(permission.AccountList);
12
+ }
13
+ else if (permission == "KeyList") {
14
+ return new TariPermissionKeyList();
15
+ }
16
+ else if (Object.prototype.hasOwnProperty.call(permission, "TransactionSend")) {
17
+ return new TariPermissionTransactionSend(permission.TransactionSend);
18
+ }
19
+ else if (permission === "TransactionGet") {
20
+ return new TariPermissionTransactionGet();
21
+ }
22
+ else if (Object.prototype.hasOwnProperty.call(permission, "GetNft")) {
23
+ return new TariPermissionGetNft(permission.GetNft);
24
+ }
25
+ else if (Object.prototype.hasOwnProperty.call(permission, "NftGetOwnershipProof")) {
26
+ return new TariPermissionNftGetOwnershipProof(permission.NftGetOwnershipProof);
27
+ }
28
+ return permission;
29
+ }
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export * from './tari_permissions';
1
+ export * from "./tari_permissions";
2
+ export * from "./helpers";
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
- export * from './tari_permissions';
1
+ export * from "./tari_permissions";
2
+ export * from "./helpers";
@@ -214,3 +214,7 @@ export declare class TariPermissions {
214
214
  addPermissions(other: TariPermissions): this;
215
215
  toJSON(): TariPermission[];
216
216
  }
217
+ export type TappletPermissions = {
218
+ requiredPermissions: TariPermission[];
219
+ optionalPermissions: TariPermission[];
220
+ };
@@ -62,12 +62,12 @@ export class NonFungibleId {
62
62
  }
63
63
  toJSON() {
64
64
  switch (typeof this.value) {
65
- case 'string':
66
- return { 'string': this.value };
67
- case 'number':
68
- return { 'Uint64': this.value };
65
+ case "string":
66
+ return { string: this.value };
67
+ case "number":
68
+ return { Uint64: this.value };
69
69
  }
70
- return { 'U256': this.value };
70
+ return { U256: this.value };
71
71
  }
72
72
  }
73
73
  export class NonFungibleAddressContents {
@@ -78,7 +78,7 @@ export class NonFungibleAddressContents {
78
78
  this.id = id;
79
79
  }
80
80
  toJSON() {
81
- return { "resource_address": this.resource_address, "id": this.id };
81
+ return { resource_address: this.resource_address, id: this.id };
82
82
  }
83
83
  }
84
84
  export class NonFungibleAddress {
@@ -98,7 +98,7 @@ export class NonFungibleIndexAddress {
98
98
  this.index = index;
99
99
  }
100
100
  toJSON() {
101
- return { "resource_address": this.resource_address, "index": this.index };
101
+ return { resource_address: this.resource_address, index: this.index };
102
102
  }
103
103
  }
104
104
  export class ComponentAddress {
@@ -126,22 +126,22 @@ export class SubstateAddress {
126
126
  }
127
127
  toJSON() {
128
128
  if (this.value instanceof ComponentAddress) {
129
- return { "Component": this.value };
129
+ return { Component: this.value };
130
130
  }
131
131
  else if (this.value instanceof ResourceAddress) {
132
- return { "Resource": this.value };
132
+ return { Resource: this.value };
133
133
  }
134
134
  else if (this.value instanceof VaultId) {
135
- return { "Vault": this.value };
135
+ return { Vault: this.value };
136
136
  }
137
137
  else if (this.value instanceof UnclaimedConfidentialOutputAddress) {
138
- return { "UnclaimedConfidentialOutput": this.value };
138
+ return { UnclaimedConfidentialOutput: this.value };
139
139
  }
140
140
  else if (this.value instanceof NonFungibleAddress) {
141
- return { "NonFungible": this.value };
141
+ return { NonFungible: this.value };
142
142
  }
143
143
  else if (this.value instanceof NonFungibleIndexAddress) {
144
- return { "NonFungibleIndex": this.value };
144
+ return { NonFungibleIndex: this.value };
145
145
  }
146
146
  throw "Unknown type";
147
147
  }
@@ -153,7 +153,7 @@ export class TariPermissionAccountBalance {
153
153
  }
154
154
  toJSON() {
155
155
  console.log("stringify", this.value);
156
- return { "AccountBalance": this.value };
156
+ return { AccountBalance: this.value };
157
157
  }
158
158
  }
159
159
  export class TariPermissionAccountInfo {
@@ -173,12 +173,12 @@ export class TariPermissionAccountList {
173
173
  }
174
174
  }
175
175
  toJSON() {
176
- console.log('JSON TariPermissionAccountList', this.value);
176
+ console.log("JSON TariPermissionAccountList", this.value);
177
177
  if (this.value === undefined) {
178
- return { "AccountList": null };
178
+ return { AccountList: null };
179
179
  }
180
180
  else {
181
- return { "AccountList": this.value };
181
+ return { AccountList: this.value };
182
182
  }
183
183
  }
184
184
  }
@@ -200,12 +200,12 @@ export class TariPermissionTransactionSend {
200
200
  this.value = value;
201
201
  }
202
202
  toJSON() {
203
- console.log('JSON TariPermissionTransactionSend', this.value);
203
+ console.log("JSON TariPermissionTransactionSend", this.value);
204
204
  if (this.value === undefined) {
205
- return { "TransactionSend": null };
205
+ return { TransactionSend: null };
206
206
  }
207
207
  else {
208
- return { "TransactionSend": this.value };
208
+ return { TransactionSend: this.value };
209
209
  }
210
210
  }
211
211
  }
@@ -217,7 +217,7 @@ export class TariPermissionGetNft {
217
217
  this.value1 = value1;
218
218
  }
219
219
  toJSON() {
220
- return { "GetNft": [this.value0, this.value1] };
220
+ return { GetNft: [this.value0, this.value1] };
221
221
  }
222
222
  }
223
223
  export class TariPermissionNftGetOwnershipProof {
@@ -226,7 +226,7 @@ export class TariPermissionNftGetOwnershipProof {
226
226
  this.value = value;
227
227
  }
228
228
  toJSON() {
229
- return { "NftGetOwnershipProof": this.value };
229
+ return { NftGetOwnershipProof: this.value };
230
230
  }
231
231
  }
232
232
  export class TariPermissionTransactionsGet {
@@ -277,6 +277,3 @@ export class TariPermissions {
277
277
  return this.permissions;
278
278
  }
279
279
  }
280
- // TariPermissionType.prototype.toString = function () {
281
- // return "wtf"
282
- // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tari-project/tari-permissions",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {