polkadot-js / common

Utilities and base libraries for use across polkadot-js for Polkadot and Substrate. Includes base libraries, crypto helpers and cross-environment helpers.
Apache License 2.0
253 stars 144 forks source link

Please provide documentation for the pkcs8 related constants in keyring #1908

Closed clearloop closed 8 months ago

clearloop commented 8 months ago

Documentation requests

https://github.com/polkadot-js/common/blob/6971012f4af62f453ba25d83d0ebbfd12eaf5709/packages/keyring/src/pair/defaults.ts#L4-L5

// review: where are these bytes from, what's the exact meaning of them
export const PKCS8_DIVIDER = new Uint8Array([161, 35, 3, 33, 0]);
// review: same
export const PKCS8_HEADER = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);

the header and divider here seems not following the private key information syntax defined in RFC5208-section-5

PrivateKeyInfo ::= SEQUENCE {
        version                   Version,
        privateKeyAlgorithm       PrivateKeyAlgorithmIdentifier,
        privateKey                PrivateKey,
        attributes           [0]  IMPLICIT Attributes OPTIONAL }

Version ::= INTEGER
PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
PrivateKey ::= OCTET STRING
Attributes ::= SET OF Attribute

both encode and decode methods are using these constants without any description, no tests provided, just hardcode bytes level checks

https://github.com/polkadot-js/common/blob/6971012f4af62f453ba25d83d0ebbfd12eaf5709/packages/keyring/src/pair/encode.ts#L16-L21 https://github.com/polkadot-js/common/blob/6971012f4af62f453ba25d83d0ebbfd12eaf5709/packages/keyring/src/pair/decode.ts#L25-L27

jacogr commented 8 months ago

Closed in #1910 - be aware that these constants should not be relied upon, only the exposed interfaces for decode/encode, it is bound to change.

(There are still a large number of files which have not been commented, in this repo and others - especially on types, it is a "ahh, this needs work and I'm here" effort)

polkadot-js-bot commented 8 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.