Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2879 tzip32 doc #2994

Merged
merged 44 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
81f82f7
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Nov 7, 2023
eab82bb
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Nov 10, 2023
0259cdd
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Nov 21, 2023
b1a2679
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Nov 27, 2023
45223bd
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Nov 28, 2023
a82b5cd
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Dec 1, 2023
3b08821
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Dec 5, 2023
bfd1f49
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Dec 5, 2023
5d0a7cc
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Dec 13, 2023
7b9d4c1
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Dec 14, 2023
37e14e4
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Dec 28, 2023
dc68be9
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Jan 9, 2024
f259810
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Jan 16, 2024
6fdda51
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Feb 6, 2024
298b413
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Feb 12, 2024
06af53b
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Feb 14, 2024
e4853cf
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Feb 16, 2024
fc2e2b0
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Feb 20, 2024
a64564e
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Feb 21, 2024
ae561ab
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Feb 22, 2024
0a2974b
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Feb 29, 2024
708d150
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Mar 1, 2024
e018e9e
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Mar 8, 2024
4523ffb
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Mar 19, 2024
3c386ad
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Mar 26, 2024
dffb59c
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Apr 5, 2024
b58a460
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Apr 5, 2024
8fa69af
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Apr 8, 2024
a896a23
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Apr 9, 2024
fd47258
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Apr 11, 2024
00892e8
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Apr 11, 2024
a39aaa5
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Apr 17, 2024
82f5a89
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang May 9, 2024
bbaba4b
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang May 13, 2024
47324c0
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang May 27, 2024
f1c5423
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Jun 6, 2024
8541658
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Jun 11, 2024
4037e50
Merge branch 'master' of https://github.com/ecadlabs/taquito
hui-an-yang Jun 13, 2024
f93802e
docs: tzip-32 signing documentation
hui-an-yang Jun 17, 2024
34a19ca
docs: updated examples in tab and and v20 versioned docs
hui-an-yang Jun 18, 2024
ebb5db4
docs: addressed review comments
hui-an-yang Jun 18, 2024
17d4711
test: add signing.md file changes
hui-an-yang Jun 18, 2024
9f4a145
Merge branch 'master' of https://github.com/ecadlabs/taquito into 287…
hui-an-yang Jul 16, 2024
42b1ef7
test: fixing integration test
hui-an-yang Jul 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions docs/signing.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,87 @@ const isVerified = verifySignature(
);
```

## Generating a tzip-32 message signature
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a good idea to capitalize to Tzip-32 here and everywhere else


The community have proposed [tzip-32](https://gitlab.com/tezos/tzip/-/blob/71be45d3ae2e15cec5c7a2f84feb88aac58fbe5e/drafts/current/draft-message-signing/tzip-32.md)(draft), Off-Chain Message Signing, which aims to define a formal message signing standard that is simple, secure, extendable and compatible with hardware wallets. Tzip-32 can be further used in [tzip-33](https://gitlab.com/tezos/tzip/-/blob/6483efc9e591960effe76f4ae996ec187bf13bf4/drafts/current/draft-sign-in-with-tezos.md)(draft) which is a [caip-122](https://chainagnostic.org/CAIPs/caip-122) compliant sign-in with Tezos standard.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also let's capitalize CAIP-122


**Message encoding**

This is the schema to encode the message into bytes, please read the [tzip-32](https://gitlab.com/tezos/tzip/-/blob/71be45d3ae2e15cec5c7a2f84feb88aac58fbe5e/drafts/current/draft-message-signing/tzip-32.md) for more detail.

| Name | Size | Contents |
|-----------------------|----------|-------------------------|
| magic_string | 30 bytes | bytes |
| # Bytes in next field | 1 byte | unsigned 8-bit integer |
| interface | variable | bytes |
| character_encoding | 1 byte | unsigned 8-bit integer |
| # Bytes in next field | 2 bytes | unsigned 16-bit integer |
| message | Variable | bytes |


<Tabs
defaultValue="contractAPI"
values={[
{label: 'Contract API', value: 'contractAPI'},
{label: 'Wallet API', value: 'walletAPI'}
]}>
<TabItem value="contractAPI">


The Off-Chain Message Signing magic bytes is `0x80` defined in [tzip-31](https://gitlab.com/tezos/tzip/-/blob/71be45d3ae2e15cec5c7a2f84feb88aac58fbe5e/drafts/current/draft-signer-requests/tzip-31.md)(draft).

```js live noInline
// import { TezosToolkit } from '@taquito/taquito'
// import { InMemorySigner } from '@taquito/signer'
// import { stringToBytes, num2PaddedHex } from '@taquito/utils';
// const Tezos = new TezosToolkit('https://ghostnet.ecadinfra.com');

let magicByte = '0x80'
let magicString = 'tezos signed offchain message'
let interface_ = 'tzip://32'
let characterEncoding = '0'
let message = 'Hello world!'

let bytes = stringToBytes(magicString) + num2PaddedHex(interface_.length, 8) + stringToBytes(interface_) + num2PaddedHex(Number(characterEncoding), 8) + num2PaddedHex(message.length, 16) + stringToBytes(message)

InMemorySigner.fromSecretKey('edsk2rKA8YEExg9Zo2qNPiQnnYheF1DhqjLVmfKdxiFfu5GyGRZRnb')
.then((theSigner) => {
Tezos.setProvider({ signer: theSigner });
return Tezos.signer.sign(bytes, new Uint8Array([parseInt(magicByte, 16)]))
})
.then(signed => {
println(JSON.stringify(signed, null, 2));
})
.catch((error) => println(`Error: ${error} ${JSON.stringify(error, null, 2)}`));
```

</TabItem>
<TabItem value="walletAPI">

```js live noInline wallet
// import { TezosToolkit } from '@taquito/taquito'
// import { InMemorySigner } from '@taquito/signer'
// import { stringToBytes, num2PaddedHex } from '@taquito/utils';
// const Tezos = new TezosToolkit('https://ghostnet.ecadinfra.com');

let magicByte = '0x80'
let magicString = 'tezos signed offchain message'
let interface_ = 'tzip://32'
let characterEncoding = '0'
let message = 'Hello world!'

let bytes = stringToBytes(magicString) + num2PaddedHex(interface_.length, 8) + stringToBytes(interface_) + num2PaddedHex(characterEncoding, 8) + num2PaddedHex(message.length, 16) + stringToBytes(message)

const payload = {
signingType: SigningType.RAW,
payload: magicByte + bytes
}
wallet.client.requestSignPayload(payload).then(signed => println(JSON.stringify(signed, null, 2)))
```

</TabItem>
</Tabs>

## Signing Michelson data

Taquito also offers the possibility to sign Michelson code. This feature can be useful, for example, if you need to send a lambda to a contract to be executed but want to restrict the number of users who can submit a lambda by verifying the signer's address. The signing of Michelson code requires the use of the `michel-codec` package:
Expand Down
21 changes: 11 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading