|
@@ -3,7 +3,8 @@ 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 './helpers'
|
|
|
|
|
|
+import { generateAppActionCommitment } from '@joystream/js/utils'
|
|
|
|
+import { createType } from '@joystream/types'
|
|
|
|
|
|
@ArgsType()
|
|
@ArgsType()
|
|
class AdminInput implements Admin {
|
|
class AdminInput implements Admin {
|
|
@@ -13,14 +14,14 @@ class AdminInput implements Admin {
|
|
|
|
|
|
@ArgsType()
|
|
@ArgsType()
|
|
class AppActionSignatureInput {
|
|
class AppActionSignatureInput {
|
|
|
|
+ @Field()
|
|
|
|
+ nonce: number
|
|
@Field()
|
|
@Field()
|
|
creatorId: string
|
|
creatorId: string
|
|
@Field({ description: 'Hex string from UInt8Array' })
|
|
@Field({ description: 'Hex string from UInt8Array' })
|
|
assets: string
|
|
assets: string
|
|
@Field({ description: 'Hex string from UInt8Array' })
|
|
@Field({ description: 'Hex string from UInt8Array' })
|
|
rawAction: string
|
|
rawAction: string
|
|
- @Field({ description: 'Hex string from UInt8Array' })
|
|
|
|
- rawAppActionMetadata: string
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Resolver()
|
|
@Resolver()
|
|
@@ -41,17 +42,18 @@ export class AdminResolver {
|
|
|
|
|
|
@Mutation(() => GeneratedSignature)
|
|
@Mutation(() => GeneratedSignature)
|
|
async signAppActionCommitment(
|
|
async signAppActionCommitment(
|
|
- @Args() { rawAppActionMetadata, rawAction, assets, creatorId }: AppActionSignatureInput
|
|
|
|
|
|
+ // 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
|
|
) {
|
|
) {
|
|
- if (!isHex(assets) || !isHex(rawAction) || !isHex(rawAppActionMetadata)) {
|
|
|
|
- throw new Error('One of input is not hex: assets, rawAction, rawAppActionMetadata')
|
|
|
|
|
|
+ if (!isHex(assets) || !isHex(rawAction)) {
|
|
|
|
+ throw new Error('One of input is not hex: assets, rawAction')
|
|
}
|
|
}
|
|
|
|
|
|
const message = generateAppActionCommitment(
|
|
const message = generateAppActionCommitment(
|
|
- creatorId,
|
|
|
|
|
|
+ nonce,
|
|
|
|
+ `m:${creatorId}`,
|
|
hexToU8a(assets),
|
|
hexToU8a(assets),
|
|
- hexToU8a(rawAction),
|
|
|
|
- hexToU8a(rawAppActionMetadata)
|
|
|
|
|
|
+ createType('Bytes', rawAction)
|
|
)
|
|
)
|
|
const signature = ed25519Sign(message, config.appKeypair)
|
|
const signature = ed25519Sign(message, config.appKeypair)
|
|
return { signature: u8aToHex(signature) }
|
|
return { signature: u8aToHex(signature) }
|