是否能通过 node.js SDK 来签名文章和创建合约?



  • 我尝试做的事情是,使用 SDK 来代替我在 P1 上面签名文章和创建合约。目的就是自动化,同时可以把分章发到其它平台,比如结合自己的 Hexo。

    不过,经过测试,虽然我能参照 SDK 的 Sample 来签名文章,创建合约,创建 draft 文章,但是签名的文章和创建的合约却不会显示在我自己的页面。

    以下是打出来的一些日志。

    ╰─ node index.js                                                                             SIGINT(2) ↵  14:39:59 
    webAuthorizeUrl: https://beta.press.one/developer/apps/138465f3af2a8c73df42f9ad5c4ea1039ac0d66c/authorize
    server is listening on 3000
    (node:11549) ExperimentalWarning: The http2 module is an experimental API.
    request url: https://beta.press.one/api/v2/apps/138465f3af2a8c73df42f9ad5c4ea1039ac0d66c/authenticate
    response 200 '{"appAuthentication":{"userAddress":"13848d46b2a0510f2881f53701ed47435bf7c29d","status":"VERIFIED","createdAt":null,"updatedAt":null,"signature":"c5204f5adf92ed63a3972d962c161284e82835a3ebb0ba681f5cb71da67b59fa260e6abf3633c8010372855cb4d7762f309f7bbee283d2c3ae3bfce1419e9d3a0","appAddress":"138465f3af2a8c73df42f9ad5c4ea1039ac0d66c","authAddress":"50048fa540e4d7ed511d32520f2e69f43288ca8b"},"token":"xyz"}' '{"server":"nginx","date":"Sun, 31 Mar 2019 06:40:09 GMT","content-type":"application/json; charset=utf-8","content-length":"733","connection":"close","vary":"Origin","strict-transport-security":"max-age=15768000;","referrer-policy":"same-origin","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","x-xss-protection":"1; mode=block","x-download-options":"noopen"}'
    token: abc
    authAddress: 50048fa540e4d7ed511d32520f2e69f43288ca8b
    request url: https://beta.press.one/api/v2/files
    response 200 '{"cache":{"msghash":"4e27a8d1f77d1816f03780790646573ac1ed1f2f76a89feaf5b508f9a6d34f43","title":"自学编程的思维模式","description":"{ \\"name\\": \\"pressone\\", \\"version\\": \\"1.0.0\\", \\"description\\": \\"\\", \\"main\\": \\"index.js\\", \\"scripts\\": { \\"test\\": \\"echo \\\\\\"Error: no test specified\\\\\\" && exit 1\\" }, \\"author\\": \\"Ken Chen\\", \\"license\\": \\"MIT\\", \\"dependencies\\": { \\"prs-lib\\": \\"0.0.5\\", \\"prs-utility\\": \\"0.0.2\\" ...","originUrl":"http://www.thinkingincrowd.me/2019/03/20/mindset-for-self-teaching-programming/","cacheUrl":"https://storage.googleapis.com/pressone/4e/27/4e27a8d1f77d1816f03780790646573ac1ed1f2f76a89feaf5b508f9a6d34f43.md","mimeType":"text/markdown","createdAt":"2019-03-31T06:40:13.000Z","source":"鹄思乱想","projectId":null,"rewardAmount":"0.000000000000000000000000000000","rewardCount":0,"category":"Programming","updatedAt":"2019-03-31T06:40:13.000Z","rId":"693cfc51f49dffad21e755d2bc47fed7bfe64cdddf74424b70a0e1c053f02498","address":"50048fa540e4d7ed511d32520f2e69f43288ca8b"},"block":{"id":"693cfc51f49dffad21e755d2bc47fed7bfe64cdddf74424b70a0e1c053f02498","type":"PUBLISH:2","user_address":"50048fa540e4d7ed511d32520f2e69f43288ca8b","hash":"85617d7d9e49f727145188389ee3a9486658d2ebca0d5863a9113d5c5d451f98","signature":"bbb2e5e1533f5bae7996f3221a3ebd9cba7cfbf7bb02c9bcddab0e3f8f7d767bd2035326cb81ce935a174b7258935ba39f064ceb098bb0be2488aed73c551afe0","meta":"{\\"uris\\":[\\"p1s://4e/27/4e27a8d1f77d1816f03780790646573ac1ed1f2f76a89feaf5b508f9a6d34f43.md\\"],\\"mime\\":\\"text/markdown;charset=UTF-8\\"}","data":"{\\"file_hash\\":\\"4e27a8d1f77d1816f03780790646573ac1ed1f2f76a89feaf5b508f9a6d34f43\\"}","createdAt":"2019-03-31T06:40:13.433Z"}}' '{"server":"nginx","date":"Sun, 31 Mar 2019 06:40:13 GMT","content-type":"application/json; charset=utf-8","content-length":"1836","connection":"close","vary":"Origin","strict-transport-security":"max-age=15768000;","referrer-policy":"same-origin","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","x-xss-protection":"1; mode=block","x-download-options":"noopen"}'
    ----------------------
    fileHash: 4e27a8d1f77d1816f03780790646573ac1ed1f2f76a89feaf5b508f9a6d34f43
    fileRId: 693cfc51f49dffad21e755d2bc47fed7bfe64cdddf74424b70a0e1c053f02498
    request url: https://beta.press.one/api/v2/contracts
    response 200 '{"contract":{"rId":"a2e954551ad25e3d38e206180e6a5902b2eafc9cc22c961d9330e6fe01e34ecd"}}' '{"server":"nginx","date":"Sun, 31 Mar 2019 06:40:16 GMT","content-type":"application/json; charset=utf-8","content-length":"101","connection":"close","vary":"Origin","strict-transport-security":"max-age=15768000;","referrer-policy":"same-origin","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","x-xss-protection":"1; mode=block","x-download-options":"noopen"}'
    contractRId: a2e954551ad25e3d38e206180e6a5902b2eafc9cc22c961d9330e6fe01e34ecd
    { privateKey: undefined,
      token: 'abc' }
    
    request url: https://beta.press.one/api/v2/contracts/a2e954551ad25e3d38e206180e6a5902b2eafc9cc22c961d9330e6fe01e34ecd/bind
    response 200 '{"rId":"35a42b74fc98cb9830fce61e7c3a25c4b7f252145d0782d986622ac192228cd0","type":"RECEIVER","uuid":"35789ff4-fa1a-4e0a-b5c3-244a7f0f5555","address":"50048fa540e4d7ed511d32520f2e69f43288ca8b","fileMsghash":"4e27a8d1f77d1816f03780790646573ac1ed1f2f76a89feaf5b508f9a6d34f43","file":"693cfc51f49dffad21e755d2bc47fed7bfe64cdddf74424b70a0e1c053f02498","contract":"a2e954551ad25e3d38e206180e6a5902b2eafc9cc22c961d9330e6fe01e34ecd","receiver":"50048fa540e4d7ed511d32520f2e69f43288ca8b","version":1}' '{"server":"nginx","date":"Sun, 31 Mar 2019 06:40:20 GMT","content-type":"application/json; charset=utf-8","content-length":"527","connection":"close","vary":"Origin","strict-transport-security":"max-age=15768000;","referrer-policy":"same-origin","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","x-xss-protection":"1; mode=block","x-download-options":"noopen"}'
    ===========================
    { rId: '35a42b74fc98cb9830fce61e7c3a25c4b7f252145d0782d986622ac192228cd0',
      type: 'RECEIVER',
      uuid: '35789ff4-fa1a-4e0a-b5c3-244a7f0f5555',
      address: '50048fa540e4d7ed511d32520f2e69f43288ca8b',
      fileMsghash: '4e27a8d1f77d1816f03780790646573ac1ed1f2f76a89feaf5b508f9a6d34f43',
      file: '693cfc51f49dffad21e755d2bc47fed7bfe64cdddf74424b70a0e1c053f02498',
      contract: 'a2e954551ad25e3d38e206180e6a5902b2eafc9cc22c961d9330e6fe01e34ecd',
      receiver: '50048fa540e4d7ed511d32520f2e69f43288ca8b',
      version: 1 }
    


  • 目前 DApp 之间的签名内容是相互独立的,press.one 主站实质上也是 PRS 网络的一个 DApp,所以你在 DApp 中创建的签名内容是不会出现在 press.one 中的。

    根据你的需求,如果想自动化的将文章发布到 press.one 上,那么可以使用 press.one 主站账户的 私钥或者授权 token 来签名文件。



  • 谢谢你的答复,并积极加我微信通知我。我的想法是:

    P1 要做的就是协议,可以让所有授权的 Dapp 发布内容。不同 Dapp 签名的内容和性质不同。

    P1 现在的页面,只是临时使用,不一定就是要作为文章发表的载体,以后可能又更好的编辑器,集成多平台的 Dapp 帮用户发不同的文章,图片,等数字内容。

    P1 反而应该是一个大仓库,让用户看到不同 Dapp 都签名了什么,做整理。一旦有 Dapp 冒用用户签了内容都能发现和 revoke 或删除。



  • @zhangpeng 为什么同样的方式,创建的 draft 文档就会在主站出现呢?请问怎么获取 press.one 主站账户的私钥,或者授权 token?我只有 keystore。有 sample code 吗?



  • keystore解密之后就是私钥。

    楼主还是有点区分不开PRS协议和press.one主站DApp,你说的大仓库本来就有,只是还没怎么做搜索功能 https://press.one/blockchain



  • @区块链观光客 我的疑问是,那为什么我另外申请的 Dapp 创建的 draft 文档,会出现在 Press.one beta 的 Dapp 上呢?我同样用自己的测试 Dapp 的 key 来认证啊。

    keystore 如何解密为私钥?如何使用 P1 主站的私钥和 token 签名?这些在 Node.js SDK 并没有说明和样例。所以希望能获取些信息。



  • 经过尝试,通过以下的方法就可以通过 keystore 获得 Press.one 的私钥了:

    const keyth = require('keythereum')
    
    // address 改成你的 app address。就是下载的 keystore 文件上面那一长串字符
    // keystore_path 就是放 keystore 文件的目录,目录下要有 keystore 这个名字的文件夹
    
    const keyobj = keyth.importFromFile('address', 'keystore_path')
    
    // 以下的 password 改成你登录/保护 P1 的密码
    const privateKey = keyth.recover('password', keyobj)
    
    console.log(privateKey.toString('hex'));
    

    签名文件的方法和 SDK sample 差不多,只是初始化 client 的方式不同

    const client2 = new PRS({ env: 'env', debug: true, address: appAddress, privateKey: appPrivateKey });
    


  • 做了一个把 Hexo 的博客搬到 Press.one 的小工具。欢迎使用和打赏。☺ https://github.com/kenspirit/hexo-to-pressone



  • @thinkingincrowd 是也乎,( ̄▽ ̄)

    赞哪...有了模板,
    用其它语言复制类似的也就很自然了 😉



  • @thinkingincrowd 很赞啊,可以基于你的模板来做其它的类似的工作,谢谢!!!



  • 被楼主同步的文章集中刷屏了,好可怕……感觉就像刷推翻到了rss bot一下同步几十条



  • @thinkingincrowd 这个其实我也一直想吐槽,根本来说是官方Dapp的定位很迷造成的问题。V2的API还能操作Press.one的草稿和订阅,真的有点出乎意料