-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathverifyUser.ts
More file actions
94 lines (87 loc) · 2.94 KB
/
verifyUser.ts
File metadata and controls
94 lines (87 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { program } from 'commander'
import { privateKeyToAccount } from 'viem/accounts'
import { sdk as audiusSdk, type AudiusSdkWithSecret } from '../sdk'
import { EntityManagerAction, EntityType } from '../services'
import { HashId } from '../types/HashId'
program
.command('verify')
.description('Verify a user')
.option('-h, --handle <handle>', 'The handle to verify')
.option('-s, --socialHandle <social-handle>', 'The social handle to verify')
.option('--privateKey <privateKey>', 'The private key to use for the request')
.option(
'-e, --environment <environment>',
'The environment to use for the request',
'production'
)
.option(
'-p, --platform <platform>',
'The platform to verify (twitter, instagram, tiktok, manual)'
)
.action(async (args) => {
if (!args.handle || !args.platform || !args.privateKey) {
console.error(
'Missing required arguments: handle, socialHandle, and platform are required'
)
process.exit(1)
}
if (args.platform !== 'manual' && !args.socialHandle) {
console.error(
'Missing required arguments: socialHandle is required for non-manual verification'
)
process.exit(1)
}
if (!['twitter', 'instagram', 'tiktok', 'manual'].includes(args.platform)) {
console.error('Invalid platform:', args.platform)
process.exit(1)
}
const account = privateKeyToAccount(
`0x${args.privateKey.replace(/^0x/, '')}` as `0x${string}`
)
const sdk = audiusSdk({
appName: 'verify-user',
apiKey: account.address,
apiSecret: args.privateKey,
environment: args.environment
}) as AudiusSdkWithSecret
try {
const user = await sdk.users.getUserByHandle({ handle: args.handle })
const userId = HashId.parse(user.data?.id)
console.info('Verifying user', userId)
const config: {
is_verified: boolean
twitter_handle?: string
instagram_handle?: string
tiktok_handle?: string
} = {
is_verified: true
}
if (args.platform === 'twitter') {
config.twitter_handle = args.socialHandle
} else if (args.platform === 'instagram') {
config.instagram_handle = args.socialHandle
} else if (args.platform === 'tiktok') {
config.tiktok_handle = args.socialHandle
}
console.info('With config', config)
console.info('Sending tx...')
const { blockHash, blockNumber } =
await sdk.services.entityManager.manageEntity({
userId,
entityType: EntityType.USER,
entityId: userId,
action: EntityManagerAction.VERIFY,
metadata: JSON.stringify({
cid: '',
data: config
})
})
console.info('Block hash', blockHash)
console.info('Block number', blockNumber)
process.exit(0)
} catch (error) {
console.error('Verification failed:', error)
process.exit(1)
}
})
program.parseAsync()