浏览代码

Update `generateAppActionCommitment` impl. (#85)

Leszek Wiesner 1 年之前
父节点
当前提交
ddbdcaf9d2
共有 3 个文件被更改,包括 31 次插入22 次删除
  1. 1 1
      package.json
  2. 15 6
      src/resolvers/admin.ts
  3. 15 15
      yarn.lock

+ 1 - 1
package.json

@@ -37,7 +37,7 @@
     "@graphql-tools/schema": "^8.3.1",
     "@graphql-tools/stitch": "^8.4.1",
     "@graphql-tools/url-loader": "^7.5.2",
-    "@joystream/js": "^1.3.0",
+    "@joystream/js": "^1.4.0",
     "@typegoose/auto-increment": "^1.3.0",
     "@typegoose/typegoose": "^9.8.1",
     "apollo-server-core": "^3.8.1",

+ 15 - 6
src/resolvers/admin.ts

@@ -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 config, { ADMIN_ROLE } from '../config'
 import { ed25519Sign } from '@polkadot/util-crypto'
 import { u8aToHex, hexToU8a, isHex } from '@polkadot/util'
 import { generateAppActionCommitment } from '@joystream/js/utils'
-import { createType } from '@joystream/types'
+import { AppAction } from '@joystream/metadata-protobuf'
 
 @ArgsType()
 class AdminInput implements Admin {
@@ -12,6 +12,8 @@ class AdminInput implements Admin {
   isKilled: boolean
 }
 
+registerEnumType(AppAction.ActionType, { name: 'AppActionActionType' })
+
 @ArgsType()
 class AppActionSignatureInput {
   @Field()
@@ -22,6 +24,8 @@ class AppActionSignatureInput {
   assets: string
   @Field({ description: 'Hex string from UInt8Array' })
   rawAction: string
+  @Field(() => AppAction.ActionType)
+  actionType: AppAction.ActionType
 }
 
 @Resolver()
@@ -42,8 +46,9 @@ export class AdminResolver {
 
   @Mutation(() => GeneratedSignature)
   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)) {
       throw new Error('One of input is not hex: assets, rawAction')
@@ -51,9 +56,13 @@ export class AdminResolver {
 
     const message = generateAppActionCommitment(
       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),
-      createType('Bytes', rawAction)
+      hexToU8a(rawAction)
     )
     const signature = ed25519Sign(message, config.appKeypair)
     return { signature: u8aToHex(signature) }

+ 15 - 15
yarn.lock

@@ -1025,12 +1025,12 @@ __metadata:
   languageName: node
   linkType: hard
 
-"@joystream/js@npm:^1.3.0":
-  version: 1.3.0
-  resolution: "@joystream/js@npm:1.3.0"
+"@joystream/js@npm:^1.4.0":
+  version: 1.4.0
+  resolution: "@joystream/js@npm:1.4.0"
   dependencies:
-    "@joystream/metadata-protobuf": ^2.8.0
-    "@joystream/types": ~2.0.0
+    "@joystream/metadata-protobuf": ^2.8.1
+    "@joystream/types": ^2.0.0
     "@polkadot/util-crypto": 9.5.1
     axios: ^1.2.1
     buffer: ^6.0.3
@@ -1038,13 +1038,13 @@ __metadata:
     long: ^5.2.1
     merkletreejs: ^0.3.9
     protobufjs: ^6.11.3
-  checksum: b97039c40418c41ca130d09d22abdf479382c19c63515491f682051ed5b7f73dd793dc429744db45ea72e85e25aa8b6996ba3f74ce7368cb1cb7d4c8f09c69b5
+  checksum: b4a64a58529dbaa38b54f1be208e6e8e90a40a548375fa0a534ca8af1815ed35d09b6689170ba24f5d212085235d9d34452ec92f5edd0cedea50f62842797d6e
   languageName: node
   linkType: hard
 
-"@joystream/metadata-protobuf@npm:^2.8.0":
-  version: 2.8.0
-  resolution: "@joystream/metadata-protobuf@npm:2.8.0"
+"@joystream/metadata-protobuf@npm:^2.8.1":
+  version: 2.8.1
+  resolution: "@joystream/metadata-protobuf@npm:2.8.1"
   dependencies:
     "@types/iso-3166-2": ^1.0.0
     "@types/long": ^4.0.1
@@ -1054,7 +1054,7 @@ __metadata:
     iso-639-1: ^2.1.9
     long: ^4.0.0
     protobufjs: ^6.11.2
-  checksum: deaeb157f959f0c61a25e77a356738af86415c0bcd9e1a41da4d545fc5c1e0ef5e1ca7f110eb15e072148a54ab3d3c9a0879afc1292233ede743b3f9d4b7610f
+  checksum: 914ca2c049d1d5720f5cf9e587c27c54913bc2f75a489839b72a29932c18436cc54d902e405da76ff73d5f54b12b4d6dce07e4f8571b568ff53332022eb97a34
   languageName: node
   linkType: hard
 
@@ -1067,9 +1067,9 @@ __metadata:
   languageName: node
   linkType: hard
 
-"@joystream/types@npm:~2.0.0":
-  version: 2.0.0
-  resolution: "@joystream/types@npm:2.0.0"
+"@joystream/types@npm:^2.0.0":
+  version: 2.1.0
+  resolution: "@joystream/types@npm:2.1.0"
   dependencies:
     "@polkadot/api": 8.9.1
     "@polkadot/keyring": 9.5.1
@@ -1079,7 +1079,7 @@ __metadata:
     ajv: ^6.11.0
     lodash: ^4.17.15
     moment: ^2.24.0
-  checksum: 9ecb3e3ce275714cc5e1ed02891cbfada30d84415b97de65618eb2c7b624bab8f7b59104b1f2299d8ac17f95471f18c3cea36f5b038c6510becbcb07f9e92223
+  checksum: 22411d5715b0f510f21cefbbdba45a91e180744e1c53961fef043026dd6193e9412e91bf0394875cfef325c50e63836c956c898a225223f5f064bfc017108cf4
   languageName: node
   linkType: hard
 
@@ -6981,7 +6981,7 @@ __metadata:
     "@graphql-tools/schema": ^8.3.1
     "@graphql-tools/stitch": ^8.4.1
     "@graphql-tools/url-loader": ^7.5.2
-    "@joystream/js": ^1.3.0
+    "@joystream/js": ^1.4.0
     "@joystream/prettier-config": ^1.0.0
     "@shelf/jest-mongodb": ^3.0.0
     "@typegoose/auto-increment": ^1.3.0