-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Adding Nostr api * feat: Nostr example * fix: Nostr type * chore: limit version * chore: message * chore: update version * feat: Adding NostrSignSchnorr Method * chore: upgrade version
- Loading branch information
1 parent
c0c2cfa
commit 7285a87
Showing
31 changed files
with
898 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
packages/connect-examples/expo-example/src/data/nostr.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { type PlaygroundProps } from '../components/Playground'; | ||
|
||
const api: PlaygroundProps[] = [ | ||
{ | ||
method: 'nostrGetPublicKey', | ||
description: 'Get a Nostr public key for your account.', | ||
presupposes: [ | ||
{ | ||
title: 'Get Nostr Public Key', | ||
value: { | ||
path: "m/44'/1237'/0'/0/0", | ||
showOnOneKey: true, | ||
}, | ||
}, | ||
{ | ||
title: 'Batch Get Public Key', | ||
value: { | ||
bundle: [ | ||
{ | ||
path: "m/44'/1237'/0'/0/0", | ||
showOnOneKey: false, | ||
}, | ||
{ | ||
path: "m/44'/1237'/1'/0/0", | ||
showOnOneKey: false, | ||
}, | ||
{ | ||
path: "m/44'/1237'/2'/0/0", | ||
showOnOneKey: false, | ||
}, | ||
{ | ||
path: "m/44'/1237'/3'/0/0", | ||
showOnOneKey: false, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
method: 'nostrSignEvent', | ||
description: 'Sign a Nostr event.', | ||
presupposes: [ | ||
{ | ||
title: 'Sign simple note', | ||
value: { | ||
path: "m/44'/1237'/0'/0/0", | ||
event: { | ||
kind: 1, | ||
content: 'Hello world', | ||
tags: [], | ||
created_at: 1702268010, | ||
}, | ||
}, | ||
}, | ||
{ | ||
title: 'Sign other nostr event', | ||
value: { | ||
path: "m/44'/1237'/0'/0/0", | ||
event: { | ||
id: '6ea5ad0c84597800da1326d1c23c7c29777faa6a750dcb358e0a228dc666c3a4', | ||
pubkey: '0b3df6d98a46e9c9204bb9302303f7956461feda90bf00b153892bb9e9d454c8', | ||
content: '', | ||
kind: 22242, | ||
created_at: 1702521824, | ||
tags: [ | ||
['challenge', '4b1fd2cc-a212-4fb3-a844-bc82ecd005eb'], | ||
['relay', 'wss://nostr.wine/'], | ||
], | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
method: 'nostrEncryptMessage', | ||
description: 'Encrypt message', | ||
presupposes: [ | ||
{ | ||
title: 'Encrypt message', | ||
value: { | ||
path: "m/44'/1237'/0'/0/0", | ||
pubkey: '2118c65161c7d68b4bdbe1374f658532670057ab1bb0c99937d0ff7cff45cb5e', | ||
plaintext: 'Hello world', | ||
showOnOneKey: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
method: 'nostrDecryptMessage', | ||
description: 'Decrypt message', | ||
presupposes: [ | ||
{ | ||
title: 'Decrypt message', | ||
value: { | ||
path: "m/44'/1237'/0'/0/0", | ||
pubkey: '2118c65161c7d68b4bdbe1374f658532670057ab1bb0c99937d0ff7cff45cb5e', | ||
ciphertext: 'VpWFJ7JDFv16jL7pBZ1shw==?iv=$1tPpwGD3Ic1RTVXJx1ZG7Q==', | ||
showOnOneKey: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
method: 'nostrSignSchnorr', | ||
description: 'Sign schnorr', | ||
presupposes: [ | ||
{ | ||
title: 'Sign schnorr', | ||
value: { | ||
path: "m/44'/1237'/0'/0/0", | ||
hash: '2118c65161c7d68b4bdbe1374f658532670057ab1bb0c99937d0ff7cff45cb5e', | ||
}, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
export default api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { NostrDecryptMessage as DecryptMessage } from '@onekeyfe/hd-transport'; | ||
import { UI_REQUEST } from '../../constants/ui-request'; | ||
import { serializedPath, validatePath } from '../helpers/pathUtils'; | ||
import { BaseMethod } from '../BaseMethod'; | ||
import { validateParams } from '../helpers/paramsValidator'; | ||
|
||
export default class NostrDecryptMessage extends BaseMethod<DecryptMessage> { | ||
hasBundle = false; | ||
|
||
init() { | ||
this.checkDeviceId = true; | ||
this.notAllowDeviceMode = [...this.notAllowDeviceMode, UI_REQUEST.INITIALIZE]; | ||
|
||
const { payload } = this; | ||
validateParams(payload, [ | ||
{ name: 'path', required: true }, | ||
{ name: 'pubkey', required: true, type: 'string' }, | ||
{ name: 'ciphertext', required: true, type: 'string' }, | ||
{ name: 'showOnOneKey', type: 'boolean' }, | ||
]); | ||
const addressN = validatePath(payload.path, 5); | ||
|
||
this.params = { | ||
address_n: addressN, | ||
pubkey: payload.pubkey, | ||
msg: payload.ciphertext, | ||
show_display: payload.showOnOneKey ?? true, | ||
}; | ||
} | ||
|
||
getVersionRange() { | ||
return { | ||
model_mini: { | ||
min: '3.6.0', | ||
}, | ||
model_touch: { | ||
min: '4.6.0', | ||
}, | ||
}; | ||
} | ||
|
||
async run() { | ||
const { message } = await this.device.commands.typedCall( | ||
'NostrDecryptMessage', | ||
'NostrDecryptedMessage', | ||
this.params | ||
); | ||
|
||
return { | ||
path: serializedPath(this.params.address_n), | ||
pubkey: this.params.pubkey, | ||
ciphertext: this.params.msg, | ||
decryptedMessage: message.msg, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { NostrEncryptMessage as EncryptMessage } from '@onekeyfe/hd-transport'; | ||
import { UI_REQUEST } from '../../constants/ui-request'; | ||
import { serializedPath, validatePath } from '../helpers/pathUtils'; | ||
import { BaseMethod } from '../BaseMethod'; | ||
import { validateParams } from '../helpers/paramsValidator'; | ||
|
||
export default class NostrEncryptMessage extends BaseMethod<EncryptMessage> { | ||
hasBundle = false; | ||
|
||
init() { | ||
this.checkDeviceId = true; | ||
this.notAllowDeviceMode = [...this.notAllowDeviceMode, UI_REQUEST.INITIALIZE]; | ||
|
||
const { payload } = this; | ||
validateParams(payload, [ | ||
{ name: 'path', required: true }, | ||
{ name: 'pubkey', required: true, type: 'string' }, | ||
{ name: 'plaintext', required: true, type: 'string' }, | ||
{ name: 'showOnOneKey', type: 'boolean' }, | ||
]); | ||
const addressN = validatePath(payload.path, 5); | ||
|
||
this.params = { | ||
address_n: addressN, | ||
pubkey: payload.pubkey, | ||
msg: payload.plaintext, | ||
show_display: payload.showOnOneKey ?? true, | ||
}; | ||
} | ||
|
||
getVersionRange() { | ||
return { | ||
model_mini: { | ||
min: '3.6.0', | ||
}, | ||
model_touch: { | ||
min: '4.6.0', | ||
}, | ||
}; | ||
} | ||
|
||
async run() { | ||
const { message } = await this.device.commands.typedCall( | ||
'NostrEncryptMessage', | ||
'NostrEncryptedMessage', | ||
this.params | ||
); | ||
|
||
return { | ||
path: serializedPath(this.params.address_n), | ||
pubkey: this.params.pubkey, | ||
plaintext: this.params.msg, | ||
encryptedMessage: message.msg, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { NostrGetPublicKey as GetPublicKey } from '@onekeyfe/hd-transport'; | ||
import { UI_REQUEST } from '../../constants/ui-request'; | ||
import { serializedPath, validatePath } from '../helpers/pathUtils'; | ||
import { BaseMethod } from '../BaseMethod'; | ||
import { validateParams } from '../helpers/paramsValidator'; | ||
import { BTCGetAddressParams } from '../../types/api/btcGetAddress'; | ||
import { NostrPublicKey } from '../../types/api/nostrGetPublicKey'; | ||
|
||
export default class NostrGetPublicKey extends BaseMethod<GetPublicKey[]> { | ||
hasBundle = false; | ||
|
||
init() { | ||
this.checkDeviceId = true; | ||
this.notAllowDeviceMode = [...this.notAllowDeviceMode, UI_REQUEST.INITIALIZE]; | ||
|
||
this.hasBundle = Object.prototype.hasOwnProperty.call(this.payload, 'bundle'); | ||
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] }; | ||
|
||
validateParams(payload, [{ name: 'bundle', type: 'array' }]); | ||
|
||
this.params = []; | ||
|
||
payload.bundle.forEach((batch: BTCGetAddressParams) => { | ||
const addressN = validatePath(batch.path, 1); | ||
|
||
validateParams(batch, [ | ||
{ name: 'path', required: true }, | ||
{ name: 'showOnOneKey', type: 'boolean' }, | ||
]); | ||
|
||
const showOnOneKey = batch.showOnOneKey ?? true; | ||
|
||
this.params.push({ | ||
address_n: addressN, | ||
show_display: showOnOneKey, | ||
}); | ||
}); | ||
} | ||
|
||
getVersionRange() { | ||
return { | ||
model_mini: { | ||
min: '3.6.0', | ||
}, | ||
model_touch: { | ||
min: '4.6.0', | ||
}, | ||
}; | ||
} | ||
|
||
async run() { | ||
const responses: NostrPublicKey[] = []; | ||
|
||
for (let i = 0; i < this.params.length; i++) { | ||
const param = this.params[i]; | ||
|
||
const res = await this.device.commands.typedCall('NostrGetPublicKey', 'NostrPublicKey', { | ||
...param, | ||
}); | ||
|
||
const response = { | ||
path: serializedPath(param.address_n), | ||
...res.message, | ||
}; | ||
|
||
responses.push(response); | ||
} | ||
|
||
return Promise.resolve(this.hasBundle ? responses : responses[0]); | ||
} | ||
} |
Oops, something went wrong.