@fksyuan/zktls-ext-core-sdk
v0.1.3
Published
Primus zktls algorithm sdk for extension
Readme
zktls-extension-core-sdk
Primus zktls algorithm sdk for extension.
Overview
The Extension Core SDK allows you to verify data through web endpoint responses. An authorized token is required to request private data.
To integrate, create a project in the Primus Develop Hub to obtain a paired appID and appSecret. Then, configure these credentials in your project to utilize the Extension Core SDK.
Primus Extension Core SDK supports two models: the Proxy TLS model and the MPC TLS model. You can specify the desired model by setting the "algorithmType" parameter during SDK integration.
For more details on setting up your project, refer to the Developer Hub.
How it Works
Here's a simplified flow of how the Primus Extension Core SDK works on your project:
1. Create Project: Create a project on the Primus Developer Hub to obtain a paired appID and appSecret, then configure them in your project.
2. Configure Verification Parameters: Ensure that two key parameters, including the request parameters and response data paths, are configured correctly. Refer to the simple example for guidance.
3. Execute zkTLS Protocol: Invoke the zkTLS protocol to initiate the data verification process.
4. Verify Data Verification Result: Your Extension retrieves the verification result from the Extension Core SDK and validates Primus' signature to ensure trustworthiness.
5. Execute Business Logic: Based on the verification result, your Extension executes the relevant business logic, such as submitting the proof on-chain or triggering other operations.
Demo
This is a Extension demo we developed using Primus Extension Core SDK.
Installation
Installation Steps
Open your terminal and navigate to your project directory. Then run one of the following commands:
- Using npm:
npm install --save @primuslabs/zktls-ext-core-sdk- Using yarn:
yarn add --save @primuslabs/zktls-ext-core-sdkImporting the SDK
After installation, you can import the SDK in your JavaScript or TypeScript files. Here's how:
const { PrimusExtCoreTLS } = require("@primuslabs/zktls-ext-core-sdk");Extension Config
Because our algorithm wasm library and wasm js encapsulation use SharedArrayBuffer, it must be run in the extension offscreen html.
webpack.config.js
When the extension is compiled, copy the 4 files directly to the extension build directory. webpack.config.js needs to add the following configuration.
new CopyWebpackPlugin({
patterns: [
{
from: 'node_modules/@primuslabs/zktls-ext-core-sdk/dist/algorithm/client_plugin.wasm',
to: path.join(__dirname, 'build'),
force: true,
},
],
}),
new CopyWebpackPlugin({
patterns: [
{
from: 'node_modules/@primuslabs/zktls-ext-core-sdk/dist/algorithm/client_plugin.worker.js',
to: path.join(__dirname, 'build'),
force: true,
},
],
}),
new CopyWebpackPlugin({
patterns: [
{
from: 'node_modules/@primuslabs/zktls-ext-core-sdk/dist/algorithm/client_plugin.js',
to: path.join(__dirname, 'build'),
force: true,
},
],
}),
new CopyWebpackPlugin({
patterns: [
{
from: 'node_modules/@primuslabs/zktls-ext-core-sdk/dist/algorithm/primus_zk.js',
to: path.join(__dirname, 'build'),
force: true,
},
],
}),offscreen html
You need to import two js files in your offscreen html.
<html>
......
<script src="client_plugin.js"></script>
<script src="primus_zk.js"></script>
......
</html>extension manifest.json
The extension manifest.json file may add the following configuration:
"content_security_policy": {
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self';"
},
"permissions": [
"offscreen"
],Test Example
The appSecret from Primus Developer Hub needs to sign the proof request parameters. For security reasons, appSecret cannot be configured on the extension side. The Test Example configures appSecret in the extension code to better illustrate the process.
Implementation
