diff --git a/CHANGELOG.md b/CHANGELOG.md index 35b6df43..8fa57e72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,29 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.7.1](https://github.com/regen-network/regen-js/compare/v0.7.0...v0.7.1) (2024-08-05) + + +### Bug Fixes + +* use base64 string for hash in amino ([88737e5](https://github.com/regen-network/regen-js/commit/88737e56f612fb957e997e26ff852662768c2046)) + + + + + +# [0.7.0](https://github.com/regen-network/regen-js/compare/v0.6.0...v0.7.0) (2024-08-05) + + +### Features + +* add amino data MsgAttest converter ([739163b](https://github.com/regen-network/regen-js/commit/739163b341ff466d14fdd7df8025ffd7c0cadfe4)) + + + + + + # [0.6.0](https://github.com/regen-network/regen-js/compare/v0.3.0...v0.6.0) (2023-03-27) diff --git a/lerna.json b/lerna.json index f3a9d8a3..89b3c852 100644 --- a/lerna.json +++ b/lerna.json @@ -9,5 +9,5 @@ "packages": [ "packages/*" ], - "version": "0.6.0" + "version": "0.7.1" } diff --git a/packages/api/CHANGELOG.md b/packages/api/CHANGELOG.md index 17a7615f..a6a2c6b0 100644 --- a/packages/api/CHANGELOG.md +++ b/packages/api/CHANGELOG.md @@ -3,6 +3,29 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.7.1](https://github.com/regen-network/regen-js/compare/v0.7.0...v0.7.1) (2024-08-05) + + +### Bug Fixes + +* use base64 string for hash in amino ([88737e5](https://github.com/regen-network/regen-js/commit/88737e56f612fb957e997e26ff852662768c2046)) + + + + + +# [0.7.0](https://github.com/regen-network/regen-js/compare/v0.6.0...v0.7.0) (2024-08-05) + + +### Features + +* add amino data MsgAttest converter ([739163b](https://github.com/regen-network/regen-js/commit/739163b341ff466d14fdd7df8025ffd7c0cadfe4)) + + + + + + # [0.6.0](https://github.com/regen-network/regen-js/compare/v0.3.0...v0.6.0) (2023-03-27) diff --git a/packages/api/package.json b/packages/api/package.json index a14149c2..ab99000d 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -1,6 +1,6 @@ { "name": "@regen-network/api", - "version": "0.6.0", + "version": "0.7.1", "author": "admin@regen.network", "description": "A client library for the Regen Ledger", "license": "Apache-2.0", diff --git a/packages/api/src/tx/modules/ecocredit/converter-utils.ts b/packages/api/src/tx/modules/converter-utils.ts similarity index 100% rename from packages/api/src/tx/modules/ecocredit/converter-utils.ts rename to packages/api/src/tx/modules/converter-utils.ts diff --git a/packages/api/src/tx/modules/data/converters.ts b/packages/api/src/tx/modules/data/converters.ts new file mode 100644 index 00000000..9e770934 --- /dev/null +++ b/packages/api/src/tx/modules/data/converters.ts @@ -0,0 +1,8 @@ +import { AminoConverters } from '@cosmjs/stargate'; +import { attestConverter, attestTypeUrl } from './v1/attest_amino'; + +export function createDataAminoConverters(): AminoConverters { + return { + [attestTypeUrl]: attestConverter(), + }; +} diff --git a/packages/api/src/tx/modules/data/v1/attest_amino.ts b/packages/api/src/tx/modules/data/v1/attest_amino.ts new file mode 100644 index 00000000..65e0c727 --- /dev/null +++ b/packages/api/src/tx/modules/data/v1/attest_amino.ts @@ -0,0 +1,79 @@ +import { AminoMsg } from '@cosmjs/amino'; + +import { MsgAttest } from '../../../../generated/regen/data/v1/tx'; +import { + DigestAlgorithm, + GraphCanonicalizationAlgorithm, + GraphMerkleTree, + ContentHash_Graph, +} from '../../../../generated/regen/data/v1/types'; +import { AminoConverter } from '@cosmjs/stargate'; +import { omitDefault } from '../../converter-utils'; + +const msgAttestAminoType = 'regen-ledger/MsgAttest'; + +export const attestTypeUrl = '/' + MsgAttest.$type; + +type AminoContentHash_Graph = { + hash: string; + digest_algorithm?: DigestAlgorithm; + canonicalization_algorithm?: GraphCanonicalizationAlgorithm; + merkle_tree?: GraphMerkleTree; +}; +export interface AminoMsgAttest extends AminoMsg { + readonly type: typeof msgAttestAminoType; + readonly value: { + readonly attestor: string; + readonly content_hashes: AminoContentHash_Graph[]; + }; +} + +export function attestConverter(): AminoConverter { + return { + aminoType: msgAttestAminoType, + toAmino: ({ + attestor, + contentHashes, + }: MsgAttest): AminoMsgAttest['value'] => ({ + attestor, + content_hashes: contentHashes.map(contentHash => ({ + hash: base64FromBytes(contentHash.hash), + digest_algorithm: omitDefault(contentHash.digestAlgorithm), + canonicalization_algorithm: omitDefault( + contentHash.canonicalizationAlgorithm, + ), + merkle_tree: omitDefault(contentHash.merkleTree), + })), + }), + fromAmino: ({ + attestor, + content_hashes, + }: AminoMsgAttest['value']): Partial => ({ + attestor, + contentHashes: content_hashes.map(contentHash => ({ + $type: ContentHash_Graph.$type, + hash: bytesFromBase64(contentHash.hash), + digestAlgorithm: contentHash.digest_algorithm || 0, + canonicalizationAlgorithm: contentHash.canonicalization_algorithm || 0, + merkleTree: contentHash.merkle_tree || 0, + })), + }), + }; +} + +function bytesFromBase64(b64: string): Uint8Array { + const bin = window.atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; +} + +function base64FromBytes(arr: Uint8Array): string { + const bin: string[] = []; + arr.forEach(byte => { + bin.push(String.fromCharCode(byte)); + }); + return window.btoa(bin.join('')); +} diff --git a/packages/api/src/tx/modules/ecocredit/marketplace/v1/buy_direct_amino.ts b/packages/api/src/tx/modules/ecocredit/marketplace/v1/buy_direct_amino.ts index a26a8eae..12a621fe 100644 --- a/packages/api/src/tx/modules/ecocredit/marketplace/v1/buy_direct_amino.ts +++ b/packages/api/src/tx/modules/ecocredit/marketplace/v1/buy_direct_amino.ts @@ -6,7 +6,7 @@ import { MsgBuyDirect_Order, } from '../../../../../generated/regen/ecocredit/marketplace/v1/tx'; import { AminoCoin } from './sell_amino'; -import { omitDefault } from '../../converter-utils'; +import { omitDefault } from '../../../converter-utils'; const msgBuyDirectAmnioType = 'regen.marketplace/MsgBuyDirect'; diff --git a/packages/api/src/tx/modules/ecocredit/marketplace/v1/sell_amino.ts b/packages/api/src/tx/modules/ecocredit/marketplace/v1/sell_amino.ts index 24c73e5c..b778290d 100644 --- a/packages/api/src/tx/modules/ecocredit/marketplace/v1/sell_amino.ts +++ b/packages/api/src/tx/modules/ecocredit/marketplace/v1/sell_amino.ts @@ -4,7 +4,7 @@ import { MsgSell, MsgSell_Order, } from '../../../../../generated/regen/ecocredit/marketplace/v1/tx'; -import { AminoDate } from '../../converter-utils'; +import { AminoDate } from '../../../converter-utils'; const msgSellAminoType = 'regen.marketplace/MsgSell'; diff --git a/packages/api/src/tx/modules/ecocredit/v1/create_batch_amino.ts b/packages/api/src/tx/modules/ecocredit/v1/create_batch_amino.ts index 9491875a..989e83a4 100644 --- a/packages/api/src/tx/modules/ecocredit/v1/create_batch_amino.ts +++ b/packages/api/src/tx/modules/ecocredit/v1/create_batch_amino.ts @@ -5,7 +5,7 @@ import { BatchIssuance, OriginTx, } from '../../../../generated/regen/ecocredit/v1/types'; -import { AminoDate } from '../converter-utils'; +import { AminoDate } from '../../converter-utils'; const msgCreateBatchAminoType = 'regen/MsgCreateBatch'; diff --git a/packages/api/src/tx/modules/index.ts b/packages/api/src/tx/modules/index.ts index 59f22690..3a6da0ed 100644 --- a/packages/api/src/tx/modules/index.ts +++ b/packages/api/src/tx/modules/index.ts @@ -1 +1,2 @@ export { createEcocreditAminoConverters } from './ecocredit/converters'; +export { createDataAminoConverters } from './data/converters'; diff --git a/packages/api/src/tx/msg.ts b/packages/api/src/tx/msg.ts index f7fd8615..6b7fa806 100644 --- a/packages/api/src/tx/msg.ts +++ b/packages/api/src/tx/msg.ts @@ -10,7 +10,10 @@ import { Registry, EncodeObject, GeneratedType } from '@cosmjs/proto-signing'; import { SigningConnectionOptions } from '../api'; import { createStargateSigningClient } from './stargate-signing'; -import { createEcocreditAminoConverters } from './modules'; +import { + createDataAminoConverters, + createEcocreditAminoConverters, +} from './modules'; import { messageTypeRegistry } from '../generated/typeRegistry'; export interface MessageClient { @@ -26,6 +29,7 @@ export interface MessageClient { function createDefaultTypes(): AminoConverters { return { ...createEcocreditAminoConverters(), + ...createDataAminoConverters(), }; } diff --git a/packages/demo-app/CHANGELOG.md b/packages/demo-app/CHANGELOG.md index 19b66568..87358422 100644 --- a/packages/demo-app/CHANGELOG.md +++ b/packages/demo-app/CHANGELOG.md @@ -3,6 +3,23 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.7.1](https://github.com/regen-network/regen-js/compare/v0.7.0...v0.7.1) (2024-08-05) + +**Note:** Version bump only for package @regen-network/demo-app + + + + + +# [0.7.0](https://github.com/regen-network/regen-js/compare/v0.6.0...v0.7.0) (2024-08-05) + +**Note:** Version bump only for package @regen-network/demo-app + + + + + + # [0.6.0](https://github.com/regen-network/regen-js/compare/v0.3.0...v0.6.0) (2023-03-27) diff --git a/packages/demo-app/package.json b/packages/demo-app/package.json index ec201760..da961a63 100644 --- a/packages/demo-app/package.json +++ b/packages/demo-app/package.json @@ -1,13 +1,13 @@ { "name": "@regen-network/demo-app", - "version": "0.6.0", + "version": "0.7.1", "author": "admin@regen.network", "description": "Demo web application using @regen-network/api", "license": "Apache-2.0", "private": true, "repository": "https://github.com/regen-network/regen-js", "dependencies": { - "@regen-network/api": "^0.6.0", + "@regen-network/api": "^0.7.1", "@testing-library/jest-dom": "^5.11.8", "@testing-library/react": "^11.2.2", "@testing-library/user-event": "^12.6.0",