Skip to content

Commit 62c125f

Browse files
committed
feat: Add convert and metadata methods
1 parent 17c88b3 commit 62c125f

16 files changed

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

example/src/modules/Metadata.tsx

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

ios/libopenpgp_bridge.a

106 KB
Binary file not shown.

src/bridge.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ export { Hash } from './model/hash';
66
export { KeyOptions } from './model/key-options';
77
export { KeyPair } from './model/key-pair';
88
export { Options } from './model/options';
9+
export { PrivateKeyMetadata } from './model/private-key-metadata';
10+
export { PublicKeyMetadata } from './model/public-key-metadata';

0 commit comments

Comments
 (0)