npm package: @line100/certification
Description: ## install * use `bun` as ts runtime * `npm i -g @line100/certification`
Latest version: 0.2.3

# certification

## install
* use `bun` as ts runtime
* `npm i -g @line100/certification`

## usage

### create root
```sh
cert-node create -v --name root --payload '{}' --output root.cert.node
```
```txt
secret Uint8Array: len = 64, digest = VJc1s5o6qftt8g==
[ "root" ] {
  pubkey: "mRiGgzYhvatSt0wM4l/wOzkVOzxTZp5/3te5tLkPd6E=",
  boxkey: "MhjGMTnJ6j8qNQ58x8Yhq+6Gl5A/FbaRH6K3OI08+BA=",
  payload: {},
  start: 1695223377071,
  expiration: 1726759377071
}
-- certification --
pmRwYXRogWRyb290ZXN0YXJ0GwAAAYqzL+yvZmJveGtleVggMhjGMTnJ6j8qNQ58x8Yhq+6Gl5A/FbaRH6K3OI08+BBmcHVia2V5WCCZGIaDNiG9q1K3TAziX/A7ORU7PFNmnn/e17m0uQ93oWdwYXlsb2FkoGpleHBpcmF0aW9uGwAAAZIK4Riv
```

### create sub node from root
```sh
cert-node create -v --name app --parent root.cert.node --payload '{}' --output app.cert.node 
```
```txt
[ "root", "app" ] {
  pubkey: "CtWlxOJbWSTw0uhc0Mge1WLT5YEdwcTXsnHLj9gVNag=",
  boxkey: "kKW4gxpxFygnyUaKb98pcRZhnt1jhp6W0VXESjCS3Dw=",
  payload: {},
  start: 1695223493372,
  expiration: 1726759493372
}
[ "root" ] {
  pubkey: "mRiGgzYhvatSt0wM4l/wOzkVOzxTZp5/3te5tLkPd6E=",
  boxkey: "MhjGMTnJ6j8qNQ58x8Yhq+6Gl5A/FbaRH6K3OI08+BA=",
  payload: {},
  start: 1695223377071,
  expiration: 1726759377071
}
-- certification --
qGRwYXRogmRyb290Y2FwcGVzdGFydBsAAAGKszGy/GZib3hrZXlYIJCluIMacRcoJ8lGim/fKXEWYZ7dY4aeltFVxEowktw8ZnBhcmVudKZkcGF0aIFkcm9vdGVzdGFydBsAAAGKsy/sr2Zib3hrZXlYIDIYxjE5yeo/KjUOfMfGIavuhpeQPxW2kR+itziNPPgQZnB1YmtleVggmRiGgzYhvatSt0wM4l/wOzkVOzxTZp5/3te5tLkPd6FncGF5bG9hZKBqZXhwaXJhdGlvbhsAAAGSCuEYr2ZwdWJrZXlYIArVpcTiW1kk8NLoXNDIHtVi0+WBHcHE17Jxy4/YFTWoZ3BheWxvYWSgamV4cGlyYXRpb24bAAABkgri3vxqcGFyZW50X3NpZ1hAE6KD/5JFuSHifVe9BsJ/i0oCN1zlzRazFfcZR04tmEwazeyZgDrkmgK1NtDtHCMftUryyPYIqOmRGVeRJjJeDQ==
```

## show node info
```sh
cert-node show app.cert.node
```
```txt
secret Uint8Array: len = 64, digest = BWAa29AvvHECdA==
[ "root", "app" ] {
  pubkey: "CtWlxOJbWSTw0uhc0Mge1WLT5YEdwcTXsnHLj9gVNag=",
  boxkey: "kKW4gxpxFygnyUaKb98pcRZhnt1jhp6W0VXESjCS3Dw=",
  payload: {},
  start: 1695223493372,
  expiration: 1726759493372
}
[ "root" ] {
  pubkey: "mRiGgzYhvatSt0wM4l/wOzkVOzxTZp5/3te5tLkPd6E=",
  boxkey: "MhjGMTnJ6j8qNQ58x8Yhq+6Gl5A/FbaRH6K3OI08+BA=",
  payload: {},
  start: 1695223377071,
  expiration: 1726759377071
}
-- certification --
qGRwYXRogmRyb290Y2FwcGVzdGFydBsAAAGKszGy/GZib3hrZXlYIJCluIMacRcoJ8lGim/fKXEWYZ7dY4aeltFVxEowktw8ZnBhcmVudKZkcGF0aIFkcm9vdGVzdGFydBsAAAGKsy/sr2Zib3hrZXlYIDIYxjE5yeo/KjUOfMfGIavuhpeQPxW2kR+itziNPPgQZnB1YmtleVggmRiGgzYhvatSt0wM4l/wOzkVOzxTZp5/3te5tLkPd6FncGF5bG9hZKBqZXhwaXJhdGlvbhsAAAGSCuEYr2ZwdWJrZXlYIArVpcTiW1kk8NLoXNDIHtVi0+WBHcHE17Jxy4/YFTWoZ3BheWxvYWSgamV4cGlyYXRpb24bAAABkgri3vxqcGFyZW50X3NpZ1hAE6KD/5JFuSHifVe9BsJ/i0oCN1zlzRazFfcZR04tmEwazeyZgDrkmgK1NtDtHCMftUryyPYIqOmRGVeRJjJeDQ==
```

## API
```ts
// Generated by dts-bundle-generator v8.0.1

export type Certification = {
        pubkey: Uint8Array;
        boxkey: Uint8Array;
        path: string[];
        payload: {
                [i: string]: any;
        };
        /** 生效时间 */
        start: number;
        /** 过期时间 */
        expiration: number;
        parent?: Certification;
        parent_sig?: Uint8Array;
};
/**
 * 客户端使用的cert store，可以用来存放多个端的root以及sub密钥
 * * 可同时使用多个root
 * * 放入多个证书，并记录密钥过期时间
 */
export declare class CertStore {
        private readonly rootSet;
        private pubkeys;
        private boxkeys;
        /**
         * 初始化key store时，需要放入root密钥，
         * * root密钥可能存在多个
         * @param rootKeys
         */
        constructor(rootKeys: Uint8Array[]);
        /**
         * 确认签名公钥是否在store中
         * @param pubkey
         * @param cb
         * @returns
         */
        validatePubkey(pubkey: Uint8Array, cb?: (cert: Certification) => boolean): boolean;
        /**
         * 确认box公钥是否在store中
         * @param boxkey
         * @param cb
         * @returns
         */
        validateBoxkey(boxkey: Uint8Array, cb?: (cert: Certification) => boolean): boolean;
        /**
         * 将二进制格式的证书保存，无法到达root的证书无效
         * @param cert
         */
        putCertificationBytes(bytes: Uint8Array): {
                ok?: true;
                error?: string;
        };
        /**
         * 将证书保存，无法到达root的证书无效
         * @param cert
         */
        putCertification(cert: Certification): {
                ok?: true;
                error?: string;
        };
}

export {};
```