@audius/sdk 1.0.10 → 1.0.11

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.
@@ -4,7 +4,8 @@ import type { Web3Manager } from '../web3Manager';
4
4
  export declare enum Action {
5
5
  CREATE = "Create",
6
6
  UPDATE = "Update",
7
- DELETE = "Delete"
7
+ DELETE = "Delete",
8
+ VERIFY = "Verify"
8
9
  }
9
10
  export declare enum EntityType {
10
11
  PLAYLIST = "Playlist",
@@ -19,7 +20,17 @@ export declare class EntityManagerClient extends ContractClient {
19
20
  web3Manager: Web3Manager;
20
21
  static Action: typeof Action;
21
22
  static EntityType: typeof EntityType;
22
- manageEntity(userId: number, entityType: EntityType, entityId: number, action: Action, metadataMultihash: string): Promise<{
23
+ getManageEntityParams(userId: number, entityType: EntityType, entityId: number, action: Action, metadataMultihash: string, privateKey?: string): Promise<[string, string]>;
24
+ /**
25
+ * Calls the manage entity method on chain
26
+ * @param {number} userId The numeric user id
27
+ * @param {EntityType} entityType The type of entity being modified
28
+ * @param {number} entityId The id of the entity
29
+ * @param {Action} action Action being performed on the entity
30
+ * @param {string} metadataMultihash CID multihash or metadata associated with action
31
+ * @param {string}privateKey The private key used to sign the transaction
32
+ */
33
+ manageEntity(userId: number, entityType: EntityType, entityId: number, action: Action, metadataMultihash: string, privateKey?: string): Promise<{
23
34
  txReceipt: TransactionReceipt;
24
35
  }>;
25
36
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@audius/sdk",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "audius": {
5
- "releaseSHA": "c3900f7771f89843401adefd86683fad8657e8f4"
5
+ "releaseSHA": "5f2f952b49defef75aab2e13ce086178edf8f66c"
6
6
  },
7
7
  "description": "",
8
8
  "main": "dist/index.cjs.js",
package/src/api/Users.ts CHANGED
@@ -724,13 +724,25 @@ export class Users extends Base {
724
724
  async updateIsVerified(
725
725
  userId: number,
726
726
  isVerified: boolean,
727
- privateKey: string
727
+ privateKey: string,
728
+ useEntityManager?: boolean
728
729
  ) {
729
- return await this.contracts.UserFactoryClient.updateIsVerified(
730
- userId,
731
- isVerified,
732
- privateKey
733
- )
730
+ if (useEntityManager) {
731
+ return await this.contracts.EntityManagerClient!.getManageEntityParams(
732
+ userId,
733
+ EntityManagerClient.EntityType.USER,
734
+ userId,
735
+ EntityManagerClient.Action.VERIFY,
736
+ '',
737
+ privateKey
738
+ )
739
+ } else {
740
+ return await this.contracts.UserFactoryClient.updateIsVerified(
741
+ userId,
742
+ isVerified,
743
+ privateKey
744
+ )
745
+ }
734
746
  }
735
747
 
736
748
  /**
@@ -207,7 +207,10 @@ export class AudiusContracts {
207
207
  */
208
208
  async getRegistryAddressForContract(contractName: string) {
209
209
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Computed_property_names
210
- this.contracts = this.contracts ?? { [this.registryAddress]: 'registry' }
210
+ this.contracts = this.contracts ?? {
211
+ [this.registryAddress]: 'registry',
212
+ [this.entityManagerAddress]: 'EntityManager'
213
+ }
211
214
  this.contractAddresses = this.contractAddresses ?? {
212
215
  registry: this.registryAddress
213
216
  }
@@ -1,4 +1,6 @@
1
1
  import type { TransactionReceipt } from 'web3-core'
2
+ import sigUtil from 'eth-sig-util'
3
+ import { Buffer as SafeBuffer } from 'safe-buffer'
2
4
 
3
5
  import { ContractClient } from '../contracts/ContractClient'
4
6
  import * as signatureSchemas from '../../data-contracts/signatureSchemas'
@@ -7,7 +9,8 @@ import type { Web3Manager } from '../web3Manager'
7
9
  export enum Action {
8
10
  CREATE = 'Create',
9
11
  UPDATE = 'Update',
10
- DELETE = 'Delete'
12
+ DELETE = 'Delete',
13
+ VERIFY = 'Verify'
11
14
  }
12
15
 
13
16
  export enum EntityType {
@@ -26,12 +29,67 @@ export class EntityManagerClient extends ContractClient {
26
29
  static Action = Action
27
30
  static EntityType = EntityType
28
31
 
32
+ async getManageEntityParams(
33
+ userId: number,
34
+ entityType: EntityType,
35
+ entityId: number,
36
+ action: Action,
37
+ metadataMultihash: string,
38
+ privateKey?: string
39
+ ): Promise<[string, string]> {
40
+ const nonce = signatureSchemas.getNonce()
41
+ const chainId = await this.getEthNetId()
42
+ const contractAddress = await this.getAddress()
43
+ const signatureData = signatureSchemas.generators.getManageEntityData(
44
+ chainId,
45
+ contractAddress,
46
+ userId,
47
+ entityType,
48
+ entityId,
49
+ action,
50
+ metadataMultihash,
51
+ nonce
52
+ )
53
+ let sig
54
+ if (privateKey) {
55
+ sig = sigUtil.signTypedData(
56
+ SafeBuffer.from(privateKey, 'hex') as unknown as Buffer,
57
+ {
58
+ data: signatureData
59
+ }
60
+ )
61
+ } else {
62
+ sig = await this.web3Manager.signTypedData(signatureData)
63
+ }
64
+ const method = await this.getMethod(
65
+ 'manageEntity',
66
+ userId,
67
+ entityType,
68
+ entityId,
69
+ action,
70
+ metadataMultihash,
71
+ nonce,
72
+ sig
73
+ )
74
+ return [method.encodeABI(), contractAddress]
75
+ }
76
+
77
+ /**
78
+ * Calls the manage entity method on chain
79
+ * @param {number} userId The numeric user id
80
+ * @param {EntityType} entityType The type of entity being modified
81
+ * @param {number} entityId The id of the entity
82
+ * @param {Action} action Action being performed on the entity
83
+ * @param {string} metadataMultihash CID multihash or metadata associated with action
84
+ * @param {string}privateKey The private key used to sign the transaction
85
+ */
29
86
  async manageEntity(
30
87
  userId: number,
31
88
  entityType: EntityType,
32
89
  entityId: number,
33
90
  action: Action,
34
- metadataMultihash: string
91
+ metadataMultihash: string,
92
+ privateKey?: string
35
93
  ): Promise<{ txReceipt: TransactionReceipt }> {
36
94
  const nonce = signatureSchemas.getNonce()
37
95
  const chainId = await this.getEthNetId()
@@ -46,7 +104,17 @@ export class EntityManagerClient extends ContractClient {
46
104
  metadataMultihash,
47
105
  nonce
48
106
  )
49
- const sig = await this.web3Manager.signTypedData(signatureData)
107
+ let sig
108
+ if (privateKey) {
109
+ sig = sigUtil.signTypedData(
110
+ SafeBuffer.from(privateKey, 'hex') as unknown as Buffer,
111
+ {
112
+ data: signatureData
113
+ }
114
+ )
115
+ } else {
116
+ sig = await this.web3Manager.signTypedData(signatureData)
117
+ }
50
118
  const method = await this.getMethod(
51
119
  'manageEntity',
52
120
  userId,