|
@@ -1,10 +1,10 @@
|
|
-import { Args, ArgsType, Authorized, Field, Mutation, Query, Resolver } from 'type-graphql'
|
|
|
|
|
|
+import { Args, ArgsType, Authorized, Field, Mutation, Query, Resolver, registerEnumType } from 'type-graphql'
|
|
import { Admin, GeneratedSignature, getAdminDoc } from '../models/Admin'
|
|
import { Admin, GeneratedSignature, getAdminDoc } from '../models/Admin'
|
|
import config, { ADMIN_ROLE } from '../config'
|
|
import config, { ADMIN_ROLE } from '../config'
|
|
import { ed25519Sign } from '@polkadot/util-crypto'
|
|
import { ed25519Sign } from '@polkadot/util-crypto'
|
|
import { u8aToHex, hexToU8a, isHex } from '@polkadot/util'
|
|
import { u8aToHex, hexToU8a, isHex } from '@polkadot/util'
|
|
import { generateAppActionCommitment } from '@joystream/js/utils'
|
|
import { generateAppActionCommitment } from '@joystream/js/utils'
|
|
-import { createType } from '@joystream/types'
|
|
|
|
|
|
+import { AppAction } from '@joystream/metadata-protobuf'
|
|
|
|
|
|
@ArgsType()
|
|
@ArgsType()
|
|
class AdminInput implements Admin {
|
|
class AdminInput implements Admin {
|
|
@@ -12,6 +12,8 @@ class AdminInput implements Admin {
|
|
isKilled: boolean
|
|
isKilled: boolean
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+registerEnumType(AppAction.ActionType, { name: 'AppActionActionType' })
|
|
|
|
+
|
|
@ArgsType()
|
|
@ArgsType()
|
|
class AppActionSignatureInput {
|
|
class AppActionSignatureInput {
|
|
@Field()
|
|
@Field()
|
|
@@ -22,6 +24,8 @@ class AppActionSignatureInput {
|
|
assets: string
|
|
assets: string
|
|
@Field({ description: 'Hex string from UInt8Array' })
|
|
@Field({ description: 'Hex string from UInt8Array' })
|
|
rawAction: string
|
|
rawAction: string
|
|
|
|
+ @Field(() => AppAction.ActionType)
|
|
|
|
+ actionType: AppAction.ActionType
|
|
}
|
|
}
|
|
|
|
|
|
@Resolver()
|
|
@Resolver()
|
|
@@ -42,8 +46,9 @@ export class AdminResolver {
|
|
|
|
|
|
@Mutation(() => GeneratedSignature)
|
|
@Mutation(() => GeneratedSignature)
|
|
async signAppActionCommitment(
|
|
async signAppActionCommitment(
|
|
- // FIXME: In the initial implementation we don't verify the nonce, but this should be changed in the future
|
|
|
|
- @Args() { nonce, rawAction, assets, creatorId }: AppActionSignatureInput
|
|
|
|
|
|
+ // FIXME: In the initial implementation we require the user to provide the nonce
|
|
|
|
+ // and don't verify it in any way, but this should be changed in the future
|
|
|
|
+ @Args() { nonce, rawAction, assets, creatorId, actionType }: AppActionSignatureInput
|
|
) {
|
|
) {
|
|
if (!isHex(assets) || !isHex(rawAction)) {
|
|
if (!isHex(assets) || !isHex(rawAction)) {
|
|
throw new Error('One of input is not hex: assets, rawAction')
|
|
throw new Error('One of input is not hex: assets, rawAction')
|
|
@@ -51,9 +56,13 @@ export class AdminResolver {
|
|
|
|
|
|
const message = generateAppActionCommitment(
|
|
const message = generateAppActionCommitment(
|
|
nonce,
|
|
nonce,
|
|
- `m:${creatorId}`,
|
|
|
|
|
|
+ `${creatorId}`,
|
|
|
|
+ actionType,
|
|
|
|
+ actionType === AppAction.ActionType.CREATE_CHANNEL
|
|
|
|
+ ? AppAction.CreatorType.MEMBER // only members are supported as channel owners for now
|
|
|
|
+ : AppAction.CreatorType.CHANNEL,
|
|
hexToU8a(assets),
|
|
hexToU8a(assets),
|
|
- createType('Bytes', rawAction)
|
|
|
|
|
|
+ hexToU8a(rawAction)
|
|
)
|
|
)
|
|
const signature = ed25519Sign(message, config.appKeypair)
|
|
const signature = ed25519Sign(message, config.appKeypair)
|
|
return { signature: u8aToHex(signature) }
|
|
return { signature: u8aToHex(signature) }
|