Skip to content

Commit 39cd0be

Browse files
authored
Merge pull request #67 from jerson/add-convert-metadata
Add convert metadata
2 parents 17c88b3 + 6680409 commit 39cd0be

17 files changed

+516
-17
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ import OpenPGP from "react-native-fast-openpgp";
6363
const generated = await OpenPGP.generate(options: Options): Promise<KeyPair>;
6464
```
6565

66+
### Convert methods
67+
```typescript
68+
import OpenPGP from "react-native-fast-openpgp";
69+
70+
const publicKey = await OpenPGP.convertPrivateKeyToPublicKey(privateKey: string): Promise<string>;
71+
```
72+
73+
### Metadata methods
74+
```typescript
75+
import OpenPGP from "react-native-fast-openpgp";
76+
77+
const metadata1 = await OpenPGP.getPublicKeyMetadata(publicKey: string): Promise<PublicKeyMetadata>;
78+
const metadata2 = await OpenPGP.getPrivateKeyMetadata(privateKey: string): Promise<PrivateKeyMetadata>;
79+
```
80+
6681
### Encrypt with multiple keys
6782

6883
```typescript
@@ -170,6 +185,24 @@ export interface KeyPair {
170185
privateKey: string;
171186
}
172187

188+
export interface PublicKeyMetadata {
189+
keyID: string;
190+
keyIDShort: string;
191+
creationTime: string;
192+
fingerprint: string;
193+
keyIDNumeric: string;
194+
isSubKey: boolean;
195+
}
196+
export interface PrivateKeyMetadata {
197+
keyID: string;
198+
keyIDShort: string;
199+
creationTime: string;
200+
fingerprint: string;
201+
keyIDNumeric: string;
202+
isSubKey: boolean;
203+
encrypted: boolean;
204+
}
205+
173206
/**
174207
* An Entity represents the components of an OpenPGP key: a primary public key
175208
* (which must be a signing key), one or more identities claimed by that key,
32 KB
Binary file not shown.
28 KB
Binary file not shown.
20 KB
Binary file not shown.
28 KB
Binary file not shown.

example/src/App.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import Generate from './modules/Generate';
1818
import EncryptDecryptFile from './modules/EncryptDecryptFile';
1919
import EncryptDecryptSymmetricFile from './modules/EncryptDecryptSymmetricFile';
2020
import SignVerifyFile from './modules/SignVerifyFile';
21+
import Metadata from './modules/Metadata';
22+
import Convert from './modules/Convert';
2123

2224
const passphrase = 'test';
2325
const privateKey = `-----BEGIN PGP PRIVATE KEY BLOCK-----
@@ -164,6 +166,13 @@ const App = () => {
164166
privateKey={privateKey}
165167
passphrase={passphrase}
166168
/>
169+
<Metadata
170+
publicKey={publicKey}
171+
privateKey={privateKey}
172+
/>
173+
<Convert
174+
privateKey={privateKey}
175+
/>
167176
</View>
168177
</ScrollView>
169178
</KeyboardAvoidingView>

example/src/modules/Convert.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {Button} from "react-native";
2+
import React, {useState} from "react";
3+
import OpenPGP from 'react-native-fast-openpgp';
4+
import SectionContainer from "../components/SectionContainer";
5+
import SectionTitle from "../components/SectionTitle";
6+
import SectionResult from "../components/SectionResult";
7+
import Container from "../components/Container";
8+
9+
interface Props {
10+
privateKey: string
11+
}
12+
13+
export default function ({privateKey}: Props) {
14+
15+
const [output, setOutput] = useState('');
16+
17+
return <Container testID={'convert-all'}>
18+
<SectionContainer testID={'convert'}>
19+
<SectionTitle>Convert</SectionTitle>
20+
<Button
21+
title={"convert PrivateKey To PublicKey"}
22+
testID={'button'}
23+
onPress={async () => {
24+
const output = await OpenPGP.convertPrivateKeyToPublicKey(privateKey);
25+
setOutput(output);
26+
}}
27+
/>
28+
{!!output && <SectionResult testID={'result'}>{output}</SectionResult>}
29+
</SectionContainer>
30+
31+
</Container>;
32+
}

example/src/modules/Metadata.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Button } from 'react-native';
2+
import React, { useState } from 'react';
3+
import OpenPGP from 'react-native-fast-openpgp';
4+
import SectionContainer from '../components/SectionContainer';
5+
import SectionTitle from '../components/SectionTitle';
6+
import SectionResult from '../components/SectionResult';
7+
import Container from '../components/Container';
8+
9+
interface Props {
10+
publicKey: string;
11+
privateKey: string;
12+
}
13+
14+
export default function ({ publicKey, privateKey }: Props) {
15+
const [metadataPrivateKey, setMetadataPrivateKey] = useState('');
16+
const [metadataPublicKey, setMetadataPublicKey] = useState('');
17+
18+
return (
19+
<Container testID={'metadata'}>
20+
<SectionContainer testID={'privatekey'}>
21+
<SectionTitle>Metadata PrivateKey</SectionTitle>
22+
<Button
23+
title={'get PrivateKey Metadata'}
24+
testID={'button'}
25+
onPress={async () => {
26+
const output = await OpenPGP.getPrivateKeyMetadata(privateKey);
27+
setMetadataPrivateKey(JSON.stringify(output, null, 2));
28+
}}
29+
/>
30+
{!!metadataPrivateKey && <SectionResult testID={'result'}>{metadataPrivateKey}</SectionResult>}
31+
</SectionContainer>
32+
<SectionContainer testID={'publikey'}>
33+
<SectionTitle>Metadata PrivateKey</SectionTitle>
34+
<Button
35+
title={'get PublicKey Metadata'}
36+
testID={'button'}
37+
onPress={async () => {
38+
const output = await OpenPGP.getPublicKeyMetadata(publicKey);
39+
setMetadataPublicKey(JSON.stringify(output, null, 2));
40+
}}
41+
/>
42+
{!!metadataPublicKey && <SectionResult testID={'result'}>{metadataPublicKey}</SectionResult>}
43+
</SectionContainer>
44+
</Container>
45+
);
46+
}

ios/libopenpgp_bridge.a

106 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-fast-openpgp",
3-
"version": "2.3.1",
3+
"version": "2.4.0",
44
"description": "library for use openPGP",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

0 commit comments

Comments
 (0)