Skip to main content

API 文档

前置条件

如果 SAAS 服务使用 OIDC 认证,则需要增加请求头:

Authorization: Bearer <oidc-token>

获取合约的元数据

API: GET /hf/metadata

测试:

curl -k https://bc-saas.172.22.96.209.nip.io/hf/metadata

返回:

{"content":"eyJpbmZvIjp7InRpdGxlIjoidW5kZWZpbmVkIiwidmVyc2lvbiI6ImxhdGVzdCJ9LCJjb250cmFjdHMiOnsib3JnLmJlc3RjaGFpbnMuY29tLkRlcG9zaXRvcnlDb250cmFjdCI6eyJpbmZvIjp7InRpdGxlIjoib3JnLmJlc3RjaGFpbnMuY29tLkRlcG9zaXRvcnlDb250cmFjdCIsInZlcnNpb24iOiJsYXRlc3QifSwibmFtZSI6Im9yZy5iZXN0Y2hhaW5zLmNvbS5EZXBvc2l0b3J5Q29udHJhY3QiLCJ0cmFuc2FjdGlvbnMiOlt7InBhcmFtZXRlcnMiOlt7Im5hbWUiOiJwYXJhbTAiLCJzY2hlbWEiOnsidHlwZSI6ImFycmF5IiwiaXRlbXMiOnsidHlwZSI6InN0cmluZyJ9fX1dLCJ0YWciOlsic3VibWl0IiwiU1VCTUlUIl0sIm5hbWUiOiJCYXRjaFB1dFVudHJ1c3RWYWx1ZSIsInJldHVybnMiOnsidHlwZSI6InN0cmluZyJ9fSx7InBhcmFtZXRlcnMiOlt7Im5hbWUiOiJwYXJhbTAiLCJzY2hlbWEiOnsidHlwZSI6InN0cmluZyJ9fSx7Im5hbWUiOiJwYXJhbTEiLCJzY2hlbWEiOnsidHlwZSI6Im51bWJlciIsImZvcm1hdCI6ImRvdWJsZSIsIm1heGltdW0iOjE4NDQ2NzQ0MDczNzA5NTUyMDAwLCJtaW5pbXVtIjowLCJtdWx0aXBsZU9mIjoxfX1dLCJ0YWciOlsic3VibWl0IiwiU1VCTUlUIl0sIm5hbWUiOiJDaGVjayJ9LHsicGFyYW1ldGVycyI6W3sibmFtZSI6InBhcmFtMCIsInNjaGVtYSI6eyJ0eXBlIjoic3RyaW5nIn19XSwidGFnIj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RhIiwicmV0dXJucyI6eyJ0eXBlIjoic3RyaW5nIn19XSwiZGVmYXVsdCI6ZmFsc2V9fSwiY29tcG9uZW50cyI6eyJzY2hlbWFzIjp7Ik1lc3NhZ2UiOnsiJGlkIjoiTWVzc2FnZSIsInByb3BlcnRpZXMiOnsibm9uY2UiOnsidHlwZSI6Im51bWJlciIsImZvcm1hdCI6ImRvdWJsZSIsIm1heGltdW0iOjE4NDQ2NzQ0MDczNzA5NTUyMDAwLCJtaW5pbXVtIjowLCJtdWx0aXBsZU9mIjoxfSwicHVibGljS2V5Ijp7InR5cGUiOiJzdHJpbmcifSwic2lnbmF0dXJlIjp7InR5cGUiOiJzdHJpbmcifX0sInJlcXVpcmVkIjpbIm5vbmNlIiwicHVibGljS2V5Iiwic2lnbmF0dXJlIl0sImFkZGl0aW9uYWxQcm9wZXJ0aWVzIjpmYWxzZX19fX0="}

获取用户的 Nonce

API: GET /basic/currentNonce

query参数:

参数名称参数描述必填默认值
account账户地址

测试:

curl -k https://bc-saas.172.22.96.209.nip.io/basic/currentNonce?account=0x02624bfc011381aa1f4e19db60e3f46673f1f171

返回

{"nonce":0}

获取存证总数

API: GET /basic/total

测试:

curl -k https://bc-saas.172.22.96.209.nip.io/basic/total

返回:

{"total":6}

获取具体存证的内容

API: GET /basic/getValue

query参数:

参数名称参数描述必填默认值
index索引二选一
kidkid二选一

测试:

curl -k https://bc-saas.172.22.96.209.nip.io/basic/getValue?index=1

返回:

{"index":"1","value":"eyJuYW1lIjoiYWJjIiwiY29udGVudFR5cGUiOiAianNvbiIsImNvbnRlbnRJRCI6ICJpZCIsInRydXN0ZWRUaW1lc3RhbXAiOiAiMTIzNCIsInBsYXRmb3JtIjogImJlc3RjaGFpbnMifQo="}

新增存证

API: POST /basic/putValue

body参数:

参数名称参数描述必填默认值
messagebase64编码过的信息,包含nonce,signature,publicKey
valuebase64编码过的信息,里面包含基本的json字符串

测试:

curl -k -XPOST -H'Content-Type: application/json' https://bc-saas.172.22.96.209.nip.io/basic/putValue -d '{"message":"eyJub25jZSI6MCwicHVibGljS2V5IjoiTUZrd0V3WUhLb1pJemowQ0FRWUlLb1pJemowREFRY0RRZ0FFN2p0MURWeG5OUWtBTVBrR3JlTDU3UHRHVVQySDVNS1FjMGkvRHdLamlBbyt0eXAxTW9ZZUZtU3FyenJJckxNY25hNXd5b0l4V3hPbXJhcU01cHFEbVE9PSIsInNpZ25hdHVyZSI6Ik1FWUNJUUNpUlowd3ZYODFwaFYvOVVMQUh0c2d0WkFMSWNOS1l2MUdLZm1OVlJGNEZBSWhBTWorc0NZb2p1WkpBcTVVeWl4eHNqS0owZ2hQU0xRYnZiZUQ1UHBrZVJOciJ9","value":"eyJuYW1lIjoiYWJjIiwiY29udGVudFR5cGUiOiAianNvbiIsImNvbnRlbnRJRCI6ICJpZCIsInRydXN0ZWRUaW1lc3RhbXAiOiAiMTIzNCIsInBsYXRmb3JtIjogImJlc3RjaGFpbnMifQo="}'

