@holochain/hc-spin 0.200.1 → 0.200.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,52 +0,0 @@
1
- use crate::utils::*;
2
- use holo_hash::{AgentPubKey, DnaHash};
3
- use holochain_integrity_types::{FunctionName, ZomeName};
4
- use holochain_zome_types::CellId;
5
- use holochain_zome_types::{CapSecret, ExternIO, ZomeCallUnsigned};
6
- use kitsune_p2p_timestamp::Timestamp;
7
-
8
- #[derive(Clone)]
9
- #[napi(object)]
10
- pub struct ZomeCallUnsignedNapi {
11
- pub cell_id: Vec<Vec<u8>>,
12
- pub zome_name: String,
13
- pub fn_name: String,
14
- pub payload: Vec<u8>,
15
- pub cap_secret: Option<Vec<u8>>,
16
- pub provenance: Vec<u8>,
17
- pub nonce: Vec<u8>,
18
- pub expires_at: i64,
19
- }
20
-
21
- impl Into<ZomeCallUnsigned> for ZomeCallUnsignedNapi {
22
- fn into(self: Self) -> ZomeCallUnsigned {
23
- ZomeCallUnsigned {
24
- cell_id: CellId::new(
25
- DnaHash::from_raw_39(self.cell_id.get(0).unwrap().clone()).unwrap(),
26
- AgentPubKey::from_raw_39(self.cell_id.get(1).unwrap().clone()).unwrap(),
27
- ),
28
- zome_name: ZomeName::from(self.zome_name),
29
- fn_name: FunctionName::from(self.fn_name),
30
- payload: ExternIO::from(self.payload),
31
- cap_secret: self
32
- .cap_secret
33
- .map_or(None, |c| Some(CapSecret::from(vec_to_arr(c)))),
34
- provenance: AgentPubKey::from_raw_39(self.provenance).unwrap(),
35
- nonce: vec_to_arr(self.nonce).into(),
36
- expires_at: Timestamp(self.expires_at),
37
- }
38
- }
39
- }
40
-
41
- #[napi(object)]
42
- pub struct ZomeCallNapi {
43
- pub cell_id: Vec<Vec<u8>>,
44
- pub zome_name: String,
45
- pub fn_name: String,
46
- pub payload: Vec<u8>,
47
- pub cap_secret: Option<Vec<u8>>,
48
- pub provenance: Vec<u8>,
49
- pub nonce: Vec<u8>,
50
- pub expires_at: i64,
51
- pub signature: Vec<u8>,
52
- }
@@ -1,4 +0,0 @@
1
- pub fn vec_to_arr<T, const N: usize>(v: Vec<T>) -> [T; N] {
2
- v.try_into()
3
- .unwrap_or_else(|v: Vec<T>| panic!("Expected a Vec of length {} but it was {}", N, v.len()))
4
- }
@@ -1,99 +0,0 @@
1
- #![deny(clippy::all)]
2
-
3
- use std::ops::Deref;
4
-
5
- use holochain_zome_types::{Signature, ZomeCallUnsigned};
6
- use lair_keystore_api::{dependencies::url::Url, ipc_keystore::ipc_keystore_connect, LairClient};
7
- use napi::Result;
8
- use sodoken::BufRead;
9
-
10
- use crate::types::*;
11
-
12
- struct ZomeCallSigner {
13
- lair_client: LairClient,
14
- }
15
-
16
- impl ZomeCallSigner {
17
- /// Connect to lair keystore
18
- pub async fn new(connection_url: String, passphrase: String) -> Self {
19
- let connection_url_parsed = Url::parse(connection_url.deref()).unwrap();
20
- let passphrase_bufread: BufRead = passphrase.as_bytes().into();
21
-
22
- let lair_client = ipc_keystore_connect(connection_url_parsed, passphrase_bufread)
23
- .await
24
- .unwrap();
25
-
26
- Self { lair_client }
27
- }
28
-
29
- /// Sign a zome call
30
- pub async fn sign_zome_call(
31
- &self,
32
- zome_call_unsigned_js: ZomeCallUnsignedNapi,
33
- ) -> Result<ZomeCallNapi> {
34
- let zome_call_unsigned: ZomeCallUnsigned = zome_call_unsigned_js.clone().into();
35
- let pub_key = zome_call_unsigned.provenance.clone();
36
- let mut pub_key_2 = [0; 32];
37
- pub_key_2.copy_from_slice(pub_key.get_raw_32());
38
-
39
- let data_to_sign = zome_call_unsigned.data_to_sign().unwrap();
40
-
41
- let sig = self
42
- .lair_client
43
- .sign_by_pub_key(pub_key_2.into(), None, data_to_sign)
44
- .await
45
- .unwrap();
46
-
47
- let signature = Signature(*sig.0);
48
-
49
- let signed_zome_call = ZomeCallNapi {
50
- cell_id: zome_call_unsigned_js.cell_id,
51
- zome_name: zome_call_unsigned.zome_name.to_string(),
52
- fn_name: zome_call_unsigned.fn_name.0,
53
- payload: zome_call_unsigned_js.payload,
54
- cap_secret: zome_call_unsigned_js.cap_secret,
55
- provenance: zome_call_unsigned_js.provenance,
56
- nonce: zome_call_unsigned_js.nonce,
57
- expires_at: zome_call_unsigned_js.expires_at,
58
- signature: signature.0.to_vec(),
59
- };
60
-
61
- Ok(signed_zome_call)
62
- }
63
- }
64
-
65
- #[napi(js_name = "ZomeCallSigner")]
66
- pub struct JsZomeCallSigner {
67
- zome_call_signer: Option<ZomeCallSigner>,
68
- }
69
-
70
- #[napi]
71
- impl JsZomeCallSigner {
72
- #[napi(constructor)]
73
- pub fn new() -> Self {
74
- Self {
75
- zome_call_signer: None,
76
- }
77
- }
78
-
79
- #[napi]
80
- pub async fn connect(connection_url: String, passphrase: String) -> Self {
81
- let zome_call_signer = ZomeCallSigner::new(connection_url, passphrase).await;
82
-
83
- JsZomeCallSigner {
84
- zome_call_signer: Some(zome_call_signer),
85
- }
86
- }
87
-
88
- #[napi]
89
- pub async fn sign_zome_call(
90
- &self,
91
- zome_call_unsigned_js: ZomeCallUnsignedNapi,
92
- ) -> Result<ZomeCallNapi> {
93
- self.zome_call_signer
94
- .as_ref()
95
- .unwrap()
96
- .sign_zome_call(zome_call_unsigned_js)
97
- .await
98
- }
99
- }