-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: v0.7.x amino data MsgAttest support (#90)
* chore(release): Publish v0.6.0 * feat: add amino data MsgAttest converter * chore(release): Publish v0.7.0 * fix: use base64 string for hash in amino * chore(release): Publish v0.7.1
- Loading branch information
Showing
14 changed files
with
163 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,5 @@ | |
"packages": [ | ||
"packages/*" | ||
], | ||
"version": "0.6.0" | ||
"version": "0.7.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@regen-network/api", | ||
"version": "0.6.0", | ||
"version": "0.7.1", | ||
"author": "[email protected]", | ||
"description": "A client library for the Regen Ledger", | ||
"license": "Apache-2.0", | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AminoConverters } from '@cosmjs/stargate'; | ||
import { attestConverter, attestTypeUrl } from './v1/attest_amino'; | ||
|
||
export function createDataAminoConverters(): AminoConverters { | ||
return { | ||
[attestTypeUrl]: attestConverter(), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MsgAttest> => ({ | ||
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('')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { createEcocreditAminoConverters } from './ecocredit/converters'; | ||
export { createDataAminoConverters } from './data/converters'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
{ | ||
"name": "@regen-network/demo-app", | ||
"version": "0.6.0", | ||
"version": "0.7.1", | ||
"author": "[email protected]", | ||
"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", | ||
|