关于测试数据的生成

// arg.json: {"name":"abc","contentType": "json","contentID": "id","trustedTimestamp": "1234","platform": "bestchains","description":"description","contentSize":1024}
// contentSize 是文件大小,单位 byte
package main

import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"encoding/base64"
"encoding/json"
"fmt"
"log"
"os"

"github.com/bestchains/bestchains-contracts/library/context"
)

func main() {
arg, _ := os.ReadFile("./arg.json")
value := base64.StdEncoding.EncodeToString(arg)

priKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
log.Fatal(err)
}

msg := &context.Message{
Nonce: 0,
}
if err := msg.GenerateSignature(priKey, value); err != nil {
log.Fatal(err)
}

if _, err := msg.VerifyAgainstArgs(value); err != nil {
log.Fatal(err)
}

msgBytes, _ := json.Marshal(msg)
msgValue := base64.StdEncoding.EncodeToString(msgBytes)
fmt.Printf("value: '%s'\n", value)
fmt.Printf("message: '%s'\n", msgValue)
}

返回:

{"kid":"18b682430b2ee5cdcb17c0ea678a52223056d256"}

新增存证(不需要二次身份验证)

API: POST /basic/putUntrustValue

body参数:

参数名称参数描述必填默认值
valuebase64编码过的信息,里面包含基本的json字符串

测试:

curl -k -XPOST -H'Content-Type: application/json' https://bc-saas.172.22.96.209.nip.io/basic/putUntrustValue -d '{"value":"eyJuYW1lIjoiYWJjIiwiY29udGVudFR5cGUiOiAianNvbiIsImNvbnRlbnRJRCI6ICJpZCIsInRydXN0ZWRUaW1lc3RhbXAiOiAiMTIzNCIsInBsYXRmb3JtIjogImJlc3RjaGFpbnMifQo="}'

返回:

{"kid":"fbef356cae5b9ada2b0e9c5bc6138fdf320ed1ba"}

验证存证

API: POST /basic/verifyValue

body参数:

参数名称参数描述必填默认值
index索引与 kid 二选一
kidkid与 index 二选一
valuebase64 编码过的内容

测试:

curl -k -XPOST -H'Content-Type: application/json' https://bc-saas.172.22.96.209.nip.io/basic/verifyValue -d '{"kid":"18b682430b2ee5cdcb17c0ea678a52223056d256","value":"eyJuYW1lIjoiYWJjIiwiY29udGVudFR5cGUiOiAianNvbiIsImNvbnRlbnRJRCI6ICJpZCIsInRydXN0ZWRUaW1lc3RhbXAiOiAiMTIzNCIsInBsYXRmb3JtIjogImJlc3RjaGFpbnMifQo="}'

返回:

{"status":true,"reason":"value match"}

获取存证列表

API: GET /basic/depositories

query参数:

参数名称参数描述必填默认值
from数据库中的偏移,利用from作分页,from=0, from=10, from=20 ...0
size分页每一页的条目数量10
startTime开始时间, 单位是秒
endTime结束时间,单位秒
name存证名称, 支持模糊搜索
contentName文件名称或者其他的描述信息,支持模糊搜索
kid存证 kid

测试:

curl -k https://bc-saas.172.22.96.209.nip.io/basic/depositories?from=0&size=1

返回:

{"count":9,"data":[{"index":"6","kid":"18b682430b2ee5cdcb17c0ea678a52223056d256","platform":"bestchains","operator":"0x02624bfc011381aa1f4e19db60e3f46673f1f171","owner":"0xe4af6dcf67b5ec06d903ec175a0c7e47f38249b2","blockNumber":72,"name":"abc","contentName":"","contentID":"id","contentType":"id","trustedTimestamp":"1683343692"}]}

根据存证 kid 获取单个存证信息

API: GET /basic/depositories/:kid

测试:

curl -k https://bc-saas.172.22.96.209.nip.io/basic/depositories/18b682430b2ee5cdcb17c0ea678a52223056d256

返回:

{"index":"6","kid":"18b682430b2ee5cdcb17c0ea678a52223056d256","platform":"bestchains","operator":"0x02624bfc011381aa1f4e19db60e3f46673f1f171","owner":"0xe4af6dcf67b5ec06d903ec175a0c7e47f38249b2","blockNumber":72,"name":"abc","contentName":"","contentID":"id","contentType":"id","trustedTimestamp":"1683343692"}

根据存证 kid 获取存证证书

API: GET /basic/depositories/certificate/:kid

query参数:

参数名称参数描述必填默认值
style证书类型,支持 CN(中文证书)和ENG(英文证书)两种CN

测试:

curl -k https://bc-saas.172.22.96.209.nip.io/basic/depositories/certificate/18b682430b2ee5cdcb17c0ea678a52223056d25?style=CN

返回:

证书文件会从浏览器中直接下载,证书内容如下:

  • 中文证书

中文证书

  • 英文证书

英文证书

其中,返回的HTTP Response Header:

Content-Type: application/octet-stream
Content-Disposition: attachment; filename=18b682430b2ee5cdcb17c0ea678a52223056d256.pdf