From 03be71505a4c7d6e647409737a0072fdecf7717b Mon Sep 17 00:00:00 2001 From: zqhxuyuan Date: Wed, 19 Apr 2023 15:41:50 +0800 Subject: [PATCH 1/4] zkSBT doc Signed-off-by: zqhxuyuan --- manta-js/docs/how-to-mint-zk-sbt.md | 151 +++++++++++++++++++++++++++- 1 file changed, 150 insertions(+), 1 deletion(-) diff --git a/manta-js/docs/how-to-mint-zk-sbt.md b/manta-js/docs/how-to-mint-zk-sbt.md index aea051a4..50e20db0 100644 --- a/manta-js/docs/how-to-mint-zk-sbt.md +++ b/manta-js/docs/how-to-mint-zk-sbt.md @@ -1,3 +1,152 @@ # How to mint zkSBT -Coming Soon... \ No newline at end of file +There're two case to mint zkSBT now. +- Credentials from other blockchain, like zkBAB, zkGalxe etc. +- Directly mint SBT on Manta network. + +## Manta zkSBT + +1. Manta Wallet initialization, reference to: https://github.com/Manta-Network/sdk/blob/signer_extension/manta-js/docs/how-to-use-manta-private-wallet-in-dapp.md + +2. reserve asest id before mint zkSBT. + +```typescript +const reserverTx = await api.tx.mantaSbt.reserveSbt(); +await reserveTx.signAndSend(polkadotAddress); +``` + +3. Query your reserve ids from on chain storage: + +```typescript +const assetIdRange = await api.query.mantaSbt.reservedIds(polkadotAddress); +``` + +3. Mint zkSBT by your reserved asset id list. + +``` typescript +const sbtInfoList = [ + { assetId: new BN(1) } +]; +const { posts, transactionDatas } = await privateWallet.multiSbtPostBuild(sbtInfoList); +const batchesTx = []; +for(var post in posts) { + const tx = api.tx.mantaSbt.toPrivate(post, metadata); + batchesTx.push(tx); +} +await batchesTx.signAndSend(polkadotAddress); +``` + +4. When user mint zkSBT, We also return `transactionDatas` which contains the proof key of zkSBT. Third party project can use this proof key information to request our NPO backend service: + +POST http://${NPO_BACKEND_SERVICE_URL}/npo/raw-proofs + +```json +{ + "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + "proof_info": [ + { + "proof_id": "25ea6df873d1541293bf75953103f1d25816eef3ce713c7b7809c1a109ce3025", + "blur_url": "BAB Metadata 3023", + "transaction_data":{"identifier":{"is_transparent":false,"utxo_commitment_randomness":[37,234,109,248,115,209,84,18,147,191,117,149,49,3,241,210,88,22,238,243,206,113,60,123,120,9,193,161,9,206,48,37]},"asset_info":{"id":[5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"value":1},"zk_address":{"receiving_key":[80,174,139,214,69,21,2,245,8,21,248,250,162,236,202,190,196,158,75,11,217,235,212,191,19,227,146,27,160,205,8,130]}} + } + ] +} +``` + +The successfully response like: + +```json +{ + "status": true +} +``` + +If the api result is failed, it means your transaction data is not correct. + + +5. After proof information is stored on our backend service, you can request our backend verifier service to verify if given proof information is valid or not: + +POST http://${NPO_BACKEND_SERVICE_URL}/npo/raw-proof + +```json +{ + "proof_id": ["0x01234567890123456789012345678901"] +} +``` + +The successfully response example like: + +```json +{ + "status": true, + "data": [ + { + "proof_id": "0x01234567890123456789012345678901", + "metadata": "https://example.com/1.png", + "asset_id": "1" + } + ] +} +``` + +## Credentials + +We currently support ethereum compatible chain which use EIP-712 signature, and only allow whitelist users to mint credentials zkSBT. + +1. Before user mint sbt, the user need to added to allowlist: + +```typescript +const address = { + bab: "0x_babAddress" +} +const allowlistTx = await api.tx.mantaSbt.allowlistEvmAccount(address); +await allowlistTx.signAndSend(polkadotAddress); +``` + +2. Query your asset ids from on chain storage: + +```typescript +const address = { + bab: "0x_babAddress" +} +const mintStatus = await api.query.mantaSbt.evmAddressAllowlist(address); +``` + +If the result value is Available, then the user is allowed to mint sbt, otherwise if the value is AlreadyMinted, it means the user has already minted sbt. + +```json +{ + Available: 1 +} +``` + +3. Get TransferPost from `privateWallet` + +```typescript +const sbtInfoList = [ + { assetId: new BN(1) } +]; +const { posts, transactionDatas } = await privateWallet.multiSbtPostBuild(sbtInfoList); +// This example only mint 1 zkSBT, you can batch your transaction if you have multiple sbt to mint. +const post = posts[0]; +const transactionData = transactionDatas[0]; +``` + +4. Mint zkSBT. + +```typescript +const metadata = "YOUR METADATA"; + +const mintTx = api.tx.mantaSbt.mintSbtEth( + post, + signedChainId, + signature, + address, + null, + null, + metadata +); +await mintTx.signAndSend(polkadotAddress); +``` + +5. Using the `transactionDatas` and request to NPO backend service, this workflow is same as previous part like mint sbt on Manata Network. \ No newline at end of file From aad78397363a9d8e1e85c8659c89abe68ac1f2f8 Mon Sep 17 00:00:00 2001 From: zqhxuyuan Date: Thu, 20 Apr 2023 11:14:01 +0800 Subject: [PATCH 2/4] update Signed-off-by: zqhxuyuan --- manta-js/docs/how-to-mint-zk-sbt.md | 45 ++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/manta-js/docs/how-to-mint-zk-sbt.md b/manta-js/docs/how-to-mint-zk-sbt.md index 50e20db0..007932d1 100644 --- a/manta-js/docs/how-to-mint-zk-sbt.md +++ b/manta-js/docs/how-to-mint-zk-sbt.md @@ -33,27 +33,31 @@ for(var post in posts) { const tx = api.tx.mantaSbt.toPrivate(post, metadata); batchesTx.push(tx); } -await batchesTx.signAndSend(polkadotAddress); +await api.tx.utility.batch(batchesTx).signAndSend(polkadotAddress); ``` 4. When user mint zkSBT, We also return `transactionDatas` which contains the proof key of zkSBT. Third party project can use this proof key information to request our NPO backend service: POST http://${NPO_BACKEND_SERVICE_URL}/npo/raw-proofs +> Note: Please contact our team to get `NPO_BACKEND_SERVICE_URL`. + ```json { - "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + "address": "YOUR POLKADOT ADDRESS", + "token_type": "zkBAB", "proof_info": [ { - "proof_id": "25ea6df873d1541293bf75953103f1d25816eef3ce713c7b7809c1a109ce3025", - "blur_url": "BAB Metadata 3023", + "proof_id": "0x4d551bb6932126300d403e9963aa051f43675ca4b56a53e9f8e3e84783440726", + "blur_url": "https://npo-cdn.asmatch.xyz/zkBAB_Front.jpg", + "asset_id": "115", "transaction_data":{"identifier":{"is_transparent":false,"utxo_commitment_randomness":[37,234,109,248,115,209,84,18,147,191,117,149,49,3,241,210,88,22,238,243,206,113,60,123,120,9,193,161,9,206,48,37]},"asset_info":{"id":[5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"value":1},"zk_address":{"receiving_key":[80,174,139,214,69,21,2,245,8,21,248,250,162,236,202,190,196,158,75,11,217,235,212,191,19,227,146,27,160,205,8,130]}} } ] } ``` -The successfully response like: +A successfully response example: ```json { @@ -64,26 +68,32 @@ The successfully response like: If the api result is failed, it means your transaction data is not correct. -5. After proof information is stored on our backend service, you can request our backend verifier service to verify if given proof information is valid or not: +5. After proof information is stored on NPO backend service, you can request NPO backend verifier service to check if given proof information is valid or not: POST http://${NPO_BACKEND_SERVICE_URL}/npo/raw-proof ```json { - "proof_id": ["0x01234567890123456789012345678901"] + "proof_id": ["0x4d551bb6932126300d403e9963aa051f43675ca4b56a53e9f8e3e84783440726"] } ``` -The successfully response example like: +A successfully response example: ```json { "status": true, "data": [ { - "proof_id": "0x01234567890123456789012345678901", - "metadata": "https://example.com/1.png", - "asset_id": "1" + "address": "dmuiB62dLVDJxRG66ZPBRnrpvgvgHdQ335qNczznnZsSHmfz1", + "url": "https://npo-cdn.asmatch.xyz/zkBAB_Front.jpg", + "randomness": "00000000000000000000000000000000", + "asset_id": "115", + "token_type": "zkBAB", + "proof_id": "0x4d551bb6932126300d403e9963aa051f43675ca4b56a53e9f8e3e84783440726", + "createAt": 1681788356, + "category": "Credential", + "token_name": "BAB" } ] } @@ -91,13 +101,15 @@ The successfully response example like: ## Credentials -We currently support ethereum compatible chain which use EIP-712 signature, and only allow whitelist users to mint credentials zkSBT. +We currently support Ethereum compatible chain which use EIP-712 signature, and only allow whitelist users to mint credentials zkSBT. 1. Before user mint sbt, the user need to added to allowlist: +> Note: We have a limit that only one special privilege account can execute `allowlistEvmAccount` transaction. So please also contact us if your project has requirement to mint credentials zkSBT. + ```typescript const address = { - bab: "0x_babAddress" + bab: "YOUR BAB ADDRESS" } const allowlistTx = await api.tx.mantaSbt.allowlistEvmAccount(address); await allowlistTx.signAndSend(polkadotAddress); @@ -107,7 +119,7 @@ await allowlistTx.signAndSend(polkadotAddress); ```typescript const address = { - bab: "0x_babAddress" + bab: "YOUR BAB ADDRESS" } const mintStatus = await api.query.mantaSbt.evmAddressAllowlist(address); ``` @@ -134,8 +146,13 @@ const transactionData = transactionDatas[0]; 4. Mint zkSBT. +> Note: We're using EIP-712 signature to verify use's eth address. + ```typescript const metadata = "YOUR METADATA"; +const address = { + bab: "YOUR BAB ADDRESS" +} const mintTx = api.tx.mantaSbt.mintSbtEth( post, From 9a729bd089995302ce8d16d9414f86069aab2127 Mon Sep 17 00:00:00 2001 From: zqhxuyuan Date: Sun, 23 Apr 2023 11:33:28 +0800 Subject: [PATCH 3/4] update doc Signed-off-by: zqhxuyuan --- manta-js/docs/how-to-mint-zk-sbt.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/manta-js/docs/how-to-mint-zk-sbt.md b/manta-js/docs/how-to-mint-zk-sbt.md index 007932d1..0acb4994 100644 --- a/manta-js/docs/how-to-mint-zk-sbt.md +++ b/manta-js/docs/how-to-mint-zk-sbt.md @@ -103,9 +103,9 @@ A successfully response example: We currently support Ethereum compatible chain which use EIP-712 signature, and only allow whitelist users to mint credentials zkSBT. -1. Before user mint sbt, the user need to added to allowlist: +1. Before user mint zkSBT, user's ethereum address need to added to allowlist. Currently we only allow one special privilege account to execute `allowlistEvmAccount` transaction. So please also contact us if your project has requirement to mint credentials zkSBT. -> Note: We have a limit that only one special privilege account can execute `allowlistEvmAccount` transaction. So please also contact us if your project has requirement to mint credentials zkSBT. +This is an example of adding user's bab address to `allowlistEvmAccount`. ```typescript const address = { @@ -117,6 +117,8 @@ await allowlistTx.signAndSend(polkadotAddress); 2. Query your asset ids from on chain storage: +This is an example of query user's bab address from `evmAddressAllowlist`. + ```typescript const address = { bab: "YOUR BAB ADDRESS" @@ -124,35 +126,34 @@ const address = { const mintStatus = await api.query.mantaSbt.evmAddressAllowlist(address); ``` -If the result value is Available, then the user is allowed to mint sbt, otherwise if the value is AlreadyMinted, it means the user has already minted sbt. +If the query result value is `Available` and contains asset id, then the user is allowed to mint zkSBT, otherwise if the value is `AlreadyMinted`, it means the user has already minted zkSBT. Or if the value is `None`, it means the user is not allowed to mint zkSBT. -```json +``` { Available: 1 } ``` -3. Get TransferPost from `privateWallet` +3. Get `TransferPost` from `privateWallet`. ```typescript const sbtInfoList = [ { assetId: new BN(1) } ]; const { posts, transactionDatas } = await privateWallet.multiSbtPostBuild(sbtInfoList); -// This example only mint 1 zkSBT, you can batch your transaction if you have multiple sbt to mint. -const post = posts[0]; -const transactionData = transactionDatas[0]; ``` 4. Mint zkSBT. -> Note: We're using EIP-712 signature to verify use's eth address. +> Note: We're using EIP-712 signature to verify use's eth address. So `mintSbtEth` extrinsic need to provide `chainId`, `signature`, and `address`. ```typescript const metadata = "YOUR METADATA"; const address = { bab: "YOUR BAB ADDRESS" } +// This example only mint 1 zkSBT, you can batch your transaction if you have multiple zkSBT to mint. +const post = posts[0]; const mintTx = api.tx.mantaSbt.mintSbtEth( post, @@ -166,4 +167,4 @@ const mintTx = api.tx.mantaSbt.mintSbtEth( await mintTx.signAndSend(polkadotAddress); ``` -5. Using the `transactionDatas` and request to NPO backend service, this workflow is same as previous part like mint sbt on Manata Network. \ No newline at end of file +5. Using the `transactionDatas` and request to NPO backend service, this workflow is same as previous part like mint zkSBT on Manata Network. \ No newline at end of file From 870b9839f60b4dfe044b297d261e41f6c5281cc3 Mon Sep 17 00:00:00 2001 From: zqhxuyuan Date: Sun, 23 Apr 2023 11:36:51 +0800 Subject: [PATCH 4/4] update Signed-off-by: zqhxuyuan --- manta-js/docs/how-to-mint-zk-sbt.md | 69 +++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/manta-js/docs/how-to-mint-zk-sbt.md b/manta-js/docs/how-to-mint-zk-sbt.md index 0acb4994..b9e777d8 100644 --- a/manta-js/docs/how-to-mint-zk-sbt.md +++ b/manta-js/docs/how-to-mint-zk-sbt.md @@ -21,7 +21,7 @@ await reserveTx.signAndSend(polkadotAddress); const assetIdRange = await api.query.mantaSbt.reservedIds(polkadotAddress); ``` -3. Mint zkSBT by your reserved asset id list. +4. Mint zkSBT by your reserved asset id list. ``` typescript const sbtInfoList = [ @@ -36,7 +36,7 @@ for(var post in posts) { await api.tx.utility.batch(batchesTx).signAndSend(polkadotAddress); ``` -4. When user mint zkSBT, We also return `transactionDatas` which contains the proof key of zkSBT. Third party project can use this proof key information to request our NPO backend service: +5. When user mint zkSBT, We also return `transactionDatas` which contains the proof key of zkSBT. Third party project can use this proof key information to request our NPO backend service: POST http://${NPO_BACKEND_SERVICE_URL}/npo/raw-proofs @@ -68,7 +68,7 @@ A successfully response example: If the api result is failed, it means your transaction data is not correct. -5. After proof information is stored on NPO backend service, you can request NPO backend verifier service to check if given proof information is valid or not: +6. After proof information is stored on NPO backend service, you can request NPO backend verifier service to check if given proof information is valid or not: POST http://${NPO_BACKEND_SERVICE_URL}/npo/raw-proof @@ -167,4 +167,65 @@ const mintTx = api.tx.mantaSbt.mintSbtEth( await mintTx.signAndSend(polkadotAddress); ``` -5. Using the `transactionDatas` and request to NPO backend service, this workflow is same as previous part like mint zkSBT on Manata Network. \ No newline at end of file +5. Using the `transactionDatas` and request to NPO backend service, Third party project can use this proof key information to request NPO backend service: + +POST http://${NPO_BACKEND_SERVICE_URL}/npo/raw-proofs + +> Note: Please contact our team to get `NPO_BACKEND_SERVICE_URL`. + +```json +{ + "address": "YOUR POLKADOT ADDRESS", + "token_type": "zkBAB", + "proof_info": [ + { + "proof_id": "0x4d551bb6932126300d403e9963aa051f43675ca4b56a53e9f8e3e84783440726", + "blur_url": "https://npo-cdn.asmatch.xyz/zkBAB_Front.jpg", + "asset_id": "115", + "transaction_data":{"identifier":{"is_transparent":false,"utxo_commitment_randomness":[37,234,109,248,115,209,84,18,147,191,117,149,49,3,241,210,88,22,238,243,206,113,60,123,120,9,193,161,9,206,48,37]},"asset_info":{"id":[5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"value":1},"zk_address":{"receiving_key":[80,174,139,214,69,21,2,245,8,21,248,250,162,236,202,190,196,158,75,11,217,235,212,191,19,227,146,27,160,205,8,130]}} + } + ] +} +``` + +A successfully response example: + +```json +{ + "status": true +} +``` + +If the api result is failed, it means your transaction data is not correct. + + +6. After proof information is stored on NPO backend service, you can request NPO backend verifier service to check if given proof information is valid or not: + +POST http://${NPO_BACKEND_SERVICE_URL}/npo/raw-proof + +```json +{ + "proof_id": ["0x4d551bb6932126300d403e9963aa051f43675ca4b56a53e9f8e3e84783440726"] +} +``` + +A successfully response example: + +```json +{ + "status": true, + "data": [ + { + "address": "dmuiB62dLVDJxRG66ZPBRnrpvgvgHdQ335qNczznnZsSHmfz1", + "url": "https://npo-cdn.asmatch.xyz/zkBAB_Front.jpg", + "randomness": "00000000000000000000000000000000", + "asset_id": "115", + "token_type": "zkBAB", + "proof_id": "0x4d551bb6932126300d403e9963aa051f43675ca4b56a53e9f8e3e84783440726", + "createAt": 1681788356, + "category": "Credential", + "token_name": "BAB" + } + ] +} +